我是 Cucumber 的新手,一直在看 Ryan Bates 的 railscast。http://railscasts.com/episodes/155-beginning-with-cucumber
不幸的是,我的场景在 railscast 通过的地方失败了。具体来说,它在步骤上失败了:Then I should see "New Article Created."
我怀疑这可能与我们使用的不同版本的 gem 有关,目前我有最新的。
它给了我以下错误:
*然后我应该看到“已创建新文章”。期望以下元素的内容包括“已创建新文章。”:
Title
Content
(Spec::Expectations::ExpectationNotMetError) ./features/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
文章控制器.rb
...
def create
@article = Article.create!(params[:article])
flash[:notice] = "New Article Created."
redirect_to articles_path
end
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 %>