free_mutant/spec/support/shared_context.rb

139 lines
4.8 KiB
Ruby
Raw Normal View History

# rubocop:disable ModuleLength
2014-10-23 07:37:53 -04:00
module SharedContext
# Prepend an anonymous module with the new `with` method
#
# Using an anonymous module eliminates warnings where `setup_shared_context`
# is used and one of the shared methods is immediately redefined.
2015-09-04 16:20:56 -04:00
def with(name, &block)
new_definition =
Module.new do
define_method(name) do
super().with(instance_eval(&block))
end
end
prepend(new_definition)
2014-10-23 07:37:53 -04:00
end
def messages(&block)
let(:message_sequence) do
FakeActor::MessageSequence.new.tap do |sequence|
2014-12-21 20:28:30 -05:00
sequence.instance_eval(&block)
2014-10-23 07:37:53 -04:00
end
end
end
2015-05-02 20:21:30 -04:00
def it_reports(expected_content)
it 'writes expected report to output' do
described_class.call(output, reportable)
output.rewind
expect(output.read).to eql(strip_indent(expected_content))
end
end
2014-10-23 07:37:53 -04:00
# rubocop:disable MethodLength
2014-12-21 20:28:30 -05:00
# rubocop:disable AbcSize
2014-10-23 07:37:53 -04:00
def setup_shared_context
let(:env) { instance_double(Mutant::Env, config: config, subjects: [subject_a], mutations: mutations) }
let(:job_a) { Mutant::Parallel::Job.new(index: 0, payload: mutation_a) }
let(:job_b) { Mutant::Parallel::Job.new(index: 1, payload: mutation_b) }
let(:job_a_result) { Mutant::Runner::JobResult.new(job: job_a, result: mutation_a_result) }
let(:job_b_result) { Mutant::Runner::JobResult.new(job: job_b, result: mutation_b_result) }
let(:test_a) { instance_double(Mutant::Test, identification: 'test-a') }
let(:test_b) { instance_double(Mutant::Test, identification: 'test-b') }
let(:output) { StringIO.new }
let(:matchable_scopes) { instance_double(Array, length: 10) }
let(:message_sequence) { FakeActor::MessageSequence.new }
let(:mutations) { [mutation_a, mutation_b] }
let(:mutation_a_node) { s(:false) }
let(:mutation_b_node) { s(:nil) }
let(:mutation_b) { Mutant::Mutation::Evil.new(subject_a, mutation_b_node) }
let(:mutation_a) { Mutant::Mutation::Evil.new(subject_a, mutation_a_node) }
let(:subject_a_node) { s(:true) }
2014-10-23 07:37:53 -04:00
2014-12-08 19:10:31 -05:00
let(:status) do
Mutant::Parallel::Status.new(
active_jobs: [].to_set,
payload: env_result,
done: true
)
end
2014-10-23 07:37:53 -04:00
let(:config) do
2015-09-04 16:20:56 -04:00
Mutant::Config::DEFAULT.with(
jobs: 1,
reporter: Mutant::Reporter::Null.new
2014-10-23 07:37:53 -04:00
)
end
let(:subject_a) do
instance_double(
Mutant::Subject,
2015-05-02 20:21:30 -04:00
node: subject_a_node,
source: Unparser.unparse(subject_a_node),
2014-10-23 07:37:53 -04:00
identification: 'subject-a'
)
end
2015-05-02 20:21:30 -04:00
before do
allow(subject_a).to receive(:mutations).and_return([mutation_a, mutation_b])
end
2014-10-23 07:37:53 -04:00
let(:env_result) do
Mutant::Result::Env.new(
env: env,
runtime: 4.0,
subject_results: [subject_a_result]
)
end
let(:mutation_a_result) do
Mutant::Result::Mutation.new(
mutation: mutation_a,
test_result: mutation_a_test_result
2014-10-23 07:37:53 -04:00
)
end
let(:mutation_b_result) do
Mutant::Result::Mutation.new(
mutation: mutation_a,
test_result: mutation_b_test_result
2014-10-23 07:37:53 -04:00
)
end
let(:mutation_a_test_result) do
2014-10-23 07:37:53 -04:00
Mutant::Result::Test.new(
tests: [test_a],
passed: false,
runtime: 1.0,
output: 'mutation a test result output'
2014-10-23 07:37:53 -04:00
)
end
let(:mutation_b_test_result) do
2014-10-23 07:37:53 -04:00
Mutant::Result::Test.new(
tests: [test_a],
passed: false,
runtime: 1.0,
output: 'mutation b test result output'
2014-10-23 07:37:53 -04:00
)
end
let(:subject_a_result) do
Mutant::Result::Subject.new(
subject: subject_a,
tests: [test_a],
2014-10-23 07:37:53 -04:00
mutation_results: [mutation_a_result, mutation_b_result]
)
end
let(:empty_subject_a_result) do
2015-09-04 16:20:56 -04:00
subject_a_result.with(mutation_results: [])
2014-10-23 07:37:53 -04:00
end
let(:partial_subject_a_result) do
2015-09-04 16:20:56 -04:00
subject_a_result.with(mutation_results: [mutation_a_result])
2014-10-23 07:37:53 -04:00
end
end
2016-04-10 17:33:47 -04:00
end # SharedContext