私はこの例を持っています:
# GET New
context "on get to new" do
it "should assign cardset" do
@profile.cardsets.expects(:build).once.returns(Factory.stub(:cardset))
get :new
assigns[:cardset].should_not be_nil
end
end
このメソッドをテストするには:
# GET /cardsets/new
def new
@cardset = current_user.cardsets.build
end
私はcurrent_user
、ユーザーが自分自身に属するものだけを作成していることを確認するために、関連付けが構築されていることを強制しようとしています。私は、オブジェクトfind
から呼び出していることを確認するために非常によく似た期待値を使用しており、それが検索で機能しますが、上記の例を実行すると、次のようになります。current_user
6)
Mocha::ExpectationError in 'CardsetsController for a logged in user on get to new should assign cardset'
not all expectations were satisfied
unsatisfied expectations:
- expected exactly once, not yet invoked: [#<Cardset:0x102eaa8c8>, #<Cardset:0x102e12438>].build(any_parameters)
satisfied expectations:
- allowed any number of times, not yet invoked: ApplicationController.require_user(any_parameters)
- allowed any number of times, already invoked twice: #<CardsetsController:0x1030849c8>.current_user(any_parameters)
/Applications/MAMP/htdocs/my_app/spec/controllers/cardsets_controller_spec.rb:32: