2011-08-26 59 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

相关问题