[rspec-users] stub with assigns?
mailing_lists at railsnewbie.com
Thu Dec 13 02:17:24 EST 2007
On Dec 13, 2007, at 2:00 AM, Jonathan Linowes wrote:
> is there a way to stub a method that sets an instance variable, so
> the stub sets it too?
Nope. The idea behind this is that instance variables are supposed
to be the inner representation of some data inside a class, while an
attr_accessor/reader is the public interface to other objects.
Obviously, this idea breaks down in rails. If you wanted something
like that, why not write some shared specs like this:
it "should find ..." do
it "should assign the instance variable to the template" do
assigns[@class_name.underscore].should == @instance_var_contents
where @class_name would be a string like "Foo"
> def find_foo
> @foo = Foo.find(params[:id]
> controller.stub!(:find_foo).and_assigns(:foo, "123")
> rspec-users mailing list
> rspec-users at rubyforge.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the rspec-users