Class: Mutant::Integration::Rspec
- Inherits:
-
Mutant::Integration
- Object
- Mutant::Integration
- Mutant::Integration::Rspec
- Defined in:
- lib/mutant/integration/rspec.rb
Overview
Rspec integration
This looks so complicated, because rspec:
-
Keeps its state global in RSpec.world and lots of other places
-
There is no API to “just run a subset of examples”, the examples need to be selected in-place via mutating the ‘RSpec.filtered_examples` datastructure
-
Does not maintain a unique identification for an example, aside the instances of ‘RSpec::Core::Example` objects itself. For that reason identifing examples by:
-
full description
-
location
Is NOT enough. It would not be uniqe. So we add an “example index” for unique reference.
-
Constant Summary collapse
- ALL =
Mutant::Expression.parse('*')
- EXPRESSION_CANDIDATE =
/\A([^ ]+)(?: )?/.freeze
- LOCATION_DELIMITER =
':'.freeze
- EXIT_SUCCESS =
0- CLI_OPTIONS =
IceNine.deep_freeze(%w[spec --fail-fast])
Instance Method Summary collapse
-
#all_tests ⇒ Enumerable<Test>
private
Return all available tests.
-
#call(tests) ⇒ Result::Test
private
Return report for test.
-
#initialize ⇒ undefined
constructor
private
Initialize rspec integration.
-
#setup ⇒ self
private
Setup rspec integration.
Constructor Details
#initialize ⇒ undefined
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize rspec integration
36 37 38 39 40 |
# File 'lib/mutant/integration/rspec.rb', line 36 def initialize @output = StringIO.new @runner = RSpec::Core::Runner.new(RSpec::Core::ConfigurationOptions.new(CLI_OPTIONS)) @world = RSpec.world end |
Instance Method Details
#all_tests ⇒ Enumerable<Test>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return all available tests
84 85 86 |
# File 'lib/mutant/integration/rspec.rb', line 84 def all_tests all_tests_index.keys end |
#call(tests) ⇒ Result::Test
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return report for test
rubocop:disable MethodLength
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/mutant/integration/rspec.rb', line 64 def call(tests) examples = tests.map(&all_tests_index.method(:fetch)) filter_examples(&examples.method(:include?)) start = Time.now passed = @runner.run_specs(@world.ordered_example_groups).equal?(EXIT_SUCCESS) @output.rewind Result::Test.new( tests: tests, output: @output.read, runtime: Time.now - start, passed: passed ) end |
#setup ⇒ self
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Setup rspec integration
48 49 50 51 |
# File 'lib/mutant/integration/rspec.rb', line 48 def setup @runner.setup($stderr, @output) self end |