Order guarantees of let

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

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

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?

On Mon, Aug 9, 2010 at 8:49 AM, David C. [email protected]
wrote:

@cti_a_id = service.create(name: “Item-A”)

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?

But,

First of all, what’s let! as opposed to let, I can’t seem to find it
via google or the latest draft of the book.

Second, unless let! is a new method which not only defines the
memoized method but invokes it, then the order of evaluation will
depend on the order the generated let methods are invoked in the
example won’t it?


Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Github: rubyredrick (Rick DeNatale) · GitHub
Twitter: @RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale

On 9 Aug 2010, at 13:49, David C. wrote:

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?

Sure - I’ve made an action to write a spec for this. I guess the
implementation is not likely to change any time soon so I’ll do it when
I find a convenient 10 mins…

Ash


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

On Aug 9, 2010, at 10:06 AM, Rick DeNatale wrote:

@cti_z_id = service.create(name: “Z-Item”)
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?

But,

First of all, what’s let! as opposed to let, I can’t seem to find it
via google or the latest draft of the book.

http://rdoc.info/projects/rspec/rspec-core - search for let and let!

Second, unless let! is a new method which not only defines the
memoized method but invokes it

That’s what it is. Sort of. It gets invoked by an implicit before hook
which is added - those get eval’d in the order in which they get
defined.

On Aug 10, 2010, at 9:08 AM, Rick DeNatale wrote:

That’s what it is. Sort of. It gets invoked by an implicit before hook which is added - those get eval’d in the order in which they get defined.

Makes sense. So is it not (going to be) mentioned in the book, it
doesn’t seem to be in Beta 15.0 supposedly the final beta version.

Correct. At this point in the production process (indexing) there is no
room to add new technical content to the book.

On Mon, Aug 9, 2010 at 11:21 AM, David C. [email protected]
wrote:

First of all, what’s let! as opposed to let, I can’t seem to find it
via google or the latest draft of the book.

http://rdoc.info/projects/rspec/rspec-core - search for let and let!

Second, unless let! is a new method which not only defines the
memoized method but invokes it

That’s what it is. Sort of. It gets invoked by an implicit before hook which is added - those get eval’d in the order in which they get defined.

Makes sense. So is it not (going to be) mentioned in the book, it
doesn’t seem to be in Beta 15.0 supposedly the final beta version.


Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Github: rubyredrick (Rick DeNatale) · GitHub
Twitter: @RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale