2013-07-26 73 views
1

我剛剛開始使用rspec,我使用expect而不是should約定。如何將「should」轉換爲「expect」約定?

我怎樣才能改變從康康舞從shouldexpect這個測試呢?例如:

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 

回答

2

你其實並不需要更換的should這種情況下,每Using implicit `subject` with `expect` in RSpec-2.11,但如果你願意,你」 d必須放棄單線程方法並使用:

it "should be able to manage a new account" do 
    expect(ability).to be_able_to(:manage, Account.new) 
end 

代替當前的it子句。順便說一句,在這個測試中看起來會有一些無關的代碼。

相關問題