如何从“应该”转换为“期望”约定?

时间:2013-07-26 18:26:55

标签: ruby rspec cancan

我刚刚开始使用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

1 个答案:

答案 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子句。另外,在这个测试中看起来有一些无关的代码。