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` data structure
-
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.
-
rubocop:disable Metrics/ClassLength
Constant Summary collapse
- ALL_EXPRESSION =
Expression::Namespace::Recursive.new(scope_name: nil)
- EXPRESSION_CANDIDATE =
/\A([^ ]+)(?: )?/
- EXIT_SUCCESS =
0
- DEFAULT_CLI_OPTIONS =
%w[--fail-fast spec].freeze
- TEST_ID_FORMAT =
'rspec:%<index>d:%<location>s/%<description>s'
Instance Method Summary collapse
-
#all_tests ⇒ Enumerable<Test>
All tests.
-
#available_tests ⇒ Enumerable<Test>
Available tests.
-
#call(tests) ⇒ Result::Test
Run a collection of tests.
- #freeze ⇒ Object
-
#initialize ⇒ undefined
constructor
Initialize rspec integration.
-
#setup ⇒ self
Setup rspec integration.
Constructor Details
#initialize ⇒ undefined
Initialize rspec integration
41 42 43 44 45 |
# File 'lib/mutant/integration/rspec.rb', line 41 def initialize(*) super @runner = RSpec::Core::Runner.new(RSpec::Core::ConfigurationOptions.new(effective_arguments)) @rspec_world = RSpec.world end |
Instance Method Details
#all_tests ⇒ Enumerable<Test>
All tests
92 93 94 |
# File 'lib/mutant/integration/rspec.rb', line 92 def all_tests all_tests_index.keys end |
#available_tests ⇒ Enumerable<Test>
Available tests
100 101 102 |
# File 'lib/mutant/integration/rspec.rb', line 100 def available_tests all_tests_index.select { |_test, example| example..fetch(:mutant, true) }.keys end |
#call(tests) ⇒ Result::Test
Run a collection of tests
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/mutant/integration/rspec.rb', line 71 def call(tests) reset_examples setup_examples(tests.map(&all_tests_index)) @runner.configuration.start_time = world.time.now - @setup_elapsed start = timer.now passed = @runner.run_specs(@rspec_world.ordered_example_groups).equal?(EXIT_SUCCESS) @runner.configuration.reset_reporter Result::Test.new( job_index: nil, output: '', passed:, runtime: timer.now - start ) end |
#freeze ⇒ Object
33 34 35 36 |
# File 'lib/mutant/integration/rspec.rb', line 33 def freeze super if @setup_elapsed self end |
#setup ⇒ self
Setup rspec integration
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/mutant/integration/rspec.rb', line 50 def setup @setup_elapsed = timer.elapsed do @runner.setup(world.stderr, world.stdout) fail 'RSpec setup failure' if rspec_setup_failure? example_group_map end @runner.configuration.force(color_mode: :on) @runner.configuration.reporter reset_examples freeze end |