2014-08-10 17:04:05 -04:00
|
|
|
RSpec.describe Mutant::Runner do
|
2014-10-23 07:37:53 -04:00
|
|
|
describe '.call' do
|
2015-11-15 15:16:42 -05:00
|
|
|
let(:integration) { instance_double(Mutant::Integration) }
|
|
|
|
let(:reporter) { instance_double(Mutant::Reporter, delay: delay) }
|
|
|
|
let(:driver) { instance_double(Mutant::Parallel::Driver) }
|
|
|
|
let(:delay) { instance_double(Float) }
|
|
|
|
let(:env) { instance_double(Mutant::Env, mutations: []) }
|
|
|
|
let(:env_result) { instance_double(Mutant::Result::Env) }
|
|
|
|
let(:actor_env) { instance_double(Mutant::Actor::Env) }
|
2014-12-08 19:10:31 -05:00
|
|
|
|
|
|
|
let(:config) do
|
2015-11-15 15:16:42 -05:00
|
|
|
instance_double(
|
|
|
|
Mutant::Config,
|
2014-12-08 19:10:31 -05:00
|
|
|
integration: integration,
|
2015-11-15 15:13:48 -05:00
|
|
|
jobs: 1,
|
|
|
|
reporter: reporter
|
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
|
2015-11-15 15:16:42 -05:00
|
|
|
allow(env).to receive_messages(config: config, actor_env: actor_env)
|
|
|
|
allow(env).to receive(:method).with(:kill).and_return(parallel_config.processor)
|
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(
|
|
|
|
env: actor_env,
|
2015-11-15 15:13:48 -05:00
|
|
|
jobs: 1,
|
|
|
|
processor: ->(_object) { fail },
|
2015-11-15 17:18:18 -05:00
|
|
|
sink: Mutant::Runner::Sink.new(env),
|
2015-11-15 15:13:48 -05:00
|
|
|
source: Mutant::Parallel::Source::Array.new(env.mutations)
|
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(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
|
2015-11-15 15:16:42 -05:00
|
|
|
let(:status) { instance_double(Mutant::Parallel::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
|
2015-11-15 15:16:42 -05:00
|
|
|
let(:status_a) { instance_double(Mutant::Parallel::Status, done: false) }
|
|
|
|
let(:status_b) { instance_double(Mutant::Parallel::Status, 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
|