![](/img/trans.png)
[英]Rails Rspec allow_any_instance_of raises “does not implement” error for ActiveRecord object attributes
[英]While running the rspec it shows does not implement( allow_any_instance_of )
我的rspec線
allow_any_instance_of(School).to receive(:admission).and_return(:body)
我的lib/school.rb
模塊 School 中有我的錄取方法
def self.admission()
像這樣,但是當我運行 rspec 時,它會拋出類似的錯誤
Failure/Error: allow_any_instance_of(School).to receive(:admission),and_return(:body)
School does not implement #admission
在這個例子中, admission
是一個 class 方法(注意前面的self.
)。 這意味着允許任何實例接收該方法是沒有意義的。
你有兩個選擇:
allow(School).to receive(:admission)...
或self.
來做admission
和instance方法。這取決於您的應用程序哪種方法更有意義。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.