# Am I correctly testing that methods from Kernel have been called?

Any time I'm testing a Ruby class that calls a Kernel method such as sleep or exit, i define a singleton method on the class instance and test that it has been invoked:

it "must throttle requests" do
sleep_was_called = false

subject.define_singleton_method(:sleep) { |seconds|
sleep_was_called = true
}

subject.request query
subject.request query

sleep_was_called.must_equal true
end


I have seen far more sophisticated method stub testing in RSpec, but it there a more fancy and less verbose way to do this using MiniTest?

• This seems like more of an SO type question. – Mark Thomas Jun 14 '13 at 12:02

I know MiniTest has an expectations framework, but I'm not familiar with it. I use rspec-expectations to accomplish this, like so:

describe ClassName do
let(:subject) { described_class.new }

describe '#method' do
it 'should sleep 3 times and output hello world' do