2010-01-25 2 views
0

Я новичок в Cucumber и перешел через railscast Райана Бейтса. http://railscasts.com/episodes/155-beginning-with-cucumberРельсы/Огурцы/Webrat: redirect_to, flash [: notice] не работает

К сожалению, мой сценарий терпит неудачу, когда проходит railscast. В частности, он не работает на этапе: Then I should see "New Article Created."

Я подозреваю, что это может иметь какое-то отношение к различным версиям драгоценных камней, которые мы используем, в настоящее время у меня есть последняя из каждой.

Это дает мне следующую ошибку:

* Тогда я должен увидеть «новую статью Created.» ожидается содержание следующего элемента, чтобы включить "новую статью Created.":

Title 
Content 

(Spec :: Ожидания :: 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 

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

ответ

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 
+0

Спасибо! Тупая ошибка с моей стороны. – Evan

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

Чтобы узнать, что произойдет.

Удачи. Надеюсь это поможет.

+0

Спасибо! Если бы у меня было это, мне бы не нужно было публиковать. – Evan

+0

Большое спасибо за советы! – benoitr