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
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 usingrack-test
driver current test #3 deal with.capybara includes capybara::dsl feature specs, use feature specs, , remove
include capybara::dsl
rspec config shown above. requires either putting spec filespec/features/my_spec.rb
, enabling rspec config determine test type directory, or manually specifying test feature specfeature "should utilise capybara download web content" ... end
or
it "should utilise capybara download web content", type: :feature ... end
your test using
rack_test
driver , notpoltergeist-billy
driver. because you're settingcapybara.javascript_driver
inside test. needs set before test, , test tagged metadata tell use specific driver. 2 options here, either setcapybara.javascript_driver = :poltergeist_billy
in spec_helper.rb , specify:js
metadatafeature "should utilise capybara download web content", :js ... end
or specify
:driver
metadata identify driver use given testfeature "should utilise capybara download web content", driver: :poltergeist_billy ... end
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 pathexpect(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 doexpect(page).to have_text('test_response')
if needs exact match
expect(page).to have_text('test_response', exact: true)
Comments
Post a Comment