[rspec-users] Order guarantees of let

Ashley Moran ashley.moran at patchspace.co.uk
Mon Aug 9 08:38:55 EDT 2010


Hi

I was just about to replace a `before` block along the lines of:

  before(:each) do
    @cti_b_id = service.create(name: "Item-B")
    @cti_z_id = service.create(name: "Z-Item")
    @cti_a_id = service.create(name: "Item-A")
    # ...
  end

with

   let!(:cti_b_id) { ... }
   let!(:cti_z_id) { ... }
   let!(:cti_a_id) { ... }

But then I wondered - since the spec depends on the order they are created in (it proves ordering is independent of creation order) - is the run order of `let!` guaranteed?  I imagine they run in the order I expect (ie top to bottom), but I wondered if that was an explicitly stated property of RSpec?

Cheers
Ash

-- 
http://www.patchspace.co.uk/
http://www.linkedin.com/in/ashleymoran



More information about the rspec-users mailing list