【发布时间】:2014-02-11 17:27:39
【问题描述】:
我有以下代码:
class Init
def initialize(global_options, options, args)
abort "Key file must be given!" if (key_file = args.first).nil?
begin
@secret = File.read(key_file)
rescue
abort "Cannot read key file #{key_file}"
end
stdout, stderr, status = Open3.capture3("git status -uno --porcelain")
#...
以及以下规格:
describe Rgc::Init do
context :initialize do
it 'should abort when no key file given' do
Rgc::Init.any_instance.should_receive(:abort)
.with("Key file must be given!")
Rgc::Init.new({}, {}, [])
end
end
end
我得到以下输出:
Failure/Error: Rgc::Init.new({}, {}, [])
#<Rgc::Init:0x0000000157f728> received :abort with unexpected arguments
expected: ("Key file must be given!")
got: ("Cannot read key file ")
should_receive 方法以某种方式阻止 abort 占位。如何修复规范以检查应用程序是否已中止并带有特定消息?
【问题讨论】: