0

我是 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 %>
4

2 回答 2

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."

看看发生了什么。

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

于 2010-01-26T01:07:43.293 回答
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
于 2010-01-26T05:25:16.917 回答