Rails / Cucumber / Webrat: redirect_to, flash [: notice] does not work

I am new to Cucumber and go through the railscast of Ryan Bates. http://railscasts.com/episodes/155-beginning-with-cucumber

Unfortunately, my script does not work when railscast passes. In particular, it does not work on the step: Then I should see "New Article Created."

I suspect that this may have something to do with the different versions of the gems we use, I currently have the last one.

This gives me the following error:

* Then I should see "Created New Article". expected the following elemental content to include "Create Article" .:

 Title Content 

(Spec :: Expectations :: ExpectationNotMetError). / features / step _definitions / web_steps.rb: 144: in /^(?:|I )should see "([^\"]*)"$/' features/manage_articles.feature:18:in Then I should see" New article created. "* *

This is the source:

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
ruby-on-rails cucumber webrat
source share
2 answers

I think you should add this line before Then I should see "New Article Created." :

 And I press "Create" 

So here is your complete scenario:

 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 
+1
source share

A good trick for debugging a cucumber is to create some debugging steps.

In the debug_steps.rb file, I have the following:

 Then /^I debug$/ do breakpoint; 0 end Then /^I open the page$/ do save_and_open_page end 

Note that save_and_open_page requires: Webrat: webrat (0.5.3) and Launchy: launchy (0.3.3)

Then add the step:

Then I open the page

until Then I should see "New Article Created."

To find out what is going on.

Good luck. Hope this helps.

+5
source share

All Articles