rspec-core 3.5.2 → 3.6.0

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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/Changelog.md +89 -2
  4. data/lib/rspec/core/bisect/server.rb +6 -1
  5. data/lib/rspec/core/configuration.rb +110 -26
  6. data/lib/rspec/core/configuration_options.rb +2 -0
  7. data/lib/rspec/core/drb.rb +2 -0
  8. data/lib/rspec/core/example.rb +14 -10
  9. data/lib/rspec/core/example_group.rb +16 -6
  10. data/lib/rspec/core/formatters/base_text_formatter.rb +3 -5
  11. data/lib/rspec/core/formatters/console_codes.rb +7 -4
  12. data/lib/rspec/core/formatters/documentation_formatter.rb +2 -1
  13. data/lib/rspec/core/formatters/exception_presenter.rb +10 -4
  14. data/lib/rspec/core/formatters/html_formatter.rb +4 -2
  15. data/lib/rspec/core/formatters/html_snippet_extractor.rb +2 -0
  16. data/lib/rspec/core/formatters/json_formatter.rb +7 -2
  17. data/lib/rspec/core/formatters/progress_formatter.rb +1 -0
  18. data/lib/rspec/core/formatters/protocol.rb +26 -25
  19. data/lib/rspec/core/formatters/snippet_extractor.rb +1 -3
  20. data/lib/rspec/core/{source → formatters}/syntax_highlighter.rb +21 -1
  21. data/lib/rspec/core/formatters.rb +15 -5
  22. data/lib/rspec/core/hooks.rb +1 -8
  23. data/lib/rspec/core/invocations.rb +22 -4
  24. data/lib/rspec/core/memoized_helpers.rb +3 -0
  25. data/lib/rspec/core/metadata.rb +1 -0
  26. data/lib/rspec/core/metadata_filter.rb +29 -17
  27. data/lib/rspec/core/notifications.rb +20 -5
  28. data/lib/rspec/core/option_parser.rb +32 -12
  29. data/lib/rspec/core/output_wrapper.rb +29 -0
  30. data/lib/rspec/core/project_initializer/.rspec +0 -1
  31. data/lib/rspec/core/project_initializer/spec/spec_helper.rb +1 -4
  32. data/lib/rspec/core/reporter.rb +33 -9
  33. data/lib/rspec/core/runner.rb +10 -3
  34. data/lib/rspec/core/set.rb +5 -0
  35. data/lib/rspec/core/shared_example_group.rb +39 -15
  36. data/lib/rspec/core/version.rb +1 -1
  37. data/lib/rspec/core/world.rb +23 -5
  38. data/lib/rspec/core.rb +2 -1
  39. data.tar.gz.sig +3 -4
  40. metadata +8 -11
  41. metadata.gz.sig +0 -0
  42. data/lib/rspec/core/source/location.rb +0 -13
  43. data/lib/rspec/core/source/node.rb +0 -93
  44. data/lib/rspec/core/source/token.rb +0 -87
  45. data/lib/rspec/core/source.rb +0 -86
@@ -39,6 +39,8 @@ module RSpec::Core
39
39
  # rubocop:disable PerceivedComplexity
40
40
  def parser(options)
41
41
  OptionParser.new do |parser|
42
+ parser.summary_width = 34
43
+
42
44
  parser.banner = "Usage: rspec [options] [files or directories]\n\n"
43
45
 
44
46
  parser.on('-I PATH', 'Specify PATH to add to $LOAD_PATH (may be used more than once).') do |dirs|
@@ -93,11 +95,6 @@ module RSpec::Core
93
95
  options[:failure_exit_code] = code
94
96
  end
95
97
 
96
- parser.on('--dry-run', 'Print the formatter output of your suite without',
97
- ' running any examples or hooks') do |_o|
98
- options[:dry_run] = true
99
- end
100
-
101
98
  parser.on('-X', '--[no-]drb', 'Run examples via DRb.') do |use_drb|
102
99
  options[:drb] = use_drb
103
100
  options[:runner] = RSpec::Core::Invocations::DRbWithFallback.new if use_drb
@@ -107,10 +104,6 @@ module RSpec::Core
107
104
  options[:drb_port] = o.to_i
108
105
  end
109
106
 
110
- parser.on('--init', 'Initialize your project with RSpec.') do |_cmd|
111
- options[:runner] = RSpec::Core::Invocations::InitializeProject.new
112
- end
113
-
114
107
  parser.separator("\n **** Output ****\n\n")
115
108
 
116
109
  parser.on('-f', '--format FORMATTER', 'Choose a formatter.',
@@ -140,8 +133,24 @@ module RSpec::Core
140
133
  options[:full_backtrace] = true
141
134
  end
142
135
 
143
- parser.on('-c', '--[no-]color', '--[no-]colour', 'Enable color in the output.') do |o|
144
- options[:color] = o
136
+ parser.on('-c', '--color', '--colour', '') do |_o|
137
+ # flag will be excluded from `--help` output because it is deprecated
138
+ options[:color] = true
139
+ options[:color_mode] = :automatic
140
+ end
141
+
142
+ parser.on('--force-color', '--force-colour', 'Force the output to be in color, even if the output is not a TTY') do |_o|
143
+ if options[:color_mode] == :off
144
+ abort "Please only use one of `--force-color` and `--no-color`"
145
+ end
146
+ options[:color_mode] = :on
147
+ end
148
+
149
+ parser.on('--no-color', '--no-colour', 'Force the output to not be in color, even if the output is a TTY') do |_o|
150
+ if options[:color_mode] == :on
151
+ abort "Please only use one of --force-color and --no-color"
152
+ end
153
+ options[:color_mode] = :off
145
154
  end
146
155
 
147
156
  parser.on('-p', '--[no-]profile [COUNT]',
@@ -163,6 +172,11 @@ module RSpec::Core
163
172
  end
164
173
  end
165
174
 
175
+ parser.on('--dry-run', 'Print the formatter output of your suite without',
176
+ ' running any examples or hooks') do |_o|
177
+ options[:dry_run] = true
178
+ end
179
+
166
180
  parser.on('-w', '--warnings', 'Enable ruby warnings') do
167
181
  $VERBOSE = true
168
182
  end
@@ -244,6 +258,10 @@ FILTERING
244
258
 
245
259
  parser.separator("\n **** Utility ****\n\n")
246
260
 
261
+ parser.on('--init', 'Initialize your project with RSpec.') do |_cmd|
262
+ options[:runner] = RSpec::Core::Invocations::InitializeProject.new
263
+ end
264
+
247
265
  parser.on('-v', '--version', 'Display the version.') do
248
266
  options[:runner] = RSpec::Core::Invocations::PrintVersion.new
249
267
  end
@@ -256,8 +274,10 @@ FILTERING
256
274
  # trigger --default-path.
257
275
  invalid_options = %w[-d --I]
258
276
 
277
+ hidden_options = invalid_options + %w[-c]
278
+
259
279
  parser.on_tail('-h', '--help', "You're looking at it.") do
260
- options[:runner] = RSpec::Core::Invocations::PrintHelp.new(parser, invalid_options)
280
+ options[:runner] = RSpec::Core::Invocations::PrintHelp.new(parser, hidden_options)
261
281
  end
262
282
 
263
283
  # This prevents usage of the invalid_options.
@@ -0,0 +1,29 @@
1
+ module RSpec
2
+ module Core
3
+ # @private
4
+ class OutputWrapper
5
+ # @private
6
+ attr_accessor :output
7
+
8
+ # @private
9
+ def initialize(output)
10
+ @output = output
11
+ end
12
+
13
+ def respond_to?(name, priv=false)
14
+ output.respond_to?(name, priv)
15
+ end
16
+
17
+ def method_missing(name, *args, &block)
18
+ output.send(name, *args, &block)
19
+ end
20
+
21
+ # Redirect calls for IO interface methods
22
+ IO.instance_methods(false).each do |method|
23
+ define_method(method) do |*args, &block|
24
+ output.send(method, *args, &block)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,2 +1 @@
1
- --color
2
1
  --require spec_helper
@@ -12,9 +12,6 @@
12
12
  # the additional setup, and require it from the spec files that actually need
13
13
  # it.
14
14
  #
15
- # The `.rspec` file also contains a few flags that are not defaults but that
16
- # users commonly want.
17
- #
18
15
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
16
  RSpec.configure do |config|
20
17
  # rspec-expectations config goes here. You can use an alternate
@@ -80,7 +77,7 @@ RSpec.configure do |config|
80
77
  # Use the documentation formatter for detailed output,
81
78
  # unless a formatter has already been configured
82
79
  # (e.g. via a command-line flag).
83
- config.default_formatter = 'doc'
80
+ config.default_formatter = "doc"
84
81
  end
85
82
 
86
83
  # Print the 10 slowest examples and example groups at the
@@ -18,19 +18,14 @@ module RSpec::Core
18
18
  @failed_examples = []
19
19
  @pending_examples = []
20
20
  @duration = @start = @load_time = nil
21
+ @non_example_exception_count = 0
22
+ @setup_default = lambda {}
23
+ @setup = false
21
24
  end
22
25
 
23
26
  # @private
24
27
  attr_reader :examples, :failed_examples, :pending_examples
25
28
 
26
- # @private
27
- def reset
28
- @examples = []
29
- @failed_examples = []
30
- @pending_examples = []
31
- @profiler = Profiler.new if defined?(@profiler)
32
- end
33
-
34
29
  # @private
35
30
  def setup_profiler
36
31
  @profiler = Profiler.new
@@ -51,6 +46,13 @@ module RSpec::Core
51
46
  true
52
47
  end
53
48
 
49
+ # @private
50
+ def prepare_default(loader, output_stream, deprecation_stream)
51
+ @setup_default = lambda do
52
+ loader.setup_default output_stream, deprecation_stream
53
+ end
54
+ end
55
+
54
56
  # @private
55
57
  def registered_listeners(notification)
56
58
  @listeners[notification].to_a
@@ -151,6 +153,19 @@ module RSpec::Core
151
153
  notify :deprecation, Notifications::DeprecationNotification.from_hash(hash)
152
154
  end
153
155
 
156
+ # @private
157
+ # Provides a way to notify of an exception that is not tied to any
158
+ # particular example (such as an exception encountered in a :suite hook).
159
+ # Exceptions will be formatted the same way they normally are.
160
+ def notify_non_example_exception(exception, context_description)
161
+ @configuration.world.non_example_failure = true
162
+ @non_example_exception_count += 1
163
+
164
+ example = Example.new(AnonymousExampleGroup, context_description, {})
165
+ presenter = Formatters::ExceptionPresenter.new(exception, example, :indentation => 0)
166
+ message presenter.fully_formatted(nil)
167
+ end
168
+
154
169
  # @private
155
170
  def finish
156
171
  close_after do
@@ -165,7 +180,8 @@ module RSpec::Core
165
180
  @profiler.example_groups)
166
181
  end
167
182
  notify :dump_summary, Notifications::SummaryNotification.new(@duration, @examples, @failed_examples,
168
- @pending_examples, @load_time)
183
+ @pending_examples, @load_time,
184
+ @non_example_exception_count)
169
185
  notify :seed, Notifications::SeedNotification.new(@configuration.seed, seed_used?)
170
186
  end
171
187
  end
@@ -185,6 +201,7 @@ module RSpec::Core
185
201
 
186
202
  # @private
187
203
  def notify(event, notification)
204
+ ensure_listeners_ready
188
205
  registered_listeners(event).each do |formatter|
189
206
  formatter.__send__(event, notification)
190
207
  end
@@ -210,6 +227,13 @@ module RSpec::Core
210
227
 
211
228
  private
212
229
 
230
+ def ensure_listeners_ready
231
+ return if @setup
232
+
233
+ @setup_default.call
234
+ @setup = true
235
+ end
236
+
213
237
  def close
214
238
  notify :close, Notifications::NullNotification
215
239
  end
@@ -108,11 +108,18 @@ module RSpec
108
108
  # or the configured failure exit code (1 by default) if specs
109
109
  # failed.
110
110
  def run_specs(example_groups)
111
- @configuration.reporter.report(@world.example_count(example_groups)) do |reporter|
111
+ examples_count = @world.example_count(example_groups)
112
+ success = @configuration.reporter.report(examples_count) do |reporter|
112
113
  @configuration.with_suite_hooks do
113
- example_groups.map { |g| g.run(reporter) }.all? ? 0 : @configuration.failure_exit_code
114
+ if examples_count == 0 && @configuration.fail_if_no_examples
115
+ return @configuration.failure_exit_code
116
+ end
117
+
118
+ example_groups.map { |g| g.run(reporter) }.all?
114
119
  end
115
- end
120
+ end && !@world.non_example_failure
121
+
122
+ success ? 0 : @configuration.failure_exit_code
116
123
  end
117
124
 
118
125
  private
@@ -44,6 +44,11 @@ module RSpec
44
44
  end
45
45
  self
46
46
  end
47
+
48
+ def clear
49
+ @values.clear
50
+ self
51
+ end
47
52
  end
48
53
  end
49
54
  end
@@ -64,11 +64,6 @@ module RSpec
64
64
  # group; any example group or example with matching metadata will
65
65
  # automatically include this shared example group.
66
66
  # @param block The block to be eval'd
67
- # @overload shared_examples(metadata, &block)
68
- # @param metadata [Array<Symbol>, Hash] metadata to attach to this
69
- # group; any example group or example with matching metadata will
70
- # automatically include this shared example group.
71
- # @param block The block to be eval'd
72
67
  #
73
68
  # Stores the block for later use. The block will be evaluated
74
69
  # in the context of an example group via `include_examples`,
@@ -153,6 +148,12 @@ module RSpec
153
148
  # @private
154
149
  class Registry
155
150
  def add(context, name, *metadata_args, &block)
151
+ unless block
152
+ RSpec.warning "Shared example group #{name} was defined without a "\
153
+ "block and will have no effect. Please define a "\
154
+ "block or remove the definition."
155
+ end
156
+
156
157
  if RSpec.configuration.shared_context_metadata_behavior == :trigger_inclusion
157
158
  return legacy_add(context, name, *metadata_args, &block)
158
159
  end
@@ -213,20 +214,43 @@ module RSpec
213
214
 
214
215
  def warn_if_key_taken(context, key, new_block)
215
216
  existing_module = shared_example_groups[context][key]
216
-
217
217
  return unless existing_module
218
218
 
219
- RSpec.warn_with <<-WARNING.gsub(/^ +\|/, ''), :call_site => nil
220
- |WARNING: Shared example group '#{key}' has been previously defined at:
221
- | #{formatted_location existing_module.definition}
222
- |...and you are now defining it at:
223
- | #{formatted_location new_block}
224
- |The new definition will overwrite the original one.
225
- WARNING
219
+ old_definition_location = formatted_location existing_module.definition
220
+ new_definition_location = formatted_location new_block
221
+ loaded_spec_files = RSpec.configuration.loaded_spec_files
222
+
223
+ if loaded_spec_files.include?(new_definition_location) && old_definition_location == new_definition_location
224
+ RSpec.warn_with <<-WARNING.gsub(/^ +\|/, ''), :call_site => nil
225
+ |WARNING: Your shared example group, '#{key}', defined at:
226
+ | #{old_definition_location}
227
+ |was automatically loaded by RSpec because the file name
228
+ |matches the configured autoloading pattern (#{RSpec.configuration.pattern}),
229
+ |and is also being required from somewhere else. To fix this
230
+ |warning, either rename the file to not match the pattern, or
231
+ |do not explicitly require the file.
232
+ WARNING
233
+ else
234
+ RSpec.warn_with <<-WARNING.gsub(/^ +\|/, ''), :call_site => nil
235
+ |WARNING: Shared example group '#{key}' has been previously defined at:
236
+ | #{old_definition_location}
237
+ |...and you are now defining it at:
238
+ | #{new_definition_location}
239
+ |The new definition will overwrite the original one.
240
+ WARNING
241
+ end
226
242
  end
227
243
 
228
- def formatted_location(block)
229
- block.source_location.join ":"
244
+ if RUBY_VERSION.to_f >= 1.9
245
+ def formatted_location(block)
246
+ block.source_location.join(":")
247
+ end
248
+ else # 1.8.7
249
+ # :nocov:
250
+ def formatted_location(block)
251
+ block.source_location.join(":").gsub(/:in.*$/, '')
252
+ end
253
+ # :nocov:
230
254
  end
231
255
 
232
256
  if Proc.method_defined?(:source_location)
@@ -3,7 +3,7 @@ module RSpec
3
3
  # Version information for RSpec Core.
4
4
  module Version
5
5
  # Current version of RSpec Core, in semantic versioning format.
6
- STRING = '3.5.2'
6
+ STRING = '3.6.0'
7
7
  end
8
8
  end
9
9
  end
@@ -10,6 +10,12 @@ module RSpec
10
10
  # Used internally to determine what to do when a SIGINT is received.
11
11
  attr_accessor :wants_to_quit
12
12
 
13
+ # Used internally to signal that a failure outside of an example
14
+ # has occurred, and that therefore the exit status should indicate
15
+ # the run failed.
16
+ # @private
17
+ attr_accessor :non_example_failure
18
+
13
19
  def initialize(configuration=RSpec.configuration)
14
20
  @configuration = configuration
15
21
  configuration.world = self
@@ -32,8 +38,10 @@ module RSpec
32
38
  #
33
39
  # Reset world to 'scratch' before running suite.
34
40
  def reset
41
+ RSpec::ExampleGroups.remove_all_constants
35
42
  example_groups.clear
36
- @shared_example_group_registry = nil
43
+ @sources_by_path.clear if defined?(@sources_by_path)
44
+ @syntax_highlighter = nil
37
45
  end
38
46
 
39
47
  # @private
@@ -122,11 +130,18 @@ module RSpec
122
130
  end
123
131
 
124
132
  # @private
125
- def source_cache
126
- @source_cache ||= begin
127
- RSpec::Support.require_rspec_core "source"
128
- Source::Cache.new(@configuration)
133
+ def source_from_file(path)
134
+ unless defined?(@sources_by_path)
135
+ RSpec::Support.require_rspec_support 'source'
136
+ @sources_by_path = {}
129
137
  end
138
+
139
+ @sources_by_path[path] ||= Support::Source.from_file(path)
140
+ end
141
+
142
+ # @private
143
+ def syntax_highlighter
144
+ @syntax_highlighter ||= Formatters::SyntaxHighlighter.new(@configuration)
130
145
  end
131
146
 
132
147
  # @api private
@@ -224,6 +239,9 @@ module RSpec
224
239
  # @private
225
240
  # Provides a null implementation for initial use by configuration.
226
241
  module Null
242
+ def self.non_example_failure; end
243
+ def self.non_example_failure=(_); end
244
+
227
245
  def self.registered_example_group_files
228
246
  []
229
247
  end
data/lib/rspec/core.rb CHANGED
@@ -56,6 +56,7 @@ module RSpec
56
56
  # they use the runner multiple times within the same process. Users must deal
57
57
  # themselves with re-configuration of RSpec before run.
58
58
  def self.reset
59
+ RSpec::ExampleGroups.remove_all_constants
59
60
  @world = nil
60
61
  @configuration = nil
61
62
  end
@@ -68,7 +69,7 @@ module RSpec
68
69
  # same process.
69
70
  def self.clear_examples
70
71
  world.reset
71
- configuration.reporter.reset
72
+ configuration.reset_reporter
72
73
  configuration.start_time = ::RSpec::Core::Time.now
73
74
  configuration.reset_filters
74
75
  end
data.tar.gz.sig CHANGED
@@ -1,4 +1,3 @@
1
- ��pW0���0�z!��k�E.��-JX���,�}��2��)U���W����7b��`���g"MN!.C����(�r�Q���1�l���n���x�L�/#�X�g���nr�'N���}Z�����o ����
2
- �^9yF�sQPzW`l?���5�i{+ZɕQTuY�|TDSsnfY��j�L���7��w�1y���4V:�^���!
3
- �~���}P�t�=kJ��Q�[��Fm���B9*83�$ ��J��BN���s�0�A���jPv�5��d*
4
- K��H��J�s�C2�\&��r �C>����i�THO)FD�VƼ�:DLS�m𣽪���Ӎ$�C�Wq�?u.ʬ��7p����ε����V����{�H���3M81�.�L*H.�J�s�]�Xtu8�"T6^����h�d>�/�3��R.��53WU�hK٧օ��GwK�~uo�t&�f��x@��{�-/芌Ġ�F�; �@>Y�؏��m�td�0KaBD�C_�l��
1
+ �}�
2
+ !�՟���L|c"_�(��_'���,V�� u'S�W����줓a+�qo�S�,uؿK�6�y���$��i��/T*z�DT�+�d���'��� ��KN{�d��} �N���3y��OI
3
+ �l,�ȂƍZ��(X�Y���u ��O>�AcP�� �=j2�>�]Fp���/�E�<w ,&ʣG�s�ˏ4l9����_[_�:�ga��K���4B�0���EtYp��M]X��n
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.5.2
4
+ version: 3.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Baker
@@ -46,7 +46,7 @@ cert_chain:
46
46
  ZsVDj6a7lH3cNqtWXZxrb2wO38qV5AkYj8SQK7Hj3/Yui9myUX3crr+PdetazSqQ
47
47
  F3MdtaDehhjC
48
48
  -----END CERTIFICATE-----
49
- date: 2016-07-28 00:00:00.000000000 Z
49
+ date: 2017-05-04 00:00:00.000000000 Z
50
50
  dependencies:
51
51
  - !ruby/object:Gem::Dependency
52
52
  name: rspec-support
@@ -54,14 +54,14 @@ dependencies:
54
54
  requirements:
55
55
  - - "~>"
56
56
  - !ruby/object:Gem::Version
57
- version: 3.5.0
57
+ version: 3.6.0
58
58
  type: :runtime
59
59
  prerelease: false
60
60
  version_requirements: !ruby/object:Gem::Requirement
61
61
  requirements:
62
62
  - - "~>"
63
63
  - !ruby/object:Gem::Version
64
- version: 3.5.0
64
+ version: 3.6.0
65
65
  - !ruby/object:Gem::Dependency
66
66
  name: cucumber
67
67
  requirement: !ruby/object:Gem::Requirement
@@ -222,6 +222,7 @@ files:
222
222
  - lib/rspec/core/formatters/progress_formatter.rb
223
223
  - lib/rspec/core/formatters/protocol.rb
224
224
  - lib/rspec/core/formatters/snippet_extractor.rb
225
+ - lib/rspec/core/formatters/syntax_highlighter.rb
225
226
  - lib/rspec/core/hooks.rb
226
227
  - lib/rspec/core/invocations.rb
227
228
  - lib/rspec/core/memoized_helpers.rb
@@ -236,6 +237,7 @@ files:
236
237
  - lib/rspec/core/notifications.rb
237
238
  - lib/rspec/core/option_parser.rb
238
239
  - lib/rspec/core/ordering.rb
240
+ - lib/rspec/core/output_wrapper.rb
239
241
  - lib/rspec/core/pending.rb
240
242
  - lib/rspec/core/profiler.rb
241
243
  - lib/rspec/core/project_initializer.rb
@@ -250,11 +252,6 @@ files:
250
252
  - lib/rspec/core/shared_context.rb
251
253
  - lib/rspec/core/shared_example_group.rb
252
254
  - lib/rspec/core/shell_escape.rb
253
- - lib/rspec/core/source.rb
254
- - lib/rspec/core/source/location.rb
255
- - lib/rspec/core/source/node.rb
256
- - lib/rspec/core/source/syntax_highlighter.rb
257
- - lib/rspec/core/source/token.rb
258
255
  - lib/rspec/core/test_unit_assertions_adapter.rb
259
256
  - lib/rspec/core/version.rb
260
257
  - lib/rspec/core/warnings.rb
@@ -280,9 +277,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
280
277
  version: '0'
281
278
  requirements: []
282
279
  rubyforge_project:
283
- rubygems_version: 2.2.2
280
+ rubygems_version: 2.4.5.2
284
281
  signing_key:
285
282
  specification_version: 4
286
- summary: rspec-core-3.5.2
283
+ summary: rspec-core-3.6.0
287
284
  test_files: []
288
285
  has_rdoc:
metadata.gz.sig CHANGED
Binary file
@@ -1,13 +0,0 @@
1
- module RSpec
2
- module Core
3
- class Source
4
- # @private
5
- # Represents a source location of node or token.
6
- Location = Struct.new(:line, :column) do
7
- def self.location?(array)
8
- array.is_a?(Array) && array.size == 2 && array.all? { |e| e.is_a?(Integer) }
9
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,93 +0,0 @@
1
- RSpec::Support.require_rspec_core "source/location"
2
-
3
- module RSpec
4
- module Core
5
- class Source
6
- # @private
7
- # A wrapper for Ripper AST node which is generated with `Ripper.sexp`.
8
- class Node
9
- include Enumerable
10
-
11
- attr_reader :sexp, :parent
12
-
13
- def self.sexp?(array)
14
- array.is_a?(Array) && array.first.is_a?(Symbol)
15
- end
16
-
17
- def initialize(ripper_sexp, parent=nil)
18
- @sexp = ripper_sexp.freeze
19
- @parent = parent
20
- end
21
-
22
- def type
23
- sexp[0]
24
- end
25
-
26
- def args
27
- @args ||= raw_args.map do |raw_arg|
28
- if Node.sexp?(raw_arg)
29
- Node.new(raw_arg, self)
30
- elsif Location.location?(raw_arg)
31
- Location.new(*raw_arg)
32
- elsif raw_arg.is_a?(Array)
33
- GroupNode.new(raw_arg, self)
34
- else
35
- raw_arg
36
- end
37
- end.freeze
38
- end
39
-
40
- def children
41
- @children ||= args.select { |arg| arg.is_a?(Node) }.freeze
42
- end
43
-
44
- def location
45
- @location ||= args.find { |arg| arg.is_a?(Location) }
46
- end
47
-
48
- def each(&block)
49
- return to_enum(__method__) unless block_given?
50
-
51
- yield self
52
-
53
- children.each do |child|
54
- child.each(&block)
55
- end
56
- end
57
-
58
- def each_ancestor
59
- return to_enum(__method__) unless block_given?
60
-
61
- current_node = self
62
-
63
- while (current_node = current_node.parent)
64
- yield current_node
65
- end
66
- end
67
-
68
- def inspect
69
- "#<#{self.class} #{type}>"
70
- end
71
-
72
- private
73
-
74
- def raw_args
75
- sexp[1..-1] || []
76
- end
77
- end
78
-
79
- # @private
80
- class GroupNode < Node
81
- def type
82
- :group
83
- end
84
-
85
- private
86
-
87
- def raw_args
88
- sexp
89
- end
90
- end
91
- end
92
- end
93
- end