2014-08-10 17:04:05 -04:00
|
|
|
RSpec.describe Mutant::Runner do
|
2014-12-08 19:10:31 -05:00
|
|
|
# setup_shared_context
|
|
|
|
class FakeEnv
|
2014-12-22 11:21:51 -05:00
|
|
|
def self.kill
|
2014-12-08 19:10:31 -05:00
|
|
|
end
|
2014-07-05 22:11:31 -04:00
|
|
|
|
2014-12-08 19:10:31 -05:00
|
|
|
def self.mutations
|
|
|
|
[]
|
|
|
|
end
|
2014-07-05 22:11:31 -04:00
|
|
|
end
|
|
|
|
|
2014-10-23 07:37:53 -04:00
|
|
|
describe '.call' do
|
2014-12-08 19:10:31 -05:00
|
|
|
let(:integration) { double('Integration') }
|
|
|
|
let(:reporter) { double('Reporter', delay: delay) }
|
|
|
|
let(:driver) { double('Driver') }
|
|
|
|
let(:delay) { double('Delay') }
|
|
|
|
let(:env) { FakeEnv }
|
|
|
|
let(:env_result) { double('Env Result') }
|
|
|
|
let(:actor_env) { double('Actor ENV') }
|
|
|
|
|
|
|
|
let(:config) do
|
|
|
|
double(
|
|
|
|
'Config',
|
|
|
|
integration: integration,
|
|
|
|
reporter: reporter,
|
|
|
|
actor_env: actor_env,
|
|
|
|
jobs: 1
|
|
|
|
)
|
|
|
|
end
|
2014-07-05 22:11:31 -04:00
|
|
|
|
2014-12-08 19:10:31 -05:00
|
|
|
before do
|
|
|
|
allow(FakeEnv).to receive(:config).and_return(config)
|
2014-12-22 13:04:41 -05:00
|
|
|
allow(FakeEnv).to receive(:actor_env).and_return(actor_env)
|
2014-12-08 19:10:31 -05:00
|
|
|
end
|
2014-07-05 22:11:31 -04:00
|
|
|
|
2014-12-08 19:10:31 -05:00
|
|
|
let(:parallel_config) do
|
|
|
|
Mutant::Parallel::Config.new(
|
|
|
|
jobs: 1,
|
|
|
|
env: actor_env,
|
|
|
|
source: Mutant::Parallel::Source::Array.new(env.mutations),
|
2014-12-22 11:27:10 -05:00
|
|
|
sink: Mutant::Runner::Sink::Mutation.new(env),
|
2014-12-22 11:21:51 -05:00
|
|
|
processor: env.method(:kill)
|
2014-12-08 19:10:31 -05:00
|
|
|
)
|
|
|
|
end
|
2014-07-05 22:11:31 -04:00
|
|
|
|
2014-12-08 19:10:31 -05:00
|
|
|
before do
|
|
|
|
expect(reporter).to receive(:start).with(env).ordered
|
|
|
|
expect(integration).to receive(:setup).ordered
|
|
|
|
expect(Mutant::Parallel).to receive(:async).with(parallel_config).and_return(driver).ordered
|
|
|
|
end
|
2014-07-05 22:11:31 -04:00
|
|
|
|
2014-12-08 19:10:31 -05:00
|
|
|
subject { described_class.call(env) }
|
2014-07-05 22:11:31 -04:00
|
|
|
|
2014-12-08 19:10:31 -05:00
|
|
|
context 'when runner finishes immediately' do
|
|
|
|
let(:status) { double('Status', done: true, payload: env_result) }
|
2014-07-07 10:07:47 -04:00
|
|
|
|
2014-12-08 19:10:31 -05:00
|
|
|
before do
|
|
|
|
expect(driver).to receive(:status).and_return(status)
|
|
|
|
expect(reporter).to receive(:progress).with(status).ordered
|
|
|
|
expect(driver).to receive(:stop).ordered
|
|
|
|
expect(reporter).to receive(:report).with(env_result).ordered
|
2014-10-23 07:37:53 -04:00
|
|
|
end
|
2014-07-16 11:26:47 -04:00
|
|
|
end
|
|
|
|
|
2014-12-08 19:10:31 -05:00
|
|
|
context 'when report iterations are done' do
|
|
|
|
let(:status_a) { double('Status A', done: false) }
|
|
|
|
let(:status_b) { double('Status B', done: true, payload: env_result) }
|
2014-07-16 11:26:47 -04:00
|
|
|
|
2014-10-23 07:37:53 -04:00
|
|
|
before do
|
2014-12-08 19:10:31 -05:00
|
|
|
expect(driver).to receive(:status).and_return(status_a).ordered
|
|
|
|
expect(reporter).to receive(:progress).with(status_a).ordered
|
|
|
|
expect(Kernel).to receive(:sleep).with(reporter.delay).ordered
|
2014-12-05 23:34:04 -05:00
|
|
|
|
2014-12-08 19:10:31 -05:00
|
|
|
expect(driver).to receive(:status).and_return(status_b).ordered
|
|
|
|
expect(reporter).to receive(:progress).with(status_b).ordered
|
|
|
|
expect(driver).to receive(:stop).ordered
|
2014-12-05 23:34:04 -05:00
|
|
|
|
2014-12-08 19:10:31 -05:00
|
|
|
expect(reporter).to receive(:report).with(env_result).ordered
|
2014-07-16 11:26:47 -04:00
|
|
|
end
|
2014-07-07 10:07:47 -04:00
|
|
|
|
2014-10-23 07:37:53 -04:00
|
|
|
it 'returns env result' do
|
2014-12-08 19:10:31 -05:00
|
|
|
should be(env_result)
|
2014-10-23 07:37:53 -04:00
|
|
|
end
|
2014-07-05 22:11:31 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|