2011-12-15 64 views
2

當我成立了一個新的Rails 3.1.3項目,並寫了黃瓜故事Webrat代碼,就像這樣:未定義Webrat方法黃瓜

response.should contain("abc") 

和我跑rake cucumber,我得到:

undefined method `contain' for #<Cucumber::Rails::World:0x00000003d2c578> (NoMethodError) 

我相信無論是Cucumber還是Webrat或者Rails都會因爲我沒有做任何特殊的事情而被破壞,並且堅持使用文檔。

以下步驟重現該錯誤:

  • rvm 1.9.2
  • rails new testapp -d mysql
  • cd testapp
  • {{編輯的database.yml}}
  • rake db:create
  • rake db:migrate
  • gem install cucumber-rails
  • gem install webrat
  • gem install database_cleaner
  • {{編輯Gemfile中包含 '黃瓜軌', 'webrat' 和 'database_cleaner' 沒有版本號}}
  • bundle install
  • rails g cucumber:install
  • rails g controller genres index
  • 將「resources:genres」添加到routes.rb
  • {{軌S和http://localhost:3000/genres作品現在}}
  • 與內容創建/features/create_movie.feature:

Feature: Create movie

Description 

    Scenario: Create a movie in genre 
    Given a genre named Comedy 
    When I create a movie Caddyshack in the Comedy genre 
    Then Caddyshack should be in the Comedy genre 

  • 與內容創建/features/step_definitions/movie_steps.rb:

Given /^a genre named Comedy$/ do end

When /^I create a movie Caddyshack in the Comedy genre$/ do 
end 

Then /^Caddyshack should be in the Comedy genre$/ do 
    visit genres_path 
    response.should contain("abc") 
end 

軌3.1.3
黃瓜1.1.4
黃瓜軌1.2.1
webrat 0.7。 3
機架1.3.5
耙0.9.2。2

有關如何解決此問題的任何提示?

回答

2

現在默認黃瓜,而不是使用Webrat Capybary。

您需要改用have_content。

下面

正確的片段:

When /^I create a movie Caddyshack in the Comedy genre$/ do 
end 

Then /^Caddyshack should be in the Comedy genre$/ do 
    visit genres_path 
    response.should have_content("abc") 
end