Note that there are some explanatory texts on larger screens.

plurals
  1. POFactory Girl Rails 4 association works in console, but not through Cucumber
    primarykey
    data
    text
    <p>I have a Rails 4 application with a series of associations: Posts have_many Reviews, Reviews have_one Assumption. I have set up Factories to generate Reviews with Assumptions:</p> <pre><code>FactoryGirl.define do factory :review do association :post, factory: :post ...fields... factory :review_with_assumption do after(:create) do |review| FactoryGirl.create(:assumption, assumable: review) end end end end </code></pre> <p>The following works perfectly in the console:</p> <pre><code>post = FactoryGirl.create(:post) rev = FactoryGirl.create(:review_with_assumption, post: post) rev.assumption.valid? =&gt; true post.reviews.first.assumption.valid? =&gt; true </code></pre> <p>And all the fields are exactly as they are set in my Factory definitions -- for example, each Assumption includes a 'score' of 6. However, when I use the following Cucumber steps, the Review is created but its Assumption is not:</p> <pre><code>Given(/^the post "(.*?)"'s review "(.*?)" has an assumption$/) do |arg1, arg2| post = FactoryGirl.create(:post, name: arg1) rev = FactoryGirl.create(:review_with_assumption, name: arg2, post: post) end Then(/^I should see the "(.*?)" review assumption's score$/) do |arg2| rev = Review.find_by_name(arg2) page.should have_content rev.assumption.score end </code></pre> <p>So I get an error that looks like:</p> <pre><code>And I should see the "Test Rev" review assumption's score undefined method `score' for nil:NilClass (NoMethodError) </code></pre> <p>The page content it is trying to render works perfectly in the browser if I input everything manually. Why doesn't it also work through Factory Girl and Cucumber?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload