[rspec-users] Stumped with nil Class error
Ants Pants
antsmailinglist at gmail.com
Sun Jan 9 08:58:57 EST 2011
Thanks for the reply but I've sorted it. I implemented this
http://iain.nl/2008/11/authlogic-is-awesome/
<http://iain.nl/2008/11/authlogic-is-awesome/>I think the instance variables
in this example replicate how they will look in the actual controller (thus
enabling me to stub them/set message expectations.
Anyway, I eventually got it working and can now press on.
Again, thanks for taking the time to reply.
On 8 January 2011 03:40, Mike Mazur <mmazur at gmail.com> wrote:
> Hi,
>
> On Sat, Jan 8, 2011 at 01:58, Ants Pants <antsmailinglist at gmail.com>
> wrote:
> > I thought that the controller.stub(:require_member).and_return(member)
> would
> > suffice for the require_member stuff but I'm obviously wrong. I've even
> > replaced the member for @member in my spec but to no avail.
> > Here's the describe example ....
> > describe "PUT edit" do
> > context "Product cut-off has passed" do
> > let(:member) { mock_model(Member).as_null_object }
> > let(:product) { mock_model(Product).as_null_object }
> > ## I just want it to create a @product object from
> > it "creates a product object" do
> > controller.stub(:require_member).and_return(member)
> > member.should_receive(:products)
> > get :edit, :id => "1"
> > end
> > end
> > end
> > If anyone would be able to untangle me, I'd be greatly appreciative.
>
> Your stub returns member, but require_member sets the @member instance
> variable. Try modifying your stub to something like this (untested):
>
> controller.stub(:require_member) { assigns(:member) = member }
>
> HTH,
> Mike
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110109/2237032b/attachment-0001.html>
More information about the rspec-users
mailing list