我正在尝试为我的Rooms控制器编写一个rspec,以测试CanCan的权限,但标题中始终出现错误。我正在执行“控制器测试”下的步骤: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
关于如何进行设计+ CanCan + RSpec的工作的任何建议,以便我可以测试控制器?谢谢
最佳答案
那不是RSpec语法,您想要的是:
@controller.stub!(:current_ability).and_return(@ability)