Rspec :js => true issue (Rails 3)

Hey all,
I’m trying to get some Javascript test coverage in my app, so I
decided to implement Rspec and Capybara with Selenium. I follow Ryan
Bate’s Railscast episode 257 to a tee, but I still can’t get it to work.
Problems arise when I add :js => true. Without it, the following DOES
work. Here’s the spec:

describe “Info Page” do
describe “GET /premium” do
it “shows the info page”, :js => true do
visit ‘/premium’
end
end
end

Which, when executed, outputs the following (with --trace):

Failures:

  1. Info Page GET /premium shows the info page
    Failure/Error: visit ‘/premium’
    TypeError:
    Zip is not a module

    ./spec/requests/info_spec.rb:6:in `block (3 levels) in <top

(required)>’

Finished in 13.15 seconds
1 example, 1 failure

Failed examples:

rspec ./spec/requests/info_spec.rb:5 # Info Page GET /premium shows the
info page
rake aborted!
ruby /Users/loadeddesigns/.rvm/rubies/ruby-1.9.2-p290/bin/ruby -S rspec
./spec/requests/info_spec.rb failed
/Users/loadeddesigns/.rvm/gems/[email protected]/gems/rspec-core-2.7.1/lib/rspec/core/rake_task.rb:149:in
block (2 levels) in initialize' /Users/loadeddesigns/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/file_utils_ext.rb:60:inverbose’
/Users/loadeddesigns/.rvm/gems/[email protected]/gems/rspec-core-2.7.1/lib/rspec/core/rake_task.rb:139:in
block in initialize' /Users/loadeddesigns/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:205:incall’
/Users/loadeddesigns/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:205:in
block in execute' /Users/loadeddesigns/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:200:ineach’
/Users/loadeddesigns/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:200:in
execute' /Users/loadeddesigns/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:158:inblock in invoke_with_call_chain’
/Users/loadeddesigns/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in
mon_synchronize' /Users/loadeddesigns/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:151:ininvoke_with_call_chain’
/Users/loadeddesigns/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:144:in
invoke' /Users/loadeddesigns/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:116:ininvoke_task’
/Users/loadeddesigns/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:94:in
block (2 levels) in top_level' /Users/loadeddesigns/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:94:ineach’
/Users/loadeddesigns/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:94:in
block in top_level' /Users/loadeddesigns/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:133:instandard_exception_handling’
/Users/loadeddesigns/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:88:in
top_level' /Users/loadeddesigns/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:66:inblock in run’
/Users/loadeddesigns/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:133:in
standard_exception_handling' /Users/loadeddesigns/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:63:inrun’
/Users/loadeddesigns/.rvm/gems/[email protected]/gems/rake-0.9.2.2/bin/rake:33:in
<top (required)>' /Users/loadeddesigns/.rvm/gems/[email protected]/bin/rake:19:inload’
/Users/loadeddesigns/.rvm/gems/[email protected]/bin/rake:19:in
`’

I am having a really hard time trying to track down the cause of this…
Heck, the only reason why I am using RSpec and Capybara is for
Javascript support (other tests in the app use test unit).

Any and all help is appreciated!

Thanks,

  • Jeff

UPDATE:

I got this working by using tips from the following blog:
http://www.neotericdesign.com/blog/capybara-webkit-rspec-and-javascript

I changed my gemfile to use the following gems:

For Testing w/ Javascript support.

Rspec needs to be in the development group to expose generators and

rake tasks without

having to type RAILS_ENV=test.

gem ‘rspec-rails’, ‘~> 2.7.0’, group: :development
gem ‘capybara-webkit’, ‘~> 0.7.2’

Debugging Tests

gem ‘launchy’

This allows for database transactions to refresh during testing with

capybara and selenium.

gem ‘database_cleaner’, ‘~> 0.6.7’

As a dependency of capybara-webkit, I also installed the QT libraries.

I still don’t know why I was getting the “Zip is not a module” error,
but I hope this helps someone in the future.

Thanks,

  • Jeff

Okay, maybe I spoke too soon. Can’t help but be hopeful, lol.

I have a bunch of “fill_in” statements for the page I’m testing, such
as:

fill_in “shopper_first_name”, with: ‘Jeffrey’

etc… however, although I’m not getting an error anymore, it DOES NOT
fill in the text UNLESS I get rid of :js => true. I’m going to be
testing ajax, so I need this functionality…

This headache is turning into a migraine…

Advice?

Thanks,

  • Jeff

headslam I just needed to RTFM more closely. I assumed the fields
weren’t being populated because I was using launchy to
save_and_open_page to see if it had done so. Capybara-webkit doesn’t
instantiate a browser though, it access the renderer (webkit) directly.

This is working now :stuck_out_tongue:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs