I would separate testing from preparing a test to make it cleaner. This means that in your example for this one long test:
You can put this in before(:all) and then do separate tests:
before(:all) do
In addition, you should also check the before(:all) steps in separate tests:
it "should be able to create an account with account_type" do # create an account factory with trait account_type # assert it worked end it "should be able to create a manager for an account" do # create an account factory with trait account_type # no assertion that it worked (that is tested before) # create manager factory for the account # assert manager got correctly created end it "should be able to opt-in to accounts" do # create an account factory with trait account_type # no assertion that it worked (that is tested before) # 5 people factories opt-in to that account # assert that it worked end it "should be able to opt-in to accounts" do # create an account factory with trait account_type # 5 people factories opt-in to that account # 1 person then opts out # assert that it worked end
There is little code duplication, but this makes the tests simple and readable, and so I would go for it.
Finally, to organize your tests, use shared_context . Therefore, if you need to prepare the same things in different tests / files, include them as shared_context :
That way you can just use include_context 'big message broadcast' so that it is prepared wherever you like.
source share