mutant-rspec 0.6.7 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/mutant/integration/rspec.rb +59 -135
  3. metadata +6 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5fbec65e9fbbda710a2839b1236605eb36aed9ae
4
- data.tar.gz: 90f3a08920d3733cff3518eb3c2ddc078ede29f4
3
+ metadata.gz: 46ada3b79ab252f059d8065f00d72003c6f66fa1
4
+ data.tar.gz: e8988daaeb561bf5e7456e4cc5ffeb52f93ff32c
5
5
  SHA512:
6
- metadata.gz: e0bccffc513e8bf9b439df0d341f18151731683f94103e9efe7dcea041d4057213bdca4e21509f3965dd2206395c05bde28417787b6c374f798c5fc470008bb9
7
- data.tar.gz: 1703e6caf48c5ec175082197df07587213005d9d3de01030581563eef6c81c240fc1027d63edf0eadc02abec50578e9de372415f968336dacef740d4ac98ad86
6
+ metadata.gz: 90dc03c3a632b7ca89eeb5235f1403fd01c97583aebe49736b343e72e42f4904981d5c74a05f6a14628b0902a90e3bca8444c4a161116b144b04dd0467749550
7
+ data.tar.gz: 7ba8812781d7209630b66acd13a7fbe99841d6cd13ac8813e9e68bd94c18a04609071ade1eb40a9668856273582d6c4286fc3cc5fd4778c27aed246ede3e06ca
@@ -1,28 +1,28 @@
1
1
  require 'rspec/core'
2
- require 'rspec/core/formatters/base_text_formatter'
3
2
 
4
3
  module Mutant
5
4
  class Integration
6
5
  # Shared parts of rspec2/3 integration
7
6
  class Rspec < self
8
- include AbstractType
9
7
 
10
- register 'rspec'
8
+ ALL = Mutant::Expression.parse('*')
9
+ EXPRESSION_DELIMITER = ' '.freeze
10
+ LOCATION_DELIMITER = ':'.freeze
11
+ EXIT_SUCCESS = 0
12
+ CLI_OPTIONS = IceNine.deep_freeze(%w[spec --fail-fast])
11
13
 
12
- RSPEC_2_VERSION_PREFIX = '2.'.freeze
14
+ register 'rspec'
13
15
 
14
- # Return integration compatible to currently loaded rspec
16
+ # Initialize rspec integration
15
17
  #
16
- # @return [Integration]
18
+ # @return [undefined]
17
19
  #
18
20
  # @api private
19
21
  #
20
- def self.build
21
- if RSpec::Core::Version::STRING.start_with?(RSPEC_2_VERSION_PREFIX)
22
- Rspec2.new
23
- else
24
- Rspec3.new
25
- end
22
+ def initialize
23
+ @output = StringIO.new
24
+ @runner = RSpec::Core::Runner.new(RSpec::Core::ConfigurationOptions.new(CLI_OPTIONS))
25
+ @world = RSpec.world
26
26
  end
27
27
 
28
28
  # Setup rspec integration
@@ -32,15 +32,14 @@ module Mutant
32
32
  # @api private
33
33
  #
34
34
  def setup
35
- options.configure(configuration)
36
- configuration.load_spec_files
35
+ @runner.setup($stderr, @output)
37
36
  self
38
37
  end
39
38
  memoize :setup
40
39
 
41
40
  # Return report for test
42
41
  #
43
- # @param [Rspec::Test] test
42
+ # @param [Enumerable<Mutant::Test>] tests
44
43
  #
45
44
  # @return [Test::Result]
46
45
  #
@@ -48,25 +47,17 @@ module Mutant
48
47
  #
49
48
  # rubocop:disable MethodLength
50
49
  #
51
- def run(test)
52
- output = StringIO.new
53
- failed = false
50
+ def call(tests)
51
+ examples = tests.map(&all_tests_index.method(:fetch)).to_set
52
+ filter_examples(&examples.method(:include?))
54
53
  start = Time.now
55
- reporter = new_reporter(output)
56
- reporter.report(1) do
57
- example_group_index.fetch(test.expression.syntax).each do |example_group|
58
- next if example_group.run(reporter)
59
- failed = true
60
- break
61
- end
62
- end
63
- output.rewind
54
+ passed = @runner.run_specs(RSpec.world.ordered_example_groups).equal?(EXIT_SUCCESS)
55
+ @output.rewind
64
56
  Result::Test.new(
65
- test: nil,
66
- mutation: nil,
67
- output: output.read,
57
+ tests: nil,
58
+ output: @output.read,
68
59
  runtime: Time.now - start,
69
- passed: !failed
60
+ passed: passed
70
61
  )
71
62
  end
72
63
 
@@ -77,136 +68,69 @@ module Mutant
77
68
  # @api private
78
69
  #
79
70
  def all_tests
80
- example_group_index.keys.each_with_object([]) do |full_description, aggregate|
81
- expression = Expression.try_parse(full_description) or next
82
-
83
- aggregate << Test.new(self, expression)
84
- end
71
+ all_tests_index.keys
85
72
  end
86
73
  memoize :all_tests
87
74
 
88
75
  private
89
76
 
90
- # Return all example groups
77
+ # Return all tests index
91
78
  #
92
- # @return [Hash<String, RSpec::Core::ExampleGroup]
79
+ # @return [Hash<Test, RSpec::Core::Example]
93
80
  #
94
81
  # @api private
95
82
  #
96
- def example_group_index
97
- index = Hash.new { |hash, key| hash[key] = [] }
98
-
99
- RSpec.world.example_groups.flat_map(&:descendants).each do |example_group|
100
- full_description = full_description(example_group)
101
- index[full_description] << example_group
83
+ def all_tests_index
84
+ all_examples.each_with_object({}) do |example, index|
85
+ index[parse_example(example)] = example
102
86
  end
103
-
104
- index
105
87
  end
106
- memoize :example_group_index
88
+ memoize :all_tests_index
107
89
 
108
- # Return configuration
90
+ # Parse example into test
91
+ #
92
+ # @param [RSpec::Core::Example]
109
93
  #
110
- # @return [RSpec::Core::Configuration]
94
+ # @return [Test]
111
95
  #
112
96
  # @api private
113
97
  #
114
- def configuration
115
- RSpec::Core::Configuration.new
98
+ def parse_example(example)
99
+ metadata = example.metadata
100
+ location = metadata.fetch(:location)
101
+ full_description = metadata.fetch(:full_description)
102
+ expression = Expression.try_parse(full_description.split(EXPRESSION_DELIMITER, 2).first) || ALL
103
+
104
+ Test.new(
105
+ id: "rspec:#{location} / #{full_description}",
106
+ expression: expression
107
+ )
116
108
  end
117
- memoize :configuration, freezer: :noop
118
109
 
119
- # Return options
110
+ # Return all examples
120
111
  #
121
- # @return [RSpec::Core::ConfigurationOptions]
112
+ # @return [Array<String, RSpec::Core::Example]
122
113
  #
123
114
  # @api private
124
115
  #
125
- def options
126
- RSpec::Core::ConfigurationOptions.new(%w[--fail-fast spec])
116
+ def all_examples
117
+ @world.example_groups.flat_map(&:descendants).flat_map(&:examples)
127
118
  end
128
- memoize :options, freezer: :noop
129
-
130
- # Rspec2 integration
131
- class Rspec2 < self
132
-
133
- register 'rspec'
134
119
 
135
- private
136
-
137
- # Return options
138
- #
139
- # @return [RSpec::Core::ConfigurationOptions]
140
- #
141
- # @api private
142
- #
143
- def options
144
- super.tap(&:parse_options)
145
- end
146
-
147
- # Return full description of example group
148
- #
149
- # @param [RSpec::Core::ExampleGroup] example_group
150
- #
151
- # @return [String]
152
- #
153
- # @api private
154
- #
155
- def full_description(example_group)
156
- example_group.metadata.fetch(:example_group).fetch(:full_description)
157
- end
158
-
159
- # Return new reporter
160
- #
161
- # @param [StringIO] output
162
- #
163
- # @return [RSpec::Core::Reporter]
164
- #
165
- # @api private
166
- #
167
- def new_reporter(output)
168
- formatter = RSpec::Core::Formatters::BaseTextFormatter.new(output)
169
-
170
- RSpec::Core::Reporter.new(formatter)
171
- end
172
-
173
- end # Rspec2
174
-
175
- # Rspec 3 integration
176
- class Rspec3 < self
177
-
178
- private
179
-
180
- # Return full description for example group
181
- #
182
- # @param [RSpec::Core::ExampleGroup] example_group
183
- #
184
- # @return [String]
185
- #
186
- # @api private
187
- #
188
- def full_description(example_group)
189
- example_group.metadata.fetch(:full_description)
190
- end
191
-
192
- # Return new reporter
193
- #
194
- # @param [StringIO] output
195
- #
196
- # @return [RSpec::Core::Reporter]
197
- #
198
- # @api private
199
- #
200
- def new_reporter(output)
201
- formatter = RSpec::Core::Formatters::BaseTextFormatter.new(output)
202
- notifications = RSpec::Core::Formatters::Loader.allocate.send(:notifications_for, formatter.class)
203
-
204
- RSpec::Core::Reporter.new(configuration).tap do |reporter|
205
- reporter.register_listener(formatter, *notifications)
206
- end
120
+ # Filter examples
121
+ #
122
+ # @param [#call] predicate
123
+ #
124
+ # @return [undefined]
125
+ #
126
+ # @api private
127
+ #
128
+ def filter_examples(&predicate)
129
+ @world.filtered_examples.each_value do |examples|
130
+ examples.keep_if(&predicate)
207
131
  end
132
+ end
208
133
 
209
- end # Rspec3
210
134
  end # Rspec
211
135
  end # Integration
212
136
  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.6.7
4
+ version: 0.7.1
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-11-17 00:00:00.000000000 Z
11
+ date: 2014-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mutant
@@ -16,21 +16,21 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.6.7
19
+ version: 0.7.1
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.6.7
26
+ version: 0.7.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec-core
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 2.14.1
33
+ version: 3.0.0
34
34
  - - "<"
35
35
  - !ruby/object:Gem::Version
36
36
  version: 3.2.0
@@ -40,7 +40,7 @@ dependencies:
40
40
  requirements:
41
41
  - - ">="
42
42
  - !ruby/object:Gem::Version
43
- version: 2.14.1
43
+ version: 3.0.0
44
44
  - - "<"
45
45
  - !ruby/object:Gem::Version
46
46
  version: 3.2.0
@@ -101,4 +101,3 @@ signing_key:
101
101
  specification_version: 4
102
102
  summary: Rspec integration for mutant
103
103
  test_files: []
104
- has_rdoc: