[rspec-users] rails /lib module testing

Andy Koch andy.koch at pc-doctor.com
Mon Nov 16 14:32:35 EST 2009


I've seen several posts related, but not touching on what I'm
wondering...

I have a lib module that I'd like to do 'white-box' testing - similar
to a Rails mvc.  But I can't see how to get a handle on the internal
instance vars in the method.

here are some code snippets that probably best explain my situation...

#########################################################
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe AasmCrawler do

  context "create_message method" do
    it "should create a new Link message" do
      @link.should == Link.new
    end
  end
end
#########################################################
module AasmCrawler
  def create_message
    @link = Link.new
  end
end
#########################################################

I've tried "assigns[:link]" but "assigns" is not known.

I've also seen comments to test this via a model where it is included
- but that seems like WET testing, if this is used repeatedly why not
test it once at the source?

thanks for any help


More information about the rspec-users mailing list