Class: Mutant::Integration::Rspec

Inherits:
Mutant::Integration show all
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.

Constant Summary collapse

ALL_EXPRESSION =
Expression::Namespace::Recursive.new(scope_name: nil)
EXPRESSION_CANDIDATE =
/\A([^ ]+)(?: )?/.freeze
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

Constructor Details

#initializeundefined

Initialize rspec integration



35
36
37
38
39
# File 'lib/mutant/integration/rspec.rb', line 35

def initialize(*)
  super
  @runner      = RSpec::Core::Runner.new(RSpec::Core::ConfigurationOptions.new(effective_arguments))
  @rspec_world = RSpec.world
end

Instance Method Details

#all_testsEnumerable<Test>

All tests

Returns:

  • (Enumerable<Test>)


70
71
72
# File 'lib/mutant/integration/rspec.rb', line 70

def all_tests
  all_tests_index.keys
end

#available_testsEnumerable<Test>

Available tests

Returns:

  • (Enumerable<Test>)


78
79
80
# File 'lib/mutant/integration/rspec.rb', line 78

def available_tests
  all_tests_index.select { |_test, example| example..fetch(:mutant, true) }.keys
end

#call(tests) ⇒ Result::Test

Run a collection of tests

Parameters:

  • tests (Enumerable<Mutant::Test>)

Returns:

  • (Result::Test)


57
58
59
60
61
62
63
64
65
# File 'lib/mutant/integration/rspec.rb', line 57

def call(tests)
  setup_examples(tests.map(&all_tests_index))
  start = timer.now
  passed = @runner.run_specs(@rspec_world.ordered_example_groups).equal?(EXIT_SUCCESS)
  Result::Test.new(
    passed:  passed,
    runtime: timer.now - start
  )
end

#setupself

Setup rspec integration

Returns:

  • (self)


44
45
46
47
48
49
# File 'lib/mutant/integration/rspec.rb', line 44

def setup
  @runner.setup($stderr, $stdout)
  example_group_map
  reset_examples
  self
end