RSPEc - 未定义的方法“存根”;对于#
我正在尝试为我的 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
关于如何让 devise + CanCan + RSpec 工作以便测试控制器有什么建议吗?谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这不是 RSpec 语法,你想要的是:
That's not RSpec syntax, what you want is:
较新版本 3.8
allow
语法。根据 Relish 3.8 文档。
Newer Version 3.8
allow
Syntax.As per the Relish 3.8 docs.