2012-02-24 54 views
0

目前還不清楚爲什麼下面的規範失敗。如果我將an_instance_of更改爲任何()匹配器,規範就會通過。我沒有正確使用它嗎?如何使用RSpec的an_instance_of匹配器

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

漫長的一天......謝謝。 – 2012-02-24 04:54:43

+0

你能詳細說明通過了什麼樣的改變嗎?自己碰到這個。 http://stackoverflow.com/questions/13765512/an-instance-of-mailmessage-not-returning-true – Steve 2012-12-08 14:44:07