[rspec-users] (rspec2/rails3) spec'ing the details of a controller that is not purely *skinny* by design.

Frank J. Mattia frankjmattia at gmail.com
Fri Jul 9 00:07:51 EDT 2010


> Here's a stripped down excerpt from my controller spec. I know how
> Order.should_receive(:method) works, but how do I translate that to an
> instance variable? I've tried assigns(:order).should_receive to no
> avail. Also, where do I put it? Above the post line won't work because
> @order doesn't exist but after doesn't work either because my action
> has already been run.
>
> describe OrdersController, :type => :controller do
>   context "when a user who is authenticated" do
>     before(:each) do
>       sign_in_user
>     end
>     context "requests POST /orders" do
>       context "with valid parameters" do
>         before(:each) do
>           Order.stub(:new) { mock_order(:save => true) }
>         end
>
>         it "should explicitly set created_by" do
>           post :create
>         end
>       end
>     end
>   end
> end

it "should explicitly set created_by" do
  controller.stub(:current_user) { mock_user }
  mock_order.should_receive(:created_by=).with(mock_user)
  post :create
end

This is my newly working spec. Does this look well thought out or is
there some glaring pitfall to doing it this way?

Cheers,
- FJM


More information about the rspec-users mailing list