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 identifying examples by:
-
full description
-
location
Is NOT enough. It would not be unique. So we add an “example index” for unique reference.
-
Constant Summary collapse
- ALL_EXPRESSION =
Expression::Namespace::Recursive.new(scope_name: nil)
- 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
Available tests.
-
#call(tests) ⇒ Result::Test
private
Run a collection of tests.
-
#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
37 38 39 40 41 42 |
# File 'lib/mutant/integration/rspec.rb', line 37 def initialize(*) super @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.
Available tests
83 84 85 |
# File 'lib/mutant/integration/rspec.rb', line 83 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.
Run a collection of tests
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
49 50 51 52 |
# File 'lib/mutant/integration/rspec.rb', line 49 def setup @runner.setup($stderr, @output) self end |