2011-08-26 56 views
1

我正在嘗試爲我的房間控制器寫一個rspec來測試CanCan的權限,但不斷收到標題中的錯誤。我在這裏以下步驟在控制器測試:https://github.com/ryanb/cancan/wiki/Testing-AbilitiesRSPEc - 未定義的方法'存根'爲#<RoomsController:0x0000010534c050>

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 

我如何能得到設計+慘慘+ RSpec的工作,所以我可以測試控制器有何建議?由於

+2

'stubs'不存在,這是''存根:http://rspec.info/documentation/mocks/stubs.html – apneadiving

回答

6

這不是RSpec的語法,你想要的是:

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

這似乎已修復該錯誤。任何想法爲什麼我需要首先存根? – AnApprentice

相關問題