堆栈:Rails 3.0.7、Mongoid 2.2.5、RSpec 2.11.0、RR 1.0.4
我有一个看起来像这样的订阅模型:
class Subscription
include Mongoid::Document
embeds_many :addons
after_save :update_feature_policy!
def update_feature_policy!
puts "Updating feature policy!"
end
end
我有一个看起来像这样的规范:
it "should update FeaturePolicy when adding an addon" do
puts "Starting spec"
mock(subscription).update_feature_policy! { true }
subscription.addons << user_addon
puts "Finished spec"
end
规范失败,但我在控制台中看到了这个输出:
Starting spec
Updating feature policy!
Finished spec
Failure/Error: mock(subscription).update_feature_policy! { true }
RR::Errors::TimesCalledError:
update_feature_policy!()
Called 0 times.
Expected 1 times.
是什么导致模拟对象不捕获方法调用并通过规范?