我刚刚开始使用rspec,我使用expect
代替should
约定。
如何将此测试示例从CanCan从should
转换为expect
?:
require "cancan/matchers"
# ...
describe "User" do
describe "abilities" do
subject { ability }
let(:ability){ Ability.new(user) }
let(:user){ nil }
context "when is an account manager" do
let(:user){ Factory(:accounts_manager) }
it{ should be_able_to(:manage, Account.new) }
end
end
end
答案 0 :(得分:2)
您实际上不必每Using implicit `subject` with `expect` in RSpec-2.11替换should
的此实例,但如果您愿意,则必须放弃单线方法并使用:
it "should be able to manage a new account" do
expect(ability).to be_able_to(:manage, Account.new)
end
代替当前的it
子句。另外,在这个测试中看起来有一些无关的代码。