【发布时间】:2012-09-19 19:46:19
【问题描述】:
堆栈: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.
是什么导致模拟对象没有捕获方法调用并通过规范?
【问题讨论】:
-
您是否缺少设置订阅 = 模拟(订阅)的部分?
-
你能发布你的相关控制器代码吗?您没有正确分配模拟,这就是它调用的原因。
-
抱歉,我没有意识到您正在使用 RR。不知道我知道这里有什么问题。
标签: ruby-on-rails rspec mocking rr