Note that there are some explanatory texts on larger screens.

plurals
  1. POrspec test passes in isolation, but fails when run with other tests
    primarykey
    data
    text
    <p>I have some specs, written in RSpec, that test various models. I use Factory Girl to generate object for testing.</p> <p>Now the most peculiar thing happens:<br> When i run <code>rspec spec/models/specific_model_spec.rb</code> --- this passes all the tests in that spec</p> <p>However, when I run <code>rspec spec/models</code> --- every test in this spec fails referring to an invalid association being created (via a factory)</p> <p>The association created by the factory is obviously valid as running the test in isolation also shows.</p> <p>What could be causing this behavior?</p> <p><strong>Update:</strong><br> The error i get when running the spec together with other specs (the error is the same for each failure):</p> <pre><code>6) StreamItem adds a stream_item to a project and consultant when an engagement is added Failure/Error: @project = Factory.create(:project, :name =&gt; 'bar' ) Validation failed: Customer is invalid # ./spec/models/stream_item_spec.rb:44:in `block (2 levels) in &lt;top (required)&gt;' </code></pre> <p>The <code>project factory</code> is tested in another spec and passes fine...</p> <p><strong>Update 2:</strong> The relevant factory code used is a follows: </p> <pre><code>Factory.define :manager, :class =&gt; User do |f| f.sequence(:email) { |n| "bar#{n}@example.com" } f.password "pass12" f.sequence(:name) { |n| "Erwin#{n}" } f.roles_mask 4 end Factory.define :customer do |f| f.sequence(:name) { |n| "foo customer#{n}" } f.association :last_actor, :factory =&gt; :manager f.account_id 1 end Factory.define :project do |f| f.sequence(:name) { |n| "foo project#{n}" } f.association :manager, :factory =&gt; :manager f.association :customer, :factory =&gt; :customer f.start_date Date.today &lt;&lt; 1 f.finish_date Date.today &gt;&gt; 2 f.status 1 f.association :last_actor, :factory =&gt; :manager f.account_id 1 end </code></pre>
    singulars
    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.
 

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