RSpec でオブジェクトをテストしようとしています。前後に確認したいことが複数あるので、Webで見つけた例に従って、次のようになりました。
describe Processor do
before(:each) do
# create some data in temp to run the test against
end
after(:each) do
# wipe out the data we put in temp
end
let(:processor) { Processor.new }
describe '#process' do
subject { lambda { processor.process } }
# it should actually perform the processing
it { should change { count('...') }.from(0).to(1) }
it { should change { count('...') }.from(0).to(2) }
# it should leave some other things unaffected
it { should_not change { count('...') } }
end
end
これは機能しますが、私が見ているのは、before()
コードとコードの両方#process
が遅く、RSpec によってそれぞれ 3 回実行されていることです。
通常、遅いものがあると「モックアップしてください」と言われますが、今回はテストしようとしているものそのものが遅いので、それは無意味です。
すべてのチェックが前後に変化するこの状況で、テストの対象への複数の呼び出しを回避するにはどうすればよいですか?