我对我正在尝试实现的基本黄瓜脚本感到疯狂。我要做的就是假装在数据库中添加一些东西,然后使用 cucumber 检查数据是否出现在我的视图中。我知道如果数据确实存在,数据将在视图中正确表示,但使用 FactoryGirl 会搞砸一些事情。
这就是我正在做的事情:
功能/新闻。功能:
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
app/views/info/welcome.html.erb
<% if news_article %>
<!-- This element never displays (according to cucumber) -->
<div class="news">
<h3><%= news_article.title %></h3>
</div>
<% end %>
我错过了什么?