我是Cucumber的新手,并且一直在踩着Ryan Bates的铁路视频。 http://railscasts.com/episodes/155-beginning-with-cucumber
不幸的是,我的方案在railscast通过的地方失败了。具体而言,该步骤失败:Then I should see "New Article Created."
我怀疑它可能与我们正在使用的宝石的不同版本有关,目前我有最新版本。
它给了我以下错误:
*然后我应该看到“New Article Created”。 期望以下元素的内容包括“New Article Created。”:
Title
Content
(规格::期望:: 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
articles_controller.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 %>
答案 0 :(得分:5)
调试黄瓜的一个好方法是创建一些调试步骤。
在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."
看看发生了什么。
祝你好运。希望这会有所帮助。答案 1 :(得分:1)
我认为您必须在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