help with writing rspec tests for ruby / capybara env (non Rails)

88 views
Skip to first unread message

Christopher Biltoft

unread,
Apr 28, 2015, 1:31:23 AM4/28/15
to rs...@googlegroups.com
The following spec works for the first example but not the second.

require 'rspec'
require 'capybara/rspec'
require 'rubygems'
require 'capybara'
require 'capybara/dsl'
 
Capybara.run_server = false
 
Capybara.current_driver = :seleniumCapybara.app_host = '<some url>'

 describe
'page <some page 1>', type: :feature do
   it
'redirects to /' do
     visit
('<some page 1>');
     expect
(page.current_path).to eq '/'
   
end
 
end

 describe
'page <some page 2>', type: :feature do
   it
'redirects to /' do
     visit
('<some page 2>');
     expect
(page.current_path).to eq '/'
   
end
 
end


Results are:

rspec spec/redirect_spec.rb
.
 An error occurred in an after hook
   ArgumentError: rack-test requires a rack application, but none was given
   occurred at /home/cb/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/capybara-2.4.4/lib/capybara/rac
k_test/driver.rb:16:in `initialize'

F

Failures:

 1) redirect page <some page 2> redirects to /
    Failure/Error: visit('< some page 2>');
    ArgumentError:
      rack-test requires a rack application, but none was given
    # ./spec/redirect_spec.rb:21:in `block (2 levels) in <top (required)>'

Finished in 6.52 seconds (files took 0.3075 seconds to load)
2 examples, 1 failure

Failed examples:

rspec ./spec/redirect_spec.rb:20 # redirect <some page 2> redirects to /

Clearly I haven't set up right for rack and I haven't found documentation on 3.2. on the subject so I'm am in the dark.

Would appreciate any assistance with solving the problem

Jon Rowe

unread,
Apr 28, 2015, 1:32:58 AM4/28/15
to rs...@googlegroups.com
`current_driver` is a one shot deal and is reset back to the default driver in `capybara/rspec` (if I remember correctly), instead set `Capybara.default_driver = :selenium` 

Jon Rowe
---------------------------

--
You received this message because you are subscribed to the Google Groups "rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rspec+un...@googlegroups.com.
To post to this group, send email to rs...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/1f4c3169-24a3-43b5-b3a2-9fd6ecf84f57%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages