Add support for rspec mutant expression metadata

This commit is contained in:
Markus Schirp 2015-05-16 23:02:04 +00:00
parent 2624e2eb87
commit 41101e4abe
3 changed files with 38 additions and 8 deletions

View file

@ -1,3 +1,3 @@
---
threshold: 18
total_score: 1240
total_score: 1241

View file

@ -111,19 +111,33 @@ module Mutant
# @api private
#
def parse_example(example, index)
metadata = example.metadata
location = metadata.fetch(:location)
metadata = example.metadata
location = metadata.fetch(:location)
full_description = metadata.fetch(:full_description)
match = EXPRESSION_CANDIDATE.match(full_description)
expression = Expression.try_parse(match.captures.first) || ALL
Test.new(
id: "rspec:#{index}:#{location}/#{full_description}",
expression: expression
expression: parse_expression(metadata)
)
end
# Parse metadata into expression
#
# @param [RSpec::Core::Example::Medatada] metadata
#
# @return [Expression]
#
# @api private
#
def parse_expression(metadata)
if metadata.key?(:mutant_expression)
Expression.parse(metadata.fetch(:mutant_expression))
else
match = EXPRESSION_CANDIDATE.match(metadata.fetch(:full_description))
Expression.try_parse(match.captures.first) || ALL
end
end
# Return all examples
#
# @return [Array<String, RSpec::Core::Example]

View file

@ -47,12 +47,24 @@ RSpec.describe Mutant::Integration::Rspec do
)
end
let(:example_e) do
double(
'Example E',
metadata: {
location: 'example-e-location',
full_description: 'Example::E',
mutant_expression: 'Foo'
}
)
end
let(:examples) do
[
example_a,
example_b,
example_c,
example_d
example_d,
example_e
]
end
@ -94,6 +106,10 @@ RSpec.describe Mutant::Integration::Rspec do
Mutant::Test.new(
id: "rspec:2:example-d-location/Example::D\nblah",
expression: Mutant::Expression.parse('*')
),
Mutant::Test.new(
id: 'rspec:3:example-e-location/Example::E',
expression: Mutant::Expression.parse('Foo')
)
]
end