views:

217

answers:

4

I've swapped out Webrat for Capybara on a new Rails 3 project. I ran through Tim Riley's great post on it here ( http://openmonkey.com/articles/2010/04/javascript-testing-with-cucumber-capybara ), and also cloned his repository, executed the example cucumber feature, and saw the browser window fire open. So the whole Cucumber, Capybara, Selenium stack seems to work fine in that instance.

However if I create a new Rails 3 project, run through setting up a similar example project, and annotate a Scenario with @javascript the browser window does not fire, and the Cucumber Scenario just fails with the usual Command failed with status (1) event (which, in the instance of failing or pending steps, Cucumber triggers by design for the benefit of CI tools).

Apart from the @javascript functionality provided by Capybara, all other features work fine.

Am I missing something incredibly obvious? Is there a way for a BDD newcomer to look deeper into the issues (the stack trace just shows the standard rake error when Cucumber fails).

  • rvm 1.9.2-head
  • gem 'rails', '3.0.0.rc'
  • gem 'cucumber'
  • gem 'cucumber-rails'
  • gem 'capybara'
  • gem 'culerity'
  • gem 'celerity', :require => nil
A: 

Capybara is "lazy" in that it will open the browser window first when it is actually needed. If you're actually doing something that would require a browser, Capybara won't open one.

jnicklas
I did recreate the same JavaScript-dependent steps as in Tim's example with no luck. Bit more headscratching and I'm sure the answer will appear!
justsee
A: 

Maybe you have not installed the mongrel gem. The browser automation is somehow not working with webrick and i have experienced the same silent failing the you describe here.

Adding

gem 'mongrel', '>= 1.2.0.beta.1'

to my Gemfile solved it.

+1  A: 

The issue is actually with cucumber-rails and a missing dependency on DatabaseCleaner: http://github.com/aslakhellesoy/cucumber-rails/issues#issue/36

The issue is manifested when adding a @javascript tag to a cucumber feature. By default the cucumber options suppress the warnings that would have alerted me to the fact. By updating config/cucumber.yml to:

std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip"

the error is shown when running cucumber: uninitialized constant DatabaseCleaner (NameError)

The quick fix in this case is to add gem 'database_cleaner' to the project's Gemfile.

justsee
+1  A: 

I made an example app on how to configure that: github.com/lailsonbm/contact_manager_app/

Lailson Bandeira