ruby on rails - Puffing Billy with Poltergeist error: "rack-test requires a rack application, but none was given" -


using puffing billy instructions rspec capybara created simple test stub request using :poltergeist_billy driver resulting in error:

argumenterror:         rack-test requires rack application, none given       # /home/resrev/.rvm/gems/ruby-2.3.1/gems/capybara-2.4.4/lib/capybara/rack_test/driver.rb:16:in `initialize'       # /home/resrev/.rvm/gems/ruby-2.3.1/gems/capybara-2.4.4/lib/capybara.rb:372:in `new'       # /home/resrev/.rvm/gems/ruby-2.3.1/gems/capybara-2.4.4/lib/capybara.rb:372:in `block in <top (required)>'       # /home/resrev/.rvm/gems/ruby-2.3.1/gems/capybara-2.4.4/lib/capybara/session.rb:79:in `driver'       # /home/resrev/.rvm/gems/ruby-2.3.1/gems/capybara-2.4.4/lib/capybara/session.rb:227:in `visit'       # /home/resrev/.rvm/gems/ruby-2.3.1/gems/capybara-2.4.4/lib/capybara/dsl.rb:51:in `block (2 levels) in <module:dsl>'       # ./spec/scraypa_spec.rb:52:in `block (4 levels) in <top (required)>' 

with code:

spec/spec_helper.rb

require "bundler/setup" require "scraypa" require 'billy/capybara/rspec'  rspec.configure |config|   # enable flags --only-failures , --next-failure   config.example_status_persistence_file_path = ".rspec_status"    config.expect_with :rspec |c|     c.syntax = :expect   end    config.include capybara::dsl end 

spec/my_spec.rb:

it "should utilise capybara download web content"   #capybara.current_driver = :poltergeist_billy   capybara.javascript_driver = :poltergeist_billy   proxy.stub('http://www.google.com/')         .and_return(:text => "test response")   visit "http://www.google.com/"   expect(page.text).to eq('test response') end 

while digging around, found example used capybara.current_driver = :poltergeist_billy (which have commented out in test above), if uncomment code, error:

cliver::dependency::notfound:         not find executable ["phantomjs"] on path.       # /home/resrev/.rvm/gems/ruby-2.3.1/gems/cliver-0.3.2/lib/cliver/dependency.rb:143:in `raise_not_found!'       # /home/resrev/.rvm/gems/ruby-2.3.1/gems/cliver-0.3.2/lib/cliver/dependency.rb:116:in `detect!'       # /home/resrev/.rvm/gems/ruby-2.3.1/gems/cliver-0.3.2/lib/cliver.rb:24:in `detect!'       # /home/resrev/.rvm/gems/ruby-2.3.1/gems/poltergeist-1.9.0/lib/capybara/poltergeist/client.rb:36:in `initialize'       # /home/resrev/.rvm/gems/ruby-2.3.1/gems/poltergeist-1.9.0/lib/capybara/poltergeist/client.rb:14:in `new'       # /home/resrev/.rvm/gems/ruby-2.3.1/gems/poltergeist-1.9.0/lib/capybara/poltergeist/client.rb:14:in `start'       # /home/resrev/.rvm/gems/ruby-2.3.1/gems/poltergeist-1.9.0/lib/capybara/poltergeist/driver.rb:42:in `client'       # /home/resrev/.rvm/gems/ruby-2.3.1/gems/poltergeist-1.9.0/lib/capybara/poltergeist/driver.rb:25:in `browser'       # /home/resrev/.rvm/gems/ruby-2.3.1/gems/poltergeist-1.9.0/lib/capybara/poltergeist/driver.rb:95:in `visit'       # /home/resrev/.rvm/gems/ruby-2.3.1/gems/capybara-2.4.4/lib/capybara/session.rb:227:in `visit'       # /home/resrev/.rvm/gems/ruby-2.3.1/gems/capybara-2.4.4/lib/capybara/dsl.rb:51:in `block (2 levels) in <module:dsl>'       # ./spec/scraypa_spec.rb:52:in `block (4 levels) in <top (required)>' 

im not sure go here or im doing wrong, ideas? thanks.

the errors many here, let's start @ beginning

  1. you don't have require capybara/rails in spec_helper.rb or rails_helper.rb - https://github.com/teamcapybara/capybara#setup - means capybara.app isn't getting set , why you're getting "rack-test requires rack application" - of course don't want using rack-test driver current test #3 deal with.

  2. capybara includes capybara::dsl feature specs, use feature specs, , remove include capybara::dsl rspec config shown above. requires either putting spec file spec/features/my_spec.rb , enabling rspec config determine test type directory, or manually specifying test feature spec

    feature "should utilise capybara download web content"   ... end 

    or

    it "should utilise capybara download web content", type: :feature   ... end 
  3. your test using rack_test driver , not poltergeist-billy driver. because you're setting capybara.javascript_driver inside test. needs set before test, , test tagged metadata tell use specific driver. 2 options here, either set capybara.javascript_driver = :poltergeist_billy in spec_helper.rb , specify :js metadata

     feature "should utilise capybara download web content", :js    ...  end 

    or specify :driver metadata identify driver use given test

    feature "should utilise capybara download web content", driver: :poltergeist_billy    ...  end 
  4. when specifying use poltergeist billy need install phantomjs (required poltergeist) in path. if using osx homebrew can brew install phantomjs - on other systems you'll need download latest version of phantomjs , put somewhere in path

  5. expect(page.text).to eq('test response'). terrible way text matching when using capybara. eq has no waiting/retrying behavior , since actions have no guarantees on being completed when capybaras methods return lead flaky tests. instead, use matchers capybara provides. if okay substring match do

    expect(page).to have_text('test_response')

    if needs exact match

    expect(page).to have_text('test_response', exact: true)


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -