[rspec-users] Newbie: Rspec, Webrat, Mechanize, Cucumber

DVG devryguy at gmail.com
Wed May 6 20:08:00 EDT 2009


Alright, I'm trying to get up to speed with using Rspec, Webrat,
Mechanize and Cucumber to test a non rails application.

The RSpec Matchers (I think) seem to not be working as expected. When
I run my feature, it says the world cannot find the method "contain"

I have the following gems installed:
cucumber 0.3.2
rspec 1.2.6
mechanize 0.9.2
webrat 0.4.4

My feature is as follows:
Feature: Google
	In order to buy a sweet new laptop
	As a apple enthusiest
	I want to find apple.com

	Scenario: Search for apple
		Given I visit "http://www.google.com"
		When I fill in "q" with "apple.com"
		And I press "Google Search"
		Then I should see "www.apple.com"

#env.rb
require 'webrat'

Webrat.configure do |config|
  config.mode = :mechanize
end

require 'webrat/core/matchers'
require 'webrat/mechanize'
class MechanizeWorld < Webrat::MechanizeSession
  require 'spec'
  include Spec::Matchers
end

World do
  MechanizeWorld.new
end

#webrat_steps
...
Given /^I visit "(.*)"$/ do |url|
    visit(url)
end

When I run the feature, everything passes except for the last step,
"should see"
Then /^I should see "([^\"]*)"$/ do |text|
  response.should contain(text)
end

The error it gives is:

    Then I should see "www.apple.com"
      undefined method `contain' for #<MechanizeWorld:0x429aa64>
(NoMethodError)
      ./features/step_definitions/webrat_steps.rb:94:in `/^I should
see "([^\"]*)"$/'
      features/google.feature:10:in `Then I should see
"www.apple.com"'

As far as I know, contain is an rspec matcher which is getting
included in MechanizeWorld, but it doesn't seem to be working
properly.

Any ideas?


More information about the rspec-users mailing list