[rspec-users] Order guarantees of let

David Chelimsky dchelimsky at gmail.com
Mon Aug 9 08:49:45 EDT 2010


On Aug 9, 2010, at 7:38 AM, Ashley Moran wrote:

> 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?

Yes, eval'd in order. No, not explicitly stated, but I think it should be. Want to submit a patch with a spec for this?

> 
> Cheers
> Ash
> 
> -- 
> http://www.patchspace.co.uk/
> http://www.linkedin.com/in/ashleymoran
> 
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users



More information about the rspec-users mailing list