It is a bit ugly but here is an initial port of the Shoulda ActiveRecord 
macros:

http://gist.github.com/14050

I did not try running ALL of the macros, but most of them.  Before going 
too far with it, I would appreciate some recommendations as to how to 
improve the flow.  The Shoulda version has a different feel to it since 
the assertions cause the code to die early.  Whereas the RSpec 
conversion I did mostly wrap each should call in its own it block.

Thanks for the help!  I learned a lot from this exercise!

Andy

David Chelimsky wrote:
> On Tue, Sep 30, 2008 at 9:38 AM, Ben Mabey <[EMAIL PROTECTED]> wrote:
>>>> This makes things a lot simpler and cleaner than having to hack away
>>>>>
>>> Here's a variation on that with a helper for defining macros that I'm
>> I like it.  For rspec-rails it would also be nice to be able to say:
>> Also, instead of yielding within another block you can simply pass in the
>> given block as an arg:
>>
>> def define_macros(&macro_block)
>>  Spec::Example::ExampleGroupMethods.extend Module.new(&macro_block)
>> end
> 
> Close but not quite. Here are two similar examples that work:
> 
> def define_macros(&block)
>   Spec::Example::ExampleGroupMethods.module_eval(&block)
> end
> 
> def define_macros(&block)
>   Spec::Example::ExampleGroupMethods.extend Module.new(&block.call)
> end
> 
> I think the first is nicer if we're not too concerned with control or
> traceability, but the second, w/ the Module.new on a separate line,
> would support maintaining references to the module (if that would be
> useful).
> 
> Cheers,
> David

-- 
Posted via http://www.ruby-forum.com/.
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to