黄瓜未定义的方法

meg*_*gas 4 rspec ruby-on-rails cucumber rspec-expectations

我使用的是cucumbercapybara

我有几个类似的错误.

对于步骤:

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
Run Code Online (Sandbox Code Playgroud)

黄瓜错误:

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'/'
Run Code Online (Sandbox Code Playgroud)

对于步骤:

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

黄瓜错误:

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

并为步骤:

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/'
Run Code Online (Sandbox Code Playgroud)

整个文件的步骤就在这里

正如您所看到的,这些错误非常相似,但我无法理解导致此问题的原因.

dab*_*bai 9

在我看来,你对rspec期望有问题.尝试添加

require 'rspec/expectations'
Run Code Online (Sandbox Code Playgroud)

到您的env.rb和等效的Gemfile.