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

Myron Marston myron.marston at gmail.com
Sun Aug 1 23:08:32 EDT 2010

OK, I tried to implement #module_exec on ruby 1.8.6, and here's what I
came up with:


It works (at least in the sense that it allows the specs and features
I added in the previous commits in that branch to pass on ruby 1.8.6),
but I don't think it's correct.  It just calls #instance_exec, but
instance_exec and module_exec are not the same (at least as I
understand them...).  However, I based that implementation on rubinius


Backports (a library that implements features of later versions of
ruby in 1.8.6) implements it in a similar fashion:


Unfortunately, rubyspec doesn't provide much help in defining how
module_exec should work:


I'd need some concrete examples demonstrating how module_exec should
work (as compared to instance_exec) to implement it correctly.  My
understanding is that they are identical except in regards to method
definitions--def's within an instance_exec define methods directly on
the Module object instance, whereas def's within a module_exec define
instance methods in the module (i.e. methods that will be added to any
class that includes the module).

One side issue I discovered is that instance_exec is implemented in
rspec-expectations, but not rspec-core (which, incidentally, is why I
linked to the cucumber implementation; I grepped in rspec-core and
couldn't find it).  instance_exec is already used in rspec-core:


It needs to be implemented in rspec-core if you want rspec-core to be
able to be used on 1.8.6 without rspec-expectations.


More information about the rspec-users mailing list