Skip to content

Commit

Permalink
Change Mutant::Test to allow multiple expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
mbj committed Oct 29, 2020
1 parent 2670c26 commit b45adad
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 22 deletions.
4 changes: 2 additions & 2 deletions lib/mutant/integration/minitest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ def all_tests_index

def construct_test(test_case)
Test.new(
id: test_case.identification,
expression: config.expression_parser.apply(test_case.expression_syntax).from_right
id: test_case.identification,
expressions: [config.expression_parser.apply(test_case.expression_syntax).from_right]
)
end

Expand Down
4 changes: 2 additions & 2 deletions lib/mutant/integration/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ def parse_example(example, index)
}

Test.new(
expression: parse_metadata(metadata),
id: id
expressions: [parse_metadata(metadata)],
id: id
)
end

Expand Down
4 changes: 3 additions & 1 deletion lib/mutant/selector/expression.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ class Expression < self
def call(subject)
subject.match_expressions.each do |match_expression|
subject_tests = integration.all_tests.select do |test|
match_expression.prefix?(test.expression)
test.expressions.any? do |test_expression|
match_expression.prefix?(test_expression)
end
end
return subject_tests if subject_tests.any?
end
Expand Down
2 changes: 1 addition & 1 deletion lib/mutant/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Mutant
# Abstract base class for test that might kill a mutation
class Test
include Adamantium::Flat, Anima.new(
:expression,
:expressions,
:id
)

Expand Down
16 changes: 8 additions & 8 deletions spec/unit/mutant/integration/rspec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,20 @@
let(:all_tests) do
[
Mutant::Test.new(
id: 'rspec:0:example-a-location/example-a-full-description',
expression: parse_expression('*')
id: 'rspec:0:example-a-location/example-a-full-description',
expressions: [parse_expression('*')]
),
Mutant::Test.new(
id: 'rspec:1:example-c-location/Example::C blah',
expression: parse_expression('Example::C')
id: 'rspec:1:example-c-location/Example::C blah',
expressions: [parse_expression('Example::C')]
),
Mutant::Test.new(
id: "rspec:2:example-d-location/Example::D\nblah",
expression: parse_expression('*')
id: "rspec:2:example-d-location/Example::D\nblah",
expressions: [parse_expression('*')]
),
Mutant::Test.new(
id: 'rspec:3:example-e-location/Example::E',
expression: parse_expression('Foo')
id: 'rspec:3:example-e-location/Example::E',
expressions: [parse_expression('Foo')]
)
]
end
Expand Down
36 changes: 28 additions & 8 deletions spec/unit/mutant/selector/expression_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,34 @@
describe '#call' do
let(:object) { described_class.new(integration) }

let(:mutation_subject) { subject_class.new(context: context, node: node, warnings: warnings) }
let(:context) { instance_double(Mutant::Context) }
let(:node) { instance_double(Parser::AST::Node) }
let(:integration) { instance_double(Mutant::Integration, all_tests: all_tests) }
let(:test_a) { instance_double(Mutant::Test, expression: parse_expression('SubjectA')) }
let(:test_b) { instance_double(Mutant::Test, expression: parse_expression('SubjectB')) }
let(:test_c) { instance_double(Mutant::Test, expression: parse_expression('SubjectC')) }
let(:warnings) { instance_double(Mutant::Warnings) }
let(:context) { instance_double(Mutant::Context) }
let(:node) { instance_double(Parser::AST::Node) }
let(:test_a) { mk_test('SubjectA') }
let(:test_b) { mk_test('SubjectB') }
let(:test_c) { mk_test('SubjectC') }
let(:warnings) { instance_double(Mutant::Warnings) }

let(:integration) do
instance_double(
Mutant::Integration,
all_tests: all_tests
)
end

let(:mutation_subject) do
subject_class.new(
context: context,
node: node,
warnings: warnings
)
end

def mk_test(expression)
instance_double(
Mutant::Test,
expressions: [parse_expression(expression)]
)
end

let(:subject_class) do
parse = method(:parse_expression)
Expand Down

0 comments on commit b45adad

Please sign in to comment.