Some of my specs fail after adding the rails "memoize" feature to model some model methods, producing the error "Can't modify frozen class/module" (these specs all passed before). This only happens if I try to use "and_return" within my spec, and those returned values affect the output of the method. I am not trying to change frozen values in my own code; the error is coming from the spec trying to change a frozen value. Below is an example of the type of spec for which this problem occurs. (This example is very simplified and somewhat contrived just to show the issue). Is there a known problem using memoize when you have message expectations? Any solutions/ best practices here?
Thanks.. Item model contains an attribute called "description" and contains this method: def name if x = description.to_s.match(/User_(\d+)/) u = User.find(x[1]) description.gsub(x[0], u.username) else description end end spec: it "should substitute user's username into the right place when fetching the item name" do i = Item.new(:description => 'foo User_1 bar') User.stub!(:find).with('1').and_return( mock_model(User, :name => 'a name') ) i.name.should == 'foo a name bar' end
_______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users