Rails/Cucumber/Webrat:redirect_to、flash[:notice] 不起作用
我是 Cucumber 的新手,一直在逐步学习 Ryan Bates 的 Railscast。 http://railscasts.com/episodes/155-beginning-with-cucumber
不幸的是,我的场景在railscast 经过的地方失败了。具体来说,它在以下步骤中失败:然后我应该看到“已创建新文章。”
我怀疑这可能与我们正在使用的宝石的不同版本有关,目前我有最新的每个。
它给了我以下错误:
*然后我应该看到“新文章已创建”。 期望以下元素的内容包含“已创建新文章。”:(
Title
Content
Spec::Expectations::ExpectationNotMetError) ./features/step_definitions/web_steps.rb:144:in /^(?:|I ) 应该看到 "([^\"]*)"$/' features/manage_articles.feature:18:in
然后我应该看到“New Article Created”。'*
这是来源:
manage_articles.feature
功能:管理文章 场景:创建有效文章 鉴于我没有文章 我在文章列表中 当我关注“新文章”时 我用“马铃薯”填写“标题” 我在“内容”中填写“美味的土豆” 然后我应该看到“新文章已创建”。 我应该看看“土豆” 我应该看看“美味土豆” 我应该有 1 篇文章
文章_controller.rb
...
def create
@article = Article.create!(params[:article])
flash[:notice] = "New Article Created."
redirect_to articles_path
end
索引.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 %>
I'm new to Cucumber and have been stepping through a railscast by Ryan Bates. http://railscasts.com/episodes/155-beginning-with-cucumber
Unfortunately my scenario is failing where the railscast passes. Specifically it is failing on the step: Then I should see "New Article Created."
I suspect it may have something to do with the differing versions of the gems we are using, currently I have the latest of each.
It gives me the following error:
*Then I should see "New Article Created."
expected the following element's content to include "New Article Created.":
Title
Content
(Spec::Expectations::ExpectationNotMetError)
./features/step_definitions/web_steps.rb:144:in /^(?:|I )should see "([^\"]*)"$/'
Then I should see "New Article Created."'*
features/manage_articles.feature:18:in
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 %>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
调试 Cucumber 的一个好技巧是创建一些调试步骤。
在 debug_steps.rb 文件中,我有以下内容:
注意,save_and_open_page 需要:
Webrat:webrat (0.5.3)
和 Launchy: launchy (0.3.3)
然后添加步骤:
然后我打开页面
,然后
然后我应该看到“新文章已创建。”
看看发生了什么。
祝你好运。希望这有帮助。
A good trick to debugging cucumber is to create some debugging steps.
In a debug_steps.rb file I have the following:
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
before
Then I should see "New Article Created."
To see what is going on.
Good luck. Hope this helps.
我认为您必须在
然后我应该看到“New Article Created”之前添加此行。
:所以,这是您的完整场景:
I think you must add this line before
Then I should see "New Article Created."
:So, here is your complete scenario: