On Aug 1, 2010, at 10:08 PM, Myron Marston wrote:

> OK, I tried to implement #module_exec on ruby 1.8.6, and here's what I
> came up with:
> 
> http://github.com/myronmarston/rspec-core/commit/364f20ebd5b7d9612227cb6e86a6e8c8c2e9931e
> 
> 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.  

If we're not exposing this as an API, and we're only using it in order to 
support this feature in RSpec when running Ruby 1.8.6, and it solves our 
problem, then I think it's correct as it needs to be.

> 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
> 1.0.1's:
> 
> http://github.com/evanphx/rubinius/blob/release-1.0.1/kernel/common/module.rb#L438-441
> 
> Backports (a library that implements features of later versions of
> ruby in 1.8.6) implements it in a similar fashion:
> 
> http://github.com/marcandre/backports/blob/v1.18.1/lib/backports/1.8.7/module.rb
> 
> Unfortunately, rubyspec doesn't provide much help in defining how
> module_exec should work:
> 
> http://github.com/rubyspec/rubyspec/blob/master/core/module/module_exec_spec.rb
> 
> 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:
> 
> http://github.com/rspec/rspec-core/blob/v2.0.0.beta.19/lib/rspec/core/example_group.rb#L179
> 
> 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.

Done: 
http://github.com/rspec/rspec-core/commit/7d492bdc3657ca9472368b50f3f3f6635aca7fe0

> 
> Myron

_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to