Search code examples
ruby-on-railsruby-on-rails-3rspecdevisecancan

RSPEc - undefined method `stubs' for #<RoomsController:0x0000010534c050>


I'm trying to write an rspec for my Rooms controller to test permissions with CanCan but keep getting the error in the title. I'm following the steps here under Controller Testing: https://github.com/ryanb/cancan/wiki/Testing-Abilities

room_controller_spec.rb

require 'spec_helper'

describe RoomsController do

  before(:each) do
    @user_1 = Factory.create(:user, :password => 'password')
    @room_for_user_1 = Room.create(:user_id => @user_1.id)

    @ability = Object.new
    @ability.extend(CanCan::Ability)
    @controller.stubs(:current_ability).returns(@ability)
  end

  describe "Room Permissions" do

    it "should allow a user to join a room" do
      @ability.can :show, @room_for_user_1
      get :show, { :uuid => @room_for_user_1.uuid }
      response.should render_template("show")
    end

  end

end

Any advice on how I can get devise + CanCan + RSpec working so I can test the controller? Thanks


Solution

  • That's not RSpec syntax, what you want is:

    @controller.stub!(:current_ability).and_return(@ability)