Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cucumber undefined methods

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.

like image 642
megas Avatar asked Dec 26 '22 22:12

megas


2 Answers

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.

like image 163
Benjamin Avatar answered Dec 30 '22 08:12

Benjamin


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. "
like image 31
Abdo Avatar answered Dec 30 '22 06:12

Abdo