[rspec-users] Evaluating shared example customisation block before shared block

Myron Marston myron.marston at gmail.com
Sun Aug 1 21:04:45 EDT 2010


> If we do this, we should use module_exec for both blocks so they both get the same arguments.

I actually find the use of this to be a bit confusing:

[:foo, :bar].each do |arg|
  it_should_behave_like "Something", arg do |a|
    # The value of the param is already bound to arg and now it's
bound to a, too.
  end
end

I suppose it may be useful in some situations, so I'm fine with it as
long as the implementation allows you to skip the `|a|`:

[:foo, :bar].each do |arg|
  it_should_behave_like "Something", arg do
    # no need to declare the |a| parameter since we already have it in
arg.
    # I find this to be less confusing.
  end
end

> Actually, I just discovered that ruby 1.8.7 actually added module_exec.

I should have mentioned that--my default ruby these days is 1.8.7, and
I found the same thing.

> re: order of evaluation of blocks, I think I'm inclined to go one way one minute, and another the next. Somebody convince me of one or the other.

Maybe it would be useful to make a list of the things that are
possible one way, but not the other, and vice versa...and then compare
these lists.  Which list has the more useful and commonly needed use
cases?

> a) add such a thing for module_exec as well, though I haven't quite figured out how that works yet.

This is my vote.  And I'm willing to take a stab at it--if for no
other reason then it'll help increase my understanding of ruby :).
I'm going to take a look at how rubinius implements this, and see what
ruby specs there are for it.

Myron


More information about the rspec-users mailing list