Class: Mutant::Integration::Rspec

Inherits:
Mutant::Integration show all
Defined in:
lib/mutant/integration/rspec.rb

Overview

Shared parts of rspec2/3 integration

Constant Summary collapse

ALL =
Mutant::Expression.parse('*')
EXPRESSION_DELIMITER =
' '.freeze
LOCATION_DELIMITER =
':'.freeze
EXIT_SUCCESS =
0
CLI_OPTIONS =
IceNine.deep_freeze(%w[spec --fail-fast])

Constants inherited from Mutant::Integration

REGISTRY

Instance Method Summary collapse

Methods inherited from Mutant::Integration

lookup

Constructor Details

#initializeundefined

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


22
23
24
25
26
# File 'lib/mutant/integration/rspec.rb', line 22

def initialize
  @output = StringIO.new
  @runner = RSpec::Core::Runner.new(RSpec::Core::ConfigurationOptions.new(CLI_OPTIONS))
  @world  = RSpec.world
end

Instance Method Details

#all_testsEnumerable<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

Returns:

  • (Enumerable<Test>)

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

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

Parameters:

Returns:


50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/mutant/integration/rspec.rb', line 50

def call(tests)
  examples = tests.map(&all_tests_index.method(:fetch)).to_set
  filter_examples(&examples.method(:include?))
  start = Time.now
  passed = @runner.run_specs(RSpec.world.ordered_example_groups).equal?(EXIT_SUCCESS)
  @output.rewind
  Result::Test.new(
    tests:    tests,
    output:   @output.read,
    runtime:  Time.now - start,
    passed:   passed
  )
end

#setupself

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

Returns:

  • (self)

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

def setup
  @runner.setup($stderr, @output)
  self
end