On 14 Apr 2009, at 16:14, Brandt Kurowski wrote:

On Apr 13, 11:26 am, Pat Maddox <[email protected]> wrote:
If this is a module that you're using to extend the behavior of
Numeric classes, just mix it in somewhere and write examples for the
class that got the mixin.

I prefer to test modules in isolation by mixing them into a stub in
the spec, in order to make it explicit that we're describing the
module itself (not some other class), and to avoid dependencies on
that other class. For example:

 describe ArtistsHelper do
   before do
     @artist = 123.456
     class << @artist
       include ArtistsHelper
     end
   end

   it "should round stuff" do
     @artist.round_to(1).should == 123.5
   end
 end

Granted, it looks a little awkward here since it looks like the module
is meant to be used with a Numeric

Isn't it? That's probably what I would infer if I read this code.

Is there any reason why you don't do this?

    @artist = Object.new.extend(ArtistHelper)


Matt Wynne
http://beta.songkick.com
http://blog.mattwynne.net



_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to