Class: Mutant::Integration::Rspec

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

Overview

Shared parts of rspec2/3 integration

Direct Known Subclasses

Rspec2, Rspec3

Defined Under Namespace

Classes: Rspec2, Rspec3

Constant Summary collapse

RSPEC_2_VERSION_PREFIX =
'2.'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.buildIntegration

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 integration compatible to currently loaded rspec

Returns:



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

def self.build
  if RSpec::Core::Version::STRING.start_with?(RSPEC_2_VERSION_PREFIX)
    Rspec2.new
  else
    Rspec3.new
  end
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>)


79
80
81
82
83
84
85
# File 'lib/mutant/integration/rspec.rb', line 79

def all_tests
  example_group_index.keys.each_with_object([]) do |full_description, aggregate|
    expression = Expression.try_parse(full_description) or next

    aggregate << Test.new(self, expression)
  end
end

#run(test) ⇒ Test::Result

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:

  • test (Rspec::Test)

Returns:

  • (Test::Result)


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/mutant/integration/rspec.rb', line 51

def run(test)
  output = StringIO.new
  failed = false
  start = Time.now
  reporter = new_reporter(output)
  reporter.report(1) do
    example_group_index.fetch(test.expression.syntax).each do |example_group|
      next if example_group.run(reporter)
      failed = true
      break
    end
  end
  output.rewind
  Result::Test.new(
    test:     nil,
    mutation: nil,
    output:   output.read,
    runtime:  Time.now - start,
    passed:   !failed
  )
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
38
# File 'lib/mutant/integration/rspec.rb', line 34

def setup
  options.configure(configuration)
  configuration.load_spec_files
  self
end