[rspec-users] (no subject)

Scott Taylor mailing_lists at railsnewbie.com
Tue Aug 14 18:35:33 EDT 2007


On Aug 14, 2007, at 5:53 PM, Scott Taylor wrote:

>
> On Aug 14, 2007, at 5:17 PM, aslak hellesoy wrote:
>
>> On 8/14/07, Scott Taylor <mailing_lists at railsnewbie.com> wrote:
>>>
>>> How would you spec out something like the following:
>>>
>>
>> You're starting with the code, trying to tape on the spec afterwards.
>> This is always a difficult task and is exactly what BDD and RSpec is
>> trying to get you away from.
>>
>> Have you tried writing the RSpec examples first? I'd help you with an
>> example if I knew what you're trying to achieve from a functional  
>> (not
>> code) standpoint.
>
>
> Sounds fair.  The only reason I included the code first and presented
> it in that way was for simplicity.  I'll now go for the complexity:
>
> I already have developed test first, and running specs.  I'd now like
> to refactor, but my specs are preventing me.  The code is here:
>
> http://pastie.caboo.se/87722
>
> Here is the code I'd like to refactor:
>
>        def anonymous_class_with_loaded_modules(*mods)
>          klass = Class.new
>          mods.each do |mod|
>            klass.send(:include, mod)
>          end
>          return klass
>        end
>
> I'd like to change it to this, which is functionally equivalent:
>
>        def anonymous_class_with_loaded_modules(*mods)
>          klass = Class.new do
>             mods.each do |mod|
>               include, mod
>             end
>          end
>          return klass
>        end

Aslak,

Maybe dependency injection would be the way to solve this problem.   
Let me know your thoughts - I'd like to clean up this code.

Scott



More information about the rspec-users mailing list