本文介绍了Rails / Cucumber / Webrat:redirect_to,flash [:notice]不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚来到Cucumber,一直在Ryan Bates的铁路旁边。 http://railscasts.com/episodes/155-beginning-with-cucumber

I'm new to Cucumber and have been stepping through a railscast by Ryan Bates. http://railscasts.com/episodes/155-beginning-with-cucumber

不幸的是,我的情况是在轨道通过的地方失败。具体来说,它是失败的步骤:然后我应该看到新文章创建。

Unfortunately my scenario is failing where the railscast passes. Specifically it is failing on the step: Then I should see "New Article Created."

它给我以下错误:

*然后我应该看到新文章创建。
希望以下元素的内容包含新文章创建。

*Then I should see "New Article Created." expected the following element's content to include "New Article Created.":

Title
Content

(Spec :: Expectations :: ExpectationNotMetError)
./features/step_definitions/web_steps.rb: 144:in / ^(?: | I)should see([^ \] *)$ /'
features / manage_articles.feature:18:in
然后我应该看到新文章创建。'*

(Spec::Expectations::ExpectationNotMetError) ./features/step_definitions/web_steps.rb:144:in /^(?:|I )should see "([^\"]*)"$/' features/manage_articles.feature:18:inThen I should see "New Article Created."'*

这是源代码:

manage_articles.feature

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

articles_controller.rb

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

index.html.erb

index.html.erb

<p><%= flash[:notice] %></p>
<% for article in @articles %>
    <p><%=h article.title %></p>
    <p><%=h article.content %></p>
<% end %>

<%= link_to "New Article", new_article_path %>


推荐答案

$ c>然后我应该看到新文章创建。:

I think you must add this line before Then I should see "New Article Created.":

And I press "Create"

所以,这里是你的完整场景:

So, here is your complete scenario:

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

这篇关于Rails / Cucumber / Webrat:redirect_to,flash [:notice]不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 15:27