I am trying to use Cucumber+webrat+mechanize to test some web pages. In a simple example, I set up something like
...
And I goto Home
Then I should see "Welcome"
And I have the following in my step file:
Then /^I should see "([^\"]*)"$/ do |text|
response_body.should contain(text)
end
I get an error, complaining that there is no "content" on nilClass... When I look closer, I notice that the response variable is nil when the "Then I should see..." clause is being executed. Any idea why?
If I replace "Then I should see ..." with "And I click on ...", I can successfully click on a link using Mechanize, so clearly webrat/mechanize got the dom and is able to following a link, but somehow, I am not getting the response variable.
My env.rb looks like
require 'webrat'
include Webrat::Methods
include Webrat::Matchers
Webrat.configure do |config|
config.mode = :mechanize
end
require 'webrat/core/matchers'
class MechanizeWorld < Webrat::MechanizeAdapter
require 'spec'
include Spec::Matchers
end
World do
MechanizeWorld.new
end
Thanks.