mutant-rspec 0.5.10 → 0.5.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 01fe0d0c8dc7e516297296664e1d8a91957742ba
4
- data.tar.gz: daba84b4ae694cafd9605c8e1f0ede4f94a904ba
3
+ metadata.gz: 02b767a437346fa7084bc671ab36fb93644261ca
4
+ data.tar.gz: 26fc28015526689e392a22fbd30348564db08705
5
5
  SHA512:
6
- metadata.gz: c68cf8892bdfda3b4e5e71e66c261fec3a5e4b5ab1146897b848bc1a390622b4ee8643d5de58c054a94305e2df0617e3bd87ad701af0acc70ed8d540350fe5fe
7
- data.tar.gz: 901526bbb8485bd6828f46e3dfee967999b13ce571982cb4c693da112fd1b5fb7ed90d35a3f12b6bb26ef244ed24f593f53bc6c1364915ffb8c0dcd47e7fa9c4
6
+ metadata.gz: 95865032ed075e9b93009af0a97fbdc7bce98fb28b047d0ba0189f8344028ba735a6d1a18414fba38dd16b4598b21733cdc1ca7493634737922f388b9c1823af
7
+ data.tar.gz: b79fb3538ac89ded3d550d53efaf7d758930565812e9de403e7d6c8d1eb200dbb0be3841548a53a702dc6dfc2fcfdef778af8a9cc143c93fd91632e5b35d83eb
@@ -1,5 +1,7 @@
1
1
  # encoding: UTF-8
2
2
 
3
+ require 'rspec'
4
+
3
5
  require 'mutant/rspec'
4
- require 'mutant/rspec/killer'
5
6
  require 'mutant/rspec/strategy'
7
+ require 'mutant/rspec/test'
@@ -1,7 +1,5 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'rspec'
4
-
5
3
  module Mutant
6
4
  # Rspec integration namespace
7
5
  module Rspec
@@ -2,12 +2,13 @@
2
2
 
3
3
  module Mutant
4
4
  module Rspec
5
+
5
6
  # Rspec killer strategy
6
7
  class Strategy < Mutant::Strategy
7
8
 
8
- register 'rspec'
9
+ RSPEC_2_VERSION_PREFIX = '2.'.freeze
9
10
 
10
- KILLER = Killer::Forking.new(Rspec::Killer)
11
+ register 'rspec'
11
12
 
12
13
  # Setup rspec strategy
13
14
  #
@@ -16,25 +17,47 @@ module Mutant
16
17
  # @api private
17
18
  #
18
19
  def setup
19
- output = StringIO.new
20
- configuration.error_stream = output
21
- configuration.output_stream = output
22
20
  options.configure(configuration)
23
21
  configuration.load_spec_files
24
22
  self
25
23
  end
26
24
  memoize :setup
27
25
 
28
- # Return configuration
26
+ # Return report for test
29
27
  #
30
- # @return [RSpec::Core::Configuration]
28
+ # @param [Rspec::Test] test
31
29
  #
32
30
  # @api private
33
31
  #
34
- def configuration
35
- RSpec::Core::Configuration.new
32
+ def run(test)
33
+ output = StringIO.new
34
+ success = false
35
+ reporter = new_reporter(output)
36
+ reporter.report(1) do
37
+ success = test.example_group.run(reporter)
38
+ end
39
+ output.rewind
40
+ Test::Report.new(
41
+ test: self,
42
+ output: output.read,
43
+ success: success
44
+ )
36
45
  end
37
- memoize :configuration, freezer: :noop
46
+
47
+ # Return all available tests
48
+ #
49
+ # @return [Enumerable<Test>]
50
+ #
51
+ # @api private
52
+ #
53
+ def all_tests
54
+ example_groups.map do |example_group|
55
+ Test.new(self, example_group)
56
+ end
57
+ end
58
+ memoize :all_tests
59
+
60
+ private
38
61
 
39
62
  # Return example groups
40
63
  #
@@ -43,7 +66,32 @@ module Mutant
43
66
  # @api private
44
67
  #
45
68
  def example_groups
46
- world.example_groups
69
+ RSpec.world.example_groups
70
+ end
71
+
72
+ # Return new reporter
73
+ #
74
+ # @param [StringIO] output
75
+ #
76
+ # @return [RSpec::Core::Reporter]
77
+ #
78
+ # @api private
79
+ #
80
+ def new_reporter(output)
81
+ reporter_class = RSpec::Core::Reporter
82
+
83
+ # rspec3 does not require that one via a very indirect autoload setup
84
+ require 'rspec/core/formatters/base_text_formatter'
85
+ formatter = RSpec::Core::Formatters::BaseTextFormatter.new(output)
86
+
87
+ if rspec2?
88
+ reporter_class.new(formatter)
89
+ else
90
+ notifications = RSpec::Core::Formatters::Loader.allocate.send(:notifications_for, formatter.class)
91
+ reporter = reporter_class.new(configuration)
92
+ reporter.register_listener(formatter, *notifications)
93
+ reporter
94
+ end
47
95
  end
48
96
 
49
97
  # Detect RSpec 2
@@ -57,21 +105,19 @@ module Mutant
57
105
  # @api private
58
106
  #
59
107
  def rspec2?
60
- RSpec::Core::Version::STRING.start_with?('2.')
108
+ RSpec::Core::Version::STRING.start_with?(RSPEC_2_VERSION_PREFIX)
61
109
  end
62
110
 
63
- private
64
-
65
- # Return world
111
+ # Return configuration
66
112
  #
67
- # @return [RSpec::Core::World]
113
+ # @return [RSpec::Core::Configuration]
68
114
  #
69
115
  # @api private
70
116
  #
71
- def world
72
- RSpec.world
117
+ def configuration
118
+ RSpec::Core::Configuration.new
73
119
  end
74
- memoize :world, freezer: :noop
120
+ memoize :configuration, freezer: :noop
75
121
 
76
122
  # Return options
77
123
  #
@@ -0,0 +1,32 @@
1
+ module Mutant
2
+ module Rspec
3
+ # Rspec test abstraction
4
+ class Test < Mutant::Test
5
+ include Concord::Public.new(:strategy, :example_group)
6
+
7
+ PREFIX = :rspec
8
+
9
+ # Return subject identification
10
+ #
11
+ # @return [String]
12
+ #
13
+ # @api private
14
+ #
15
+ def subject_identification
16
+ example_group.description
17
+ end
18
+ memoize :subject_identification
19
+
20
+ # Run test, return report
21
+ #
22
+ # @return [String]
23
+ #
24
+ # @api private
25
+ #
26
+ def run
27
+ strategy.run(self)
28
+ end
29
+
30
+ end # Test
31
+ end # Rspec
32
+ end # Mutant
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mutant-rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.10
4
+ version: 0.5.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Markus Schirp
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-06 00:00:00.000000000 Z
11
+ date: 2014-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mutant
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: 0.5.10
19
+ version: 0.5.13
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: 0.5.10
26
+ version: 0.5.13
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec-core
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -75,11 +75,10 @@ extra_rdoc_files:
75
75
  files:
76
76
  - lib/mutant-rspec.rb
77
77
  - lib/mutant/rspec.rb
78
- - lib/mutant/rspec/killer.rb
79
78
  - lib/mutant/rspec/strategy.rb
79
+ - lib/mutant/rspec/test.rb
80
80
  - TODO
81
81
  - LICENSE
82
- - spec/unit/mutant/rspec/killer_spec.rb
83
82
  homepage: https://github.com/mbj/mutant
84
83
  licenses:
85
84
  - MIT
@@ -104,6 +103,5 @@ rubygems_version: 2.0.14
104
103
  signing_key:
105
104
  specification_version: 4
106
105
  summary: Rspec integration for mutant
107
- test_files:
108
- - spec/unit/mutant/rspec/killer_spec.rb
106
+ test_files: []
109
107
  has_rdoc:
@@ -1,110 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Mutant
4
- module Rspec
5
- # Runner for rspec tests
6
- class Killer < Mutant::Killer
7
-
8
- private
9
-
10
- # Run rspec test
11
- #
12
- # @return [true]
13
- # when test is NOT successful
14
- #
15
- # @return [false]
16
- # otherwise
17
- #
18
- # @api private
19
- #
20
- def run
21
- mutation.insert
22
-
23
- groups =
24
- if mutation.is_a?(Mutation::Neutral::Noop)
25
- [example_groups.first]
26
- else
27
- example_groups
28
- end
29
-
30
- unless groups
31
- $stderr.puts("No rspec example groups found for: #{match_prefixes.join(', ')}")
32
- return false
33
- end
34
-
35
- example_groups.each do |group|
36
- return true unless group.run(reporter)
37
- end
38
-
39
- false
40
- end
41
-
42
- # Return match prefixes
43
- #
44
- # @return [Enumerble<String>]
45
- #
46
- # @api private
47
- #
48
- def match_prefixes
49
- subject.match_prefixes
50
- end
51
-
52
- # Return example groups
53
- #
54
- # @return [Array<RSpec::Example>]
55
- #
56
- # @api private
57
- #
58
- def example_groups
59
- match_prefixes.each do |match_expression|
60
- example_groups = find_with(match_expression)
61
- return example_groups unless example_groups.empty?
62
- end
63
-
64
- nil
65
- end
66
-
67
- # Return example groups that match expression
68
- #
69
- # @param [String] match_expression
70
- #
71
- # @return [Enumerable<String>]
72
- #
73
- # @api private
74
- #
75
- def find_with(match_expression)
76
- all_example_groups.select do |example_group|
77
- example_group.description.start_with?(match_expression)
78
- end
79
- end
80
-
81
- # Return all example groups
82
- #
83
- # @return [Enumerable<RSpec::Example>]
84
- #
85
- # @api private
86
- #
87
- def all_example_groups
88
- strategy.example_groups
89
- end
90
-
91
- # Choose and memoize RSpec reporter
92
- #
93
- # @return [RSpec::Core::Reporter]
94
- #
95
- # @api private
96
- #
97
- def reporter
98
- reporter_class = RSpec::Core::Reporter
99
-
100
- if strategy.rspec2?
101
- reporter_class.new
102
- else
103
- reporter_class.new(strategy.configuration)
104
- end
105
- end
106
- memoize :reporter, freezer: :noop
107
-
108
- end # Killer
109
- end # Rspec
110
- end # Mutant
@@ -1,57 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
- require 'mutant-rspec'
5
-
6
- describe Mutant::Rspec::Killer, '.new' do
7
-
8
- before do
9
- pending 'dactivated'
10
- end
11
-
12
- subject { object.new(strategy, mutation) }
13
-
14
- let(:context) { double('Context') }
15
- let(:mutation_subject) { double('Mutation Subject') }
16
-
17
- let(:object) { described_class }
18
-
19
- let(:mutation) do
20
- double(
21
- 'Mutation',
22
- subject: mutation_subject,
23
- should_survive?: false
24
- )
25
- end
26
-
27
- let(:strategy) do
28
- double(
29
- 'Strategy',
30
- spec_files: ['foo'],
31
- error_stream: $stderr,
32
- output_stream: $stdout
33
- )
34
- end
35
-
36
- before do
37
- mutation.stub(:insert)
38
- mutation.stub(:reset)
39
- RSpec::Core::Runner.stub(run: exit_status)
40
- end
41
-
42
- context 'when run exits zero' do
43
- let(:exit_status) { 0 }
44
-
45
- it { expect(subject.killed?).to be(false) }
46
-
47
- it { should be_a(described_class) }
48
- end
49
-
50
- context 'when run exits nonzero' do
51
- let(:exit_status) { 1 }
52
-
53
- it { expect(subject.killed?).to be(true) }
54
-
55
- it { should be_a(described_class) }
56
- end
57
- end