Rails / Cucumber / Webrat:redirect_to,flash 无效

我是Cucumber的新手,并且一直在踩着Ryan Bates的转播。 http://railscasts.com/episodes/155-beginning-with-cucumber

不幸的是,我的场景在railscast通过的地方失败了。 具体来说,它是失败的步骤: Then I should see "New Article Created."

我怀疑它可能与我们正在使用的gem的不同版本有关,目前我有最新版本。

它给我以下错误:

*然后我应该看到“创建新文章”。 期望以下元素的内容包括“New Article Created。”:

 Title Content 

(Spec :: Expectations :: ExpectationNotMetError)./ feature /^(?:|I )should see "([^\"]*)"$/' features/manage_articles.feature:18:in step_definitions /web_steps.rb:144:in /^(?:|I )should see "([^\"]*)"$/' features/manage_articles.feature:18:in然后我应该看到“New Article Created。”’*

这是来源:

manage_articles.feature

 Feature: Manage Articles Scenario: Create Valid Article Given I have no articles And I am on the list of articles When I follow "New Article" And I fill in "Title" with "Spuds" And I fill in "Content" with "Delicious potatoes" Then I should see "New Article Created." And I should see "Spuds" And I should see "Delicious potatoes" And I should have 1 article 

articles_controller.rb

  ... def create @article = Article.create!(params[:article]) flash[:notice] = "New Article Created." redirect_to articles_path end 

index.html.erb

 

我想你必须先添加这一行Then I should see "New Article Created."

 And I press "Create" 

那么,这是你的完整场景:

 Feature: Manage Articles Scenario: Create Valid Article Given I have no articles And I am on the list of articles When I follow "New Article" And I fill in "Title" with "Spuds" And I fill in "Content" with "Delicious potatoes" And I press "Create" Then I should see "New Article Created." And I should see "Spuds" And I should see "Delicious potatoes" And I should have 1 article 

调试黄瓜的一个好方法是创建一些调试步骤。

在debug_steps.rb文件中,我有以下内容:

 Then /^I debug$/ do breakpoint; 0 end Then /^I open the page$/ do save_and_open_page end 

注意,save_and_open_page需要:Webrat:webrat(0.5.3)和Launchy:launchy(0.3.3)

然后添加步骤:

Then I open the page

之前Then I should see "New Article Created."

看看发生了什么。

祝好运。 希望这可以帮助。