2012-02-24 35 views
0

以下の仕様が失敗する理由は不明です。 an_instance_ofをanything()マッチャーに変更すると、specが渡されます。正しく使用していないのですか?RSpecのan_instance_of matcherの使用方法

controller.should_receive(:authorize!).with(:show, an_instance_of(Network)) 
get :new 


Failure/Error: get :new 
     #<AffiliationsController:0x007ff5c607f238> received :authorize! with unexpected arguments 
     expected: (:show, #<RSpec::Mocks::ArgumentMatchers::InstanceOf:0x007ff5c6081600 @klass=Network(id: integer, creator_id: integer, name: string, zipcode: string, created_at: datetime, updated_at: datetime, allows_invitations: boolean, network_type_id: integer, active: boolean, fee: decimal, invitation_standard_text: text, description: text)>) 
       got: (:show, Network(id: integer, creator_id: integer, name: string, zipcode: string, created_at: datetime, updated_at: datetime, allows_invitations: boolean, network_type_id: integer, active: boolean, fee: decimal, invitation_standard_text: text, description: text)) 

コントローラがCanCanのload_and_authorize_resourceメソッドを呼び出していることをテストしようとしています。私は理想的には発見に期待を持ちますが、それを働かせることはできませんでした。次のようなものがあります。

network = stub 
Network.should_receive(:new).and_return(stub) 
controller.should_receive(:authorize!).with(:show, network) 

答えて

1

実際のネットワーククラスでメッセージを受信して​​いるようですが、そのインスタンスではありません。

+0

長い日...ありがとう。 –

+0

このテストにどのような変更が加えられたのか詳しく説明できますか?この自分自身に実行します。 http://stackoverflow.com/questions/13765512/an-instance-of-mailmessage-not-returning-true – Steve

関連する問題