cucumber's web_step#follow using capybara produces a NameError

Question!

Does anyone know why I get the following error when I use the web_step#follow method?

When I follow "Stuff" within "#main-nav"               # features/step_definitions/web_steps.rb:33
  undefined local variable or method `node' for #<Capybara::Driver::RackTest::Node:0x00000101409b40> (NameError)
  ./features/step_definitions/web_steps.rb:35:in `block (2 levels) in <top (required)>'
  ./features/step_definitions/web_steps.rb:14:in `block in with_scope'
  ./features/step_definitions/web_steps.rb:14:in `with_scope'
  ./features/step_definitions/web_steps.rb:34:in `/^(?:|I )follow "([^"]*)"(?: within "([^"]*)")?$/'

This is the html output:

<ul id='main-nav'> 
  <li><a href="/things">Things</a></li> 
  <li><a href="/stuff">Stuff</a></li> 
</ul>

P.S. I have removed webrat and am solely using capybara

Thanks in advance!

By : Coderama


Answers

This means that the actual output of your page does not include the element you're trying to search for. For example, if you had with_scope("#my_div") but your content didn't have any divs with the id my_div it would raise this exception.

I'd suggest trying to add a cucumber step of Then show me the page before the failing step, and investigate the source of the generated page.



per: https://github.com/jnicklas/capybara/issues/110

comment out this line in env.rb:

require 'cucumber/rails/capybara_javascript_emulation'

Note: after commenting that line you'll have to explicitly tag your features/scenarios with @javascript if you want to click links with onclick javascript handlers.

See also: https://github.com/aslakhellesoy/cucumber-rails/issues/77 which eventually takes you on a journey to discover it should be fixed in cucumber-rails v0.4.0 (2011-03-20). This may still be relevant for folks with Rails 2.3.x projects using cucumber-rails v0.3.2



This video can help you solving your question :)
By: admin