rspec-core 3.0.4 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/Changelog.md +67 -0
  5. data/lib/rspec/core.rb +3 -1
  6. data/lib/rspec/core/backtrace_formatter.rb +13 -10
  7. data/lib/rspec/core/configuration.rb +123 -57
  8. data/lib/rspec/core/configuration_options.rb +12 -12
  9. data/lib/rspec/core/drb.rb +11 -11
  10. data/lib/rspec/core/dsl.rb +0 -1
  11. data/lib/rspec/core/example.rb +39 -12
  12. data/lib/rspec/core/example_group.rb +31 -98
  13. data/lib/rspec/core/filter_manager.rb +16 -17
  14. data/lib/rspec/core/formatters.rb +14 -13
  15. data/lib/rspec/core/formatters/base_formatter.rb +8 -113
  16. data/lib/rspec/core/formatters/base_text_formatter.rb +3 -5
  17. data/lib/rspec/core/formatters/console_codes.rb +1 -2
  18. data/lib/rspec/core/formatters/deprecation_formatter.rb +2 -3
  19. data/lib/rspec/core/formatters/documentation_formatter.rb +3 -4
  20. data/lib/rspec/core/formatters/helpers.rb +5 -6
  21. data/lib/rspec/core/formatters/html_formatter.rb +20 -19
  22. data/lib/rspec/core/formatters/html_printer.rb +6 -5
  23. data/lib/rspec/core/formatters/json_formatter.rb +3 -2
  24. data/lib/rspec/core/formatters/profile_formatter.rb +0 -2
  25. data/lib/rspec/core/formatters/progress_formatter.rb +4 -4
  26. data/lib/rspec/core/formatters/protocol.rb +163 -0
  27. data/lib/rspec/core/formatters/snippet_extractor.rb +7 -6
  28. data/lib/rspec/core/hooks.rb +25 -10
  29. data/lib/rspec/core/memoized_helpers.rb +7 -5
  30. data/lib/rspec/core/metadata.rb +29 -30
  31. data/lib/rspec/core/metadata_filter.rb +66 -66
  32. data/lib/rspec/core/minitest_assertions_adapter.rb +1 -1
  33. data/lib/rspec/core/mocking_adapters/flexmock.rb +3 -1
  34. data/lib/rspec/core/mocking_adapters/mocha.rb +3 -1
  35. data/lib/rspec/core/mocking_adapters/null.rb +2 -0
  36. data/lib/rspec/core/mocking_adapters/rr.rb +3 -1
  37. data/lib/rspec/core/mocking_adapters/rspec.rb +3 -1
  38. data/lib/rspec/core/notifications.rb +36 -29
  39. data/lib/rspec/core/option_parser.rb +29 -25
  40. data/lib/rspec/core/ordering.rb +8 -9
  41. data/lib/rspec/core/pending.rb +6 -8
  42. data/lib/rspec/core/project_initializer.rb +4 -2
  43. data/lib/rspec/core/project_initializer/.rspec +0 -1
  44. data/lib/rspec/core/project_initializer/spec/spec_helper.rb +37 -26
  45. data/lib/rspec/core/rake_task.rb +37 -19
  46. data/lib/rspec/core/reporter.rb +13 -16
  47. data/lib/rspec/core/ruby_project.rb +2 -2
  48. data/lib/rspec/core/runner.rb +11 -14
  49. data/lib/rspec/core/shared_example_group.rb +14 -13
  50. data/lib/rspec/core/test_unit_assertions_adapter.rb +1 -1
  51. data/lib/rspec/core/version.rb +1 -1
  52. data/lib/rspec/core/warnings.rb +4 -4
  53. data/lib/rspec/core/world.rb +22 -24
  54. metadata +6 -5
  55. metadata.gz.sig +0 -0
@@ -1,3 +1,4 @@
1
+ RSpec::Support.require_rspec_support "directory_maker"
1
2
  # ## Built-in Formatters
2
3
  #
3
4
  # * progress (default) - prints dots for passing examples, `F` for failures, `*` for pending
@@ -110,15 +111,15 @@ module RSpec::Core::Formatters
110
111
 
111
112
  # @private
112
113
  def setup_default(output_stream, deprecation_stream)
113
- if @formatters.empty?
114
- add default_formatter, output_stream
115
- end
114
+ add default_formatter, output_stream if @formatters.empty?
115
+
116
116
  unless @formatters.any? { |formatter| DeprecationFormatter === formatter }
117
117
  add DeprecationFormatter, deprecation_stream, output_stream
118
118
  end
119
- if RSpec.configuration.profile_examples? && !existing_formatter_implements?(:dump_profile)
120
- add RSpec::Core::Formatters::ProfileFormatter, output_stream
121
- end
119
+
120
+ return unless RSpec.configuration.profile_examples? && !existing_formatter_implements?(:dump_profile)
121
+
122
+ add RSpec::Core::Formatters::ProfileFormatter, output_stream
122
123
  end
123
124
 
124
125
  # @private
@@ -138,11 +139,11 @@ module RSpec::Core::Formatters
138
139
  if line
139
140
  call_site = "Formatter added at: #{line}"
140
141
  else
141
- call_site = "The formatter was added via command line flag or your "+
142
+ call_site = "The formatter was added via command line flag or your "\
142
143
  "`.rspec` file."
143
144
  end
144
145
 
145
- RSpec.warn_deprecation <<-WARNING.gsub(/\s*\|/,' ')
146
+ RSpec.warn_deprecation <<-WARNING.gsub(/\s*\|/, ' ')
146
147
  |The #{formatter_class} formatter uses the deprecated formatter
147
148
  |interface not supported directly by RSpec 3.
148
149
  |
@@ -201,9 +202,9 @@ module RSpec::Core::Formatters
201
202
  formatter_ref
202
203
  elsif string_const?(formatter_ref)
203
204
  begin
204
- formatter_ref.gsub(/^::/,'').split('::').inject(Object) { |const,string| const.const_get string }
205
+ formatter_ref.gsub(/^::/, '').split('::').inject(Object) { |a, e| a.const_get e }
205
206
  rescue NameError
206
- require( path_for(formatter_ref) ) ? retry : raise
207
+ require(path_for(formatter_ref)) ? retry : raise
207
208
  end
208
209
  end
209
210
  end
@@ -224,15 +225,15 @@ module RSpec::Core::Formatters
224
225
  def underscore(camel_cased_word)
225
226
  word = camel_cased_word.to_s.dup
226
227
  word.gsub!(/::/, '/')
227
- word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
228
- word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
228
+ word.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
229
+ word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
229
230
  word.tr!("-", "_")
230
231
  word.downcase!
231
232
  word
232
233
  end
233
234
 
234
235
  def file_at(path)
235
- FileUtils.mkdir_p(File.dirname(path))
236
+ RSpec::Support::DirectoryMaker.mkdir_p(File.dirname(path))
236
237
  File.new(path, 'w')
237
238
  end
238
239
  end
@@ -4,23 +4,20 @@ require 'stringio'
4
4
  module RSpec
5
5
  module Core
6
6
  module Formatters
7
- # RSpec's built-in formatters are all subclasses of RSpec::Core::Formatters::BaseTextFormatter,
8
- # but the BaseTextFormatter documents all of the notifications implemented as part of the standard
9
- # interface. The reporter will issue these during a normal test suite run, but a formatter will
10
- # only receive those notifications it has registered itself to receive.
7
+ # RSpec's built-in formatters are all subclasses of RSpec::Core::Formatters::BaseTextFormatter.
11
8
  #
12
9
  # @see RSpec::Core::Formatters::BaseTextFormatter
13
10
  # @see RSpec::Core::Reporter
11
+ # @see RSpec::Core::Formatters::Protocol
14
12
  class BaseFormatter
15
-
16
13
  # all formatters inheriting from this formatter will receive these notifications
17
14
  Formatters.register self, :start, :example_group_started, :close
18
15
  attr_accessor :example_group
19
16
  attr_reader :output
20
17
 
21
18
  # @api public
22
- #
23
19
  # @param output [IO] the formatter output
20
+ # @see RSpec::Core::Formatters::Protocol#initialize
24
21
  def initialize(output)
25
22
  @output = output || StringIO.new
26
23
  @example_group = nil
@@ -28,14 +25,8 @@ module RSpec
28
25
 
29
26
  # @api public
30
27
  #
31
- # This method is invoked before any examples are run, right after
32
- # they have all been collected. This can be useful for special
33
- # formatters that need to provide progress on feedback (graphical ones).
34
- #
35
- # This will only be invoked once, and the next one to be invoked
36
- # is {#example_group_started}.
37
- #
38
28
  # @param notification [StartNotification]
29
+ # @see RSpec::Core::Formatters::Protocol#start
39
30
  def start(notification)
40
31
  start_sync_output
41
32
  @example_count = notification.count
@@ -43,112 +34,17 @@ module RSpec
43
34
 
44
35
  # @api public
45
36
  #
46
- # This method is invoked at the beginning of the execution of each example group.
47
- #
48
- # The next method to be invoked after this is {#example_passed},
49
- # {#example_pending}, or {#example_group_finished}.
50
- #
51
37
  # @param notification [GroupNotification] containing example_group subclass of `RSpec::Core::ExampleGroup`
38
+ # @see RSpec::Core::Formatters::Protocol#example_group_started
52
39
  def example_group_started(notification)
53
40
  @example_group = notification.group
54
41
  end
55
42
 
56
- # @method example_group_finished
57
- # @api public
58
- #
59
- # Invoked at the end of the execution of each example group.
60
- #
61
- # @param notification [GroupNotification] containing example_group subclass of `RSpec::Core::ExampleGroup`
62
-
63
- # @method example_started
64
- # @api public
65
- #
66
- # Invoked at the beginning of the execution of each example.
67
- #
68
- # @param notification [ExampleNotification] containing example subclass of `RSpec::Core::Example`
69
-
70
- # @method example_passed
71
43
  # @api public
72
44
  #
73
- # Invoked when an example passes.
74
- #
75
- # @param notification [ExampleNotification] containing example subclass of `RSpec::Core::Example`
76
-
77
- # @method example_pending
78
- # Invoked when an example is pending.
79
- #
80
- # @param notification [ExampleNotification] containing example subclass of `RSpec::Core::Example`
81
-
82
- # @method example_failed
83
- # @api public
84
- #
85
- # Invoked when an example fails.
86
- #
87
- # @param notification [ExampleNotification] containing example subclass of `RSpec::Core::Example`
88
-
89
- # @method message
90
- # @api public
91
- #
92
- # Used by the reporter to send messages to the output stream.
93
- #
94
- # @param notification [MessageNotification] containing message
95
-
96
- # @method stop
97
- # @api public
98
- #
99
- # Invoked after all examples have executed, before dumping post-run reports.
100
- #
101
45
  # @param notification [NullNotification]
102
-
103
- # @method start_dump
104
- # @api public
105
- #
106
- # This method is invoked after all of the examples have executed. The next method
107
- # to be invoked after this one is {#dump_failures}
108
- # (BaseTextFormatter then calls {#dump_failure} once for each failed example.)
109
- #
110
- # @param notification [NullNotification]
111
-
112
- # @method dump_failures
113
- # @api public
114
- #
115
- # Dumps detailed information about each example failure.
116
- #
117
- # @param notification [NullNotification]
118
-
119
- # @method dump_summary
120
- # @api public
121
- #
122
- # This method is invoked after the dumping of examples and failures. Each parameter
123
- # is assigned to a corresponding attribute.
124
- #
125
- # @param summary [SummaryNotification] containing duration, example_count,
126
- # failure_count and pending_count
127
-
128
- # @method dump_profile
129
- # @api public
130
- #
131
- # This method is invoked after the dumping the summary if profiling is
132
- # enabled.
133
- #
134
- # @param profile [ProfileNotification] containing duration, slowest_examples
135
- # and slowest_example_groups
136
-
137
- # @method dump_pending
138
- # @api public
139
- #
140
- # Outputs a report of pending examples. This gets invoked
141
- # after the summary if option is set to do so.
142
- #
143
- # @param notification [NullNotification]
144
-
145
- # @api public
146
- #
147
- # Invoked at the very end, `close` allows the formatter to clean
148
- # up resources, e.g. open streams, etc.
149
- #
150
- # @param notification [NullNotification]
151
- def close(notification)
46
+ # @see RSpec::Core::Formatters::Protocol#close
47
+ def close(_notification)
152
48
  restore_sync_output
153
49
  end
154
50
 
@@ -159,13 +55,12 @@ module RSpec
159
55
  end
160
56
 
161
57
  def restore_sync_output
162
- output.sync = @old_sync if output_supports_sync and !output.closed?
58
+ output.sync = @old_sync if output_supports_sync && !output.closed?
163
59
  end
164
60
 
165
61
  def output_supports_sync
166
62
  output.respond_to?(:sync=)
167
63
  end
168
-
169
64
  end
170
65
  end
171
66
  end
@@ -4,15 +4,14 @@ RSpec::Support.require_rspec_core "formatters/console_codes"
4
4
  module RSpec
5
5
  module Core
6
6
  module Formatters
7
-
8
7
  # Base for all of RSpec's built-in formatters. See RSpec::Core::Formatters::BaseFormatter
9
8
  # to learn more about all of the methods called by the reporter.
10
9
  #
11
10
  # @see RSpec::Core::Formatters::BaseFormatter
12
11
  # @see RSpec::Core::Reporter
13
12
  class BaseTextFormatter < BaseFormatter
14
- Formatters.register self, :message, :dump_summary, :dump_failures,
15
- :dump_pending, :seed
13
+ Formatters.register self,
14
+ :message, :dump_summary, :dump_failures, :dump_pending, :seed
16
15
 
17
16
  # @method message
18
17
  # @api public
@@ -65,13 +64,12 @@ module RSpec
65
64
  # up resources, e.g. open streams, etc.
66
65
  #
67
66
  # @param notification [NullNotification]
68
- def close(notification)
67
+ def close(_notification)
69
68
  return unless IO === output
70
69
  return if output.closed? || output == $stdout
71
70
 
72
71
  output.close
73
72
  end
74
-
75
73
  end
76
74
  end
77
75
  end
@@ -30,7 +30,7 @@ module RSpec
30
30
  def console_code_for(code_or_symbol)
31
31
  if RSpec.configuration.respond_to?(:"#{code_or_symbol}_color")
32
32
  console_code_for configuration_color(code_or_symbol)
33
- elsif VT100_CODE_VALUES.has_key?(code_or_symbol)
33
+ elsif VT100_CODE_VALUES.key?(code_or_symbol)
34
34
  code_or_symbol
35
35
  else
36
36
  VT100_CODES.fetch(code_or_symbol) do
@@ -58,7 +58,6 @@ module RSpec
58
58
  def configuration_color(code)
59
59
  RSpec.configuration.__send__(:"#{code}_color")
60
60
  end
61
-
62
61
  end
63
62
  end
64
63
  end
@@ -37,7 +37,7 @@ module RSpec
37
37
  @seen_deprecations << notification
38
38
  end
39
39
 
40
- def deprecation_summary(notification)
40
+ def deprecation_summary(_notification)
41
41
  printer.deprecation_summary
42
42
  end
43
43
 
@@ -57,7 +57,7 @@ module RSpec
57
57
  |deprecation warnings into errors, giving you the full backtrace.
58
58
  EOS
59
59
 
60
- DEPRECATION_STREAM_NOTICE = "Pass `--deprecation-out` or set " +
60
+ DEPRECATION_STREAM_NOTICE = "Pass `--deprecation-out` or set " \
61
61
  "`config.deprecation_stream` to a file for full output."
62
62
 
63
63
  SpecifiedDeprecationMessage = Struct.new(:type) do
@@ -213,7 +213,6 @@ module RSpec
213
213
  puts RAISE_ERROR_CONFIG_NOTICE
214
214
  end
215
215
  end
216
-
217
216
  end
218
217
  end
219
218
 
@@ -6,7 +6,7 @@ module RSpec
6
6
  # @private
7
7
  class DocumentationFormatter < BaseTextFormatter
8
8
  Formatters.register self, :example_group_started, :example_group_finished,
9
- :example_passed, :example_pending, :example_failed
9
+ :example_passed, :example_pending, :example_failed
10
10
 
11
11
  def initialize(output)
12
12
  super
@@ -20,7 +20,7 @@ module RSpec
20
20
  @group_level += 1
21
21
  end
22
22
 
23
- def example_group_finished(notification)
23
+ def example_group_finished(_notification)
24
24
  @group_level -= 1
25
25
  end
26
26
 
@@ -46,7 +46,7 @@ module RSpec
46
46
  ConsoleCodes.wrap("#{current_indentation}#{example.description.strip} (PENDING: #{message})", :pending)
47
47
  end
48
48
 
49
- def failure_output(example, exception)
49
+ def failure_output(example, _exception)
50
50
  ConsoleCodes.wrap("#{current_indentation}#{example.description.strip} (FAILED - #{next_failure_index})", :failure)
51
51
  end
52
52
 
@@ -62,7 +62,6 @@ module RSpec
62
62
  def example_group_chain
63
63
  example_group.parent_groups.reverse
64
64
  end
65
-
66
65
  end
67
66
  end
68
67
  end
@@ -3,7 +3,6 @@ module RSpec
3
3
  module Formatters
4
4
  # Formatters helpers
5
5
  module Helpers
6
-
7
6
  # @private
8
7
  SUB_SECOND_PRECISION = 5
9
8
 
@@ -22,9 +21,9 @@ module RSpec
22
21
  # format_duration(135.14) #=> "2 minutes 15.14 seconds"
23
22
  def self.format_duration(duration)
24
23
  precision = case
25
- when duration < 1; SUB_SECOND_PRECISION
26
- when duration < 120; DEFAULT_PRECISION
27
- when duration < 300; 1
24
+ when duration < 1 then SUB_SECOND_PRECISION
25
+ when duration < 120 then DEFAULT_PRECISION
26
+ when duration < 300 then 1
28
27
  else 0
29
28
  end
30
29
 
@@ -54,9 +53,9 @@ module RSpec
54
53
  # The precision used is set in {Helpers::SUB_SECOND_PRECISION} and {Helpers::DEFAULT_PRECISION}.
55
54
  #
56
55
  # @see #strip_trailing_zeroes
57
- def self.format_seconds(float, precision = nil)
56
+ def self.format_seconds(float, precision=nil)
58
57
  precision ||= (float < 1) ? SUB_SECOND_PRECISION : DEFAULT_PRECISION
59
- formatted = sprintf("%.#{precision}f", float)
58
+ formatted = "%.#{precision}f" % float
60
59
  strip_trailing_zeroes(formatted)
61
60
  end
62
61
 
@@ -7,8 +7,8 @@ module RSpec
7
7
  # @private
8
8
  class HtmlFormatter < BaseFormatter
9
9
  Formatters.register self, :start, :example_group_started, :start_dump,
10
- :example_started, :example_passed, :example_failed,
11
- :example_pending, :dump_summary
10
+ :example_started, :example_passed, :example_failed,
11
+ :example_pending, :dump_summary
12
12
 
13
13
  def initialize(output)
14
14
  super(output)
@@ -30,25 +30,23 @@ module RSpec
30
30
  @example_group_red = false
31
31
  @example_group_number += 1
32
32
 
33
- unless example_group_number == 1
34
- @printer.print_example_group_end
35
- end
36
- @printer.print_example_group_start( example_group_number, notification.group.description, notification.group.parent_groups.size )
33
+ @printer.print_example_group_end unless example_group_number == 1
34
+ @printer.print_example_group_start(example_group_number, notification.group.description, notification.group.parent_groups.size)
37
35
  @printer.flush
38
36
  end
39
37
 
40
- def start_dump(notification)
38
+ def start_dump(_notification)
41
39
  @printer.print_example_group_end
42
40
  @printer.flush
43
41
  end
44
42
 
45
- def example_started(notification)
43
+ def example_started(_notification)
46
44
  @example_number += 1
47
45
  end
48
46
 
49
47
  def example_passed(passed)
50
48
  @printer.move_progress(percent_done)
51
- @printer.print_example_passed( passed.example.description, passed.example.execution_result.run_time )
49
+ @printer.print_example_passed(passed.example.description, passed.example.execution_result.run_time)
52
50
  @printer.flush
53
51
  end
54
52
 
@@ -70,13 +68,13 @@ module RSpec
70
68
 
71
69
  exception = failure.exception
72
70
  exception_details = if exception
73
- {
74
- :message => exception.message,
75
- :backtrace => failure.formatted_backtrace.join("\n")
76
- }
77
- else
78
- false
79
- end
71
+ {
72
+ :message => exception.message,
73
+ :backtrace => failure.formatted_backtrace.join("\n")
74
+ }
75
+ else
76
+ false
77
+ end
80
78
  extra = extra_failure_content(failure)
81
79
 
82
80
  @printer.print_example_failed(
@@ -97,7 +95,7 @@ module RSpec
97
95
  @printer.make_header_yellow unless @header_red
98
96
  @printer.make_example_group_header_yellow(example_group_number) unless @example_group_red
99
97
  @printer.move_progress(percent_done)
100
- @printer.print_example_pending( example.description, example.execution_result.pending_message )
98
+ @printer.print_example_pending(example.description, example.execution_result.pending_message)
101
99
  @printer.flush
102
100
  end
103
101
 
@@ -113,6 +111,9 @@ module RSpec
113
111
 
114
112
  private
115
113
 
114
+ # If these methods are declared with attr_reader Ruby will issue a warning because they are private
115
+ # rubocop:disable Style/TrivialAccessors
116
+
116
117
  # The number of the currently running example_group
117
118
  def example_group_number
118
119
  @example_group_number
@@ -122,6 +123,7 @@ module RSpec
122
123
  def example_number
123
124
  @example_number
124
125
  end
126
+ # rubocop:enable Style/TrivialAccessors
125
127
 
126
128
  def percent_done
127
129
  result = 100.0
@@ -136,12 +138,11 @@ module RSpec
136
138
  #
137
139
  def extra_failure_content(failure)
138
140
  RSpec::Support.require_rspec_core "formatters/snippet_extractor"
139
- backtrace = failure.exception.backtrace.map {|line| RSpec.configuration.backtrace_formatter.backtrace_line(line)}
141
+ backtrace = failure.exception.backtrace.map { |line| RSpec.configuration.backtrace_formatter.backtrace_line(line) }
140
142
  backtrace.compact!
141
143
  @snippet_extractor ||= SnippetExtractor.new
142
144
  " <pre class=\"ruby\"><code>#{@snippet_extractor.snippet(backtrace)}</code></pre>"
143
145
  end
144
-
145
146
  end
146
147
  end
147
148
  end