4

で使っcucumberていますcapybara

同様のエラーがいくつかあります。

ステップの場合:

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

きゅうりエラー:

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'/'

ステップの場合:

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

きゅうりエラー:

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

そしてステップのために:

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/'

手順のファイル全体はこちら

ご覧のとおり、これらのエラーは非常に似ていますが、この問題の原因がわかりません。

4

3 に答える 3

9

rspec-expectationsに問題があるように見えます。追加してみてください

require 'rspec/expectations'

env.rbおよびGemfileと同等のものに。

于 2012-06-17T20:56:43.250 に答える
1

Rspec の代わりに MiniTest を使用している場合は、試してください。assert

すなわち

assert page.body.scan(/<tr>/).length == 0, "Expected to not find <tr> in page. "
于 2013-07-19T20:07:12.227 に答える
0

代わりの方法を提供するために (@dabai のソリューションがおそらく最適だと思います)、代わりに次のようなアサーションを使用できます。

assert Movie.find(:all).length == page.body.scan(/<tr>/).length
于 2012-10-28T21:08:11.300 に答える