4

I'm using cucumber with capybara

I've got several similar errors.

For step:

Then /I should see movies of rating 'PG' or 'R'/ do
  page.body.should match(/<td>PG<\/td>/)
  page.body.should match(/<td>R<\/td>/)
end

Cucumber error:

undefined method `match' for #<Cucumber::Rails::World:...> (NoMethodError)
./features/step_definitions/movie_steps.rb:37:in 
   `/I should see movies of rating 'PG' or 'R'/'

For step:

Then /I should see an empty table/ do
  page.body.scan(/<tr>/).length.should == 0
end

Cucumber error:

undefined method `should' for 1:Fixnum (NoMethodError)
./features/step_definitions/movie_steps.rb:46:in 
      `/I should see an empty table/'

And for step:

Then /I should see all of the movies/ do
  Movie.find(:all).length.should page.body.scan(/<tr>/).length
end

undefined method `should' for 10:Fixnum (NoMethodError)
./features/step_definitions/movie_steps.rb:59:in 
    `/I should see all of the movies/'

The whole file of steps is here

As you can see these errors are quite similar but I can't understand what cause this problem.

Dave Schweisguth
  • 36,475
  • 10
  • 98
  • 121
megas
  • 21,401
  • 12
  • 79
  • 130

3 Answers3

9

It looks to me like you are having problems with the rspec-expectations. Try to add

require 'rspec/expectations'

to your env.rb and the equivalent to your Gemfile.

Benjamin
  • 1,726
  • 1
  • 14
  • 35
1

If you're using MiniTest instead of Rspec, try assert

i.e.

assert page.body.scan(/<tr>/).length == 0, "Expected to not find <tr> in page. "
Abdo
  • 13,549
  • 10
  • 79
  • 98
0

Just to offer an alternative (thought @dabai's solution is probably the best), you can use an assertion instead, like:

assert Movie.find(:all).length == page.body.scan(/<tr>/).length