【发布时间】:2017-11-19 18:04:32
【问题描述】:
我想检查是否使用 rspec 在我的函数中调用了该块。以下是我的代码:
class SP
def speak(options={},&block)
puts "speak called"
block.call()
rescue ZeroDivisionError => e
end
end
describe SP do
it "testing speak functionality can receive a block" do
sp = SP.new
def test_func
a = 1
end
sp_mock = double(sp)
expect(sp_mock).to receive(:speak).with(test_func)
sp.speak(test_func)
end
end
以下是我的错误:
SP testing speak functionality can receive a block
Failure/Error: block.call()
NoMethodError:
undefined method `call' for nil:NilClass
# ./test.rb:9:in `speak'
# ./test.rb:25:in `block (2 levels) in <top (required)>'
你能帮忙吗?我花了很多时间。
【问题讨论】:
标签: ruby rspec ruby-block