0

実装しようとしている基本的なキュウリ スクリプトに頭がおかしくなりそうです。私がやりたいことは、データベースに何かを追加するふりをしてから、キュウリを使用してデータがビュー内に表示されていることを確認することだけです。データが実際に存在する場合、データがビューで正しく表現されるという事実は知っていますが、FactoryGirl を使用すると何かが台無しになります。

これが私がやっていることです:

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

私は何が欠けていますか?

4

0 に答える 0