Search code examples
ruby-on-railstestingrspecmodelsshoulda

How can I reduce rspec test dependency?


If 1 test fails, tons of others do. How could I change this so that the other checks (the "it's") below only get done if should be_valid is true, i.e. how can I nest the following "it"'s. I can create a different context for all the other ones and have be_valid on its own but how do I ensure that they are dependent (in a good way in this case! e.g. they won't run).

describe Gorilla do
  context "is valid" do
    subject { Factory.build(:gorilla) }
    it { should be_valid }
    it { should have_many :gorilla_memberships}
    it { should have_many(:gorilla_groups).through(:gorilla_memberships) }
    it { should have_many :gorilla_observations }
    it { should have_one(:avatar).through(:gorilla_observations) }
    it { should have_one(:noseprint).through(:gorilla_observations) }
...

Solution

  • There is no explicit support for creating any sort of relationship between examples in rspec.