我正在尝试实施一个基本的黄瓜脚本。我想要做的就是假装在数据库中添加一些东西,然后使用黄瓜来检查数据是否出现在我的视图中。我知道,如果数据确实存在,数据将在视图中正确显示,但使用FactoryGirl会搞砸一些事情。
这就是我正在做的事情:
特征/ news.feature:
Scenario: News on the home page
Given a news article exists with the title "I love mung"
When I go to the root page
Then I should see "I love mung" within ".news"
特征/ step_definitions / news_steps.rb:
Given /^a news article exists with the title "([^"]+)"$/ do |title|
# I've added the FactoryGirl::Syntax::Methods to the `World`
create :news, title: title
# If I check the data here, it seems to think everything is ok
expect(News.find_by(title: title).title).to eql title
end
应用程序/视图/信息/ welcome.html.erb
<% if news_article %>
<!-- This element never displays (according to cucumber) -->
<div class="news">
<h3><%= news_article.title %></h3>
</div>
<% end %>
我错过了什么?