[rspec-users] How to write a spec file for a helper

Brandt Kurowski brandtkurowski at gmail.com
Tue Apr 14 11:14:05 EDT 2009

On Apr 13, 11:26 am, Pat Maddox <pat.mad... at gmail.com> 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

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

Granted, it looks a little awkward here since it looks like the module
is meant to be used with a Numeric, but in general I find this
approach to be pretty clean.


More information about the rspec-users mailing list