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
do_action
@class_name.constantize.should_receive(:find).with
(params).and_return @instance_var_contents
end
it "should assign the instance variable to the template" do
do_action
[EMAIL PROTECTED] == @instance_var_contents
end
where @class_name would be a string like "Foo"
Scott
def find_foo
@foo = Foo.find(params[:id]
end
...
controller.stub!(:find_foo).and_assigns(:foo, "123")
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users