假设我有这样的方法的类:从造成的RSpec测试故障防止错误
class MyClass
...
def self.some_class_method
my_instance = MyClass.new
self.other_class_method(my_instance)
raise 'ERROR'
end
def self.other_class_method(instance)
...
end
end
而且测试它看起来像这样:
require 'spec_helper'
describe MyClass do
describe '.some_class_method' do
context 'testing some_class_method' do
it 'calls other_class_method' do
MyClass.should_receive(:other_class_method)
MyClass.some_class_method
end
end
end
end
测试错误出与ERROR
,如果我删除raise 'ERROR'
行,测试通过。但在这里,我只想测试some_class_method
是否调用other_class_method
,而不管之后会发生什么。我可以改变它以期望该方法提出错误,但这不是此特定测试的目的。有没有更好的办法?
谢谢,这个作品! – blacktrance