assign_to failing in Rails 3 / RSpec 2 / Shoulda 2.11.3 (Expected action to assign a value for @var)

490 views
Skip to first unread message

Dan Ryan

unread,
Sep 20, 2010, 5:09:15 PM9/20/10
to shoulda
I'm having trouble testing a Rails 3 app with RSpec (2.0.0.beta.22)
and Shoulda (2.11.3) matchers:

http://pastie.org/1170752

The closest thing I could find to this was
http://rspeicher.tumblr.com/post/1111927237/an-rspec2-shoulda-controller-gotcha,
but as you can see from the above pastie, I have followed the advice.

assigns(:var) works, but the assign_to(:var) matcher does not. What's
the fix? What other info do you need from me?

Thanks!
Dan

mhenrixon

unread,
Mar 6, 2011, 12:19:59 PM3/6/11
to sho...@googlegroups.com
Also have the same problem I followed the blog post but assign_to doesn't work. Anything I can do to help?

mhenrixon

unread,
Mar 6, 2011, 12:27:03 PM3/6/11
to sho...@googlegroups.com
this works for me : 
    it "should assign to orders" do
      assigns[:orders].should == @orders
    end          
Really frustrating! :) 
 

Mikael Henriksson

unread,
Mar 6, 2011, 1:44:44 PM3/6/11
to Dan Croak, sho...@googlegroups.com
The blog post that the first post in the thread refers to : http://rspeicher.tumblr.com/post/1111927237/an-rspec2-shoulda-controller-gotcha

subject { controller }
it { should assign_to :order } #is not working for me

# the following works
it "should assign to orders" do
   assigns[:orders].should == @orders
end 



Mikael Henriksson

Tel: +46 (0) 730- 393 200 
http://flavors.me/mhenrixon

On Sunday, March 6, 2011 at 7:05 PM, Dan Croak wrote:

Which blog post? What was the code that wasn't working for you?


On Sun, Mar 6, 2011 at 12:19 PM, mhenrixon <mik...@zoolutions.se> wrote:
Also have the same problem I followed the blog post but assign_to doesn't
work. Anything I can do to help?

--
Individuals over processes. Interactions over tools.

Agile Rails training from thoughtbot, the makers of Clearance, Shoulda, &
Factory Girl:
http://thoughtbot.com/services/training

The Shoulda group:
http://groups.google.com/group/shoulda

To post to this group, send email to
sho...@googlegroups.com

To unsubscribe from this group, send email to
shoulda+u...@googlegroups.com

Mikael Henriksson

unread,
Mar 6, 2011, 1:58:51 PM3/6/11
to sho...@googlegroups.com

Forwarded message:

Ok, full code comming up 
  context "as admin" do
    before do
      user = Factory(:admin)
      @orders = []
      10.times do
        @orders << Factory(:order)
      end
      sign_in user
      User.current = user
      controller.stubs(:current_user).returns(user)
      Order.stubs(:all_for_index).returns(@orders)

      get :index
    end

    subject { controller }
    
    it { should assign_to(:orders) } #this does not work
    # this works fine
    it "should assign to orders" do
      assigns[:orders].should == @orders
    end
    it { should respond_with(:success) }
    it { should respond_with_content_type(:html) }
    it { should render_template(:index) }
    it { should_not set_the_flash }
  end   

Reply all
Reply to author
Forward
0 new messages