0

私は Cucumber を初めて使用し、Ryan Bates による Railscast を踏んでいます。http://railscasts.com/episodes/155-beginning-with-cucumber

残念ながら、レールキャストが通過する場所で私のシナリオは失敗しています。具体的には、次のステップで失敗しています。Then I should see "New Article Created."

私たちが使用しているgemの異なるバージョンと関係があるのではないかと思います.現在、私はそれぞれの最新のものを持っています.

次のエラーが表示されます。

※すると「記事を新規作成しました」と表示されます。は、次の要素のコンテンツに「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「新しい記事が作成されました」と表示されます。

これはソースです:

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

article_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 %>
4

2 に答える 2

5

cucumber をデバッグするための良い方法は、いくつかのデバッグ ステップを作成することです。

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 に答える