[rspec-users] Controller spec with devise.

Justin Ko jko170 at gmail.com
Fri Aug 27 02:48:52 EDT 2010


This is how I do it:

before { sign_in(user_record) }

describe "#index" do
  before do
    controller.current_user.stub(:orders) { ... }
  end

  it "..." do
    get :index
  end
end

Hope that helps.

On Aug 24, 7:51 pm, Titinux <jeremie.horh... at titinux.net> wrote:
> Hello,
>
> I'm new in using RSpec and I can't figured out to spec this controller
> action.
>
> class OrdersController < ApplicationController
>   before_filter :authenticate_user!
>
>   def index
>     respond_with(@orders = current_user.orders)
>   end
> end
>
> When I want to spec this "@assets = Asset.all" I use "Asset.stub(:all)
> { [mock_asset] }" as I read in the RSpec book but with
> "current_user.orders" I don't know how to do.
>
> NB: I'm using Rails 3.0.0.rc2 and RSpec 2.0.0.beta.20
>
> Thanks in advance.
> Jérémie Horhant
> _______________________________________________
> rspec-users mailing list
> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users


More information about the rspec-users mailing list