rspec-core 3.9.0 → 3.10.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dfc313a9688827e1869e5e7f8a77c48e4de3dae1e5c482ff025ff1ab10d8a5f9
4
- data.tar.gz: 778eadf545aad964419c6726a1528d437270b271e144406e0bafe66dea7145ee
3
+ metadata.gz: 0117b5c68702f84872a6b528a286040ebad81a5201912cf75add518b16391fd8
4
+ data.tar.gz: 6a744e765c464099b304f42223079af2133ee5e278ffa3f3f3c5118f0ccdae54
5
5
  SHA512:
6
- metadata.gz: 4e3079c080a916da726c6f5fc09d72a80c0f91273ef2cbbe1301708eb458b86773cf336c8f1aa297c819f882ee0b55952f86692c9db0fe2c0a62af5b7a8abf2e
7
- data.tar.gz: 90d9fb02c3de9af80b516bf2b3b76520281a0926e16ba383e9384a86a7843be0f20268daba0dd0baa9ca2cb135e58e1bc123b15f5dffd3f0a269ab854b5e3316
6
+ metadata.gz: d659433a8e529d32ef874d0e6c6d100a5482f1dbb1bcc00a65daccbdfd23fd16307f6938b01fada58609ea828f7215992574dd7fda7f1c2873763f9abbf77574
7
+ data.tar.gz: bdec2aae3e9a5a0c34ccba2bb97a3f4480fa8400f605bb0625b609ebb90a3abf77bfcdbe247f0137d00a2d69f26c3e9ee1565a7a653afe3d14376b3eb97f6ac4
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -1,7 +1,59 @@
1
+ ### 3.10.0 / 2020-10-30
2
+ [Full Changelog](http://github.com/rspec/rspec-core/compare/v3.9.3...v3.10.0)
3
+
4
+ Enhancements:
5
+
6
+ * Memoize `RSpec::Core::Formatters::ExceptionPresenter#exception_lines` to improve performance
7
+ with slow exception messages. (Maxime Lapointe, #2743)
8
+ * Add configuration for an error exit code (to disambiguate errored builds from failed builds
9
+ by exit status). (Dana Sherson, #2749)
10
+
11
+ # 3.9.3 / 2020-09-30
12
+ [Full Changelog](http://github.com/rspec/rspec-core/compare/v3.9.2...v3.9.3)
13
+
14
+ Bug Fixes:
15
+
16
+ * Declare `ruby2_keywords` on `method_missing` for other gems. (Jon Rowe, #2731)
17
+ * Ensure custom error codes are returned from bisect runs. (Jon Rowe, #2732)
18
+ * Ensure `RSpec::Core::Configuration` predicate config methods return booleans.
19
+ (Marc-André Lafortune, #2736)
20
+ * Prevent `rspec --bisect` from generating zombie processes while executing
21
+ bisect runs. (Benoit Tigeot, Jon Rowe, #2739)
22
+ * Predicates for pending examples, (in `RSpec::Core::Example`, `#pending?`, `#skipped?` and
23
+ `#pending_fixed?`) now return boolean values rather than truthy values.
24
+ (Marc-André Lafortune, #2756, #2758)
25
+ * Exceptions which have a message which cannot be cast to a string will no longer
26
+ cause a crash. (Jon Rowe, #2761)
27
+
28
+ ### 3.9.2 / 2020-05-02
29
+ [Full Changelog](http://github.com/rspec/rspec-core/compare/v3.9.1...v3.9.2)
30
+
31
+ Bug Fixes:
32
+
33
+ * Emit a warning when `around` hook is used with `:context` scope
34
+ (Phil Pirozhkov, #2687)
35
+ * Prevent invalid implementations of `Exception#cause` from being treated as a
36
+ valid cause (and causing strange errors) in `RSpec::Core::Formatters::ExceptionPresenter`.
37
+ (Jon Rowe, #2703)
38
+ * Correctly detect patterns when `rspec_opts` is an array in `RSpec::Core::RakeTask`.
39
+ (Marc-André Lafortune, #2704)
40
+ * Make `RSpec.clear_examples` reset example counts for example groups. This fixes
41
+ an issue with re-running specs not matching ids. (Agis Anastasopoulos, #2723)
42
+
43
+ ### 3.9.1 / 2019-12-28
44
+ [Full Changelog](http://github.com/rspec/rspec-core/compare/v3.9.0...v3.9.1)
45
+
46
+ Bug Fixes:
47
+
48
+ * Prevent bisect command from blocking when number of specs exceeds file
49
+ descriptor limit on OSX or Linux. (Benoit Tigeot, #2669)
50
+ * Prevent warnings being issued on Ruby 2.7.0. (Jon Rowe, #2680)
51
+
1
52
  ### 3.9.0 / 2019-10-07
2
53
  [Full Changelog](http://github.com/rspec/rspec-core/compare/v3.8.2...v3.9.0)
3
54
 
4
55
  Enhancements:
56
+
5
57
  * Improve the handling of errors during loading support files, if a file
6
58
  errors before loading specs, RSpec will now skip loading the specs.
7
59
  (David Rodríguez, #2568)
@@ -2119,6 +2171,7 @@ Bug fixes
2119
2171
  [Full Changelog](http://github.com/rspec/rspec-core/compare/v2.2.0...v2.2.1)
2120
2172
 
2121
2173
  Bug fixes
2174
+
2122
2175
  * alias_method instead of override Kernel#method_missing (John Wilger)
2123
2176
  * changed --autotest to --tty in generated command (MIKAMI Yoshiyuki)
2124
2177
  * revert change to debugger (had introduced conflict with Rails)
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # rspec-core [![Build Status](https://secure.travis-ci.org/rspec/rspec-core.svg?branch=master)](http://travis-ci.org/rspec/rspec-core) [![Code Climate](https://codeclimate.com/github/rspec/rspec-core.svg)](https://codeclimate.com/github/rspec/rspec-core)
1
+ # rspec-core [![Build Status](https://secure.travis-ci.org/rspec/rspec-core.svg?branch=main)](http://travis-ci.org/rspec/rspec-core) [![Code Climate](https://codeclimate.com/github/rspec/rspec-core.svg)](https://codeclimate.com/github/rspec/rspec-core)
2
2
 
3
3
  rspec-core provides the structure for writing executable examples of how your
4
4
  code should behave, and an `rspec` command with tools to constrain which
@@ -10,12 +10,12 @@ examples get run and tailor the output.
10
10
  gem install rspec-core # for rspec-core only
11
11
  rspec --help
12
12
 
13
- Want to run against the `master` branch? You'll need to include the dependent
13
+ Want to run against the `main` branch? You'll need to include the dependent
14
14
  RSpec repos as well. Add the following to your `Gemfile`:
15
15
 
16
16
  ```ruby
17
17
  %w[rspec rspec-core rspec-expectations rspec-mocks rspec-support].each do |lib|
18
- gem lib, :git => "https://github.com/rspec/#{lib}.git", :branch => 'master'
18
+ gem lib, :git => "https://github.com/rspec/#{lib}.git", :branch => 'main'
19
19
  end
20
20
  ```
21
21
 
@@ -6,7 +6,7 @@ module RSpec
6
6
  module Core
7
7
  module Bisect
8
8
  # A Bisect runner that runs requested subsets of the suite by forking
9
- # sub-processes. The master process bootstraps RSpec and the application
9
+ # sub-processes. The main process bootstraps RSpec and the application
10
10
  # environment (including preloading files specified via `--require`) so
11
11
  # that the individual spec runs do not have to re-pay that cost. Each
12
12
  # spec run happens in a forked process, ensuring that the spec files are
@@ -92,7 +92,11 @@ module RSpec
92
92
 
93
93
  def dispatch_specs(run_descriptor)
94
94
  pid = fork { run_specs(run_descriptor) }
95
- Process.waitpid(pid)
95
+ # We don't use Process.waitpid here as it was causing bisects to
96
+ # block due to the file descriptor limit on OSX / Linux. We need
97
+ # to detach the process to avoid having zombie processes
98
+ # consuming slots in the kernel process table during bisect runs.
99
+ Process.detach(pid)
96
100
  end
97
101
 
98
102
  private
@@ -67,15 +67,17 @@ module RSpec
67
67
  end
68
68
 
69
69
  # @private
70
- def self.define_aliases(name, alias_name)
70
+ def self.define_alias(name, alias_name)
71
71
  alias_method alias_name, name
72
72
  alias_method "#{alias_name}=", "#{name}="
73
- define_predicate_for alias_name
73
+ define_predicate alias_name
74
74
  end
75
75
 
76
76
  # @private
77
- def self.define_predicate_for(*names)
78
- names.each { |name| alias_method "#{name}?", name }
77
+ def self.define_predicate(name)
78
+ define_method "#{name}?" do
79
+ !!send(name)
80
+ end
79
81
  end
80
82
 
81
83
  # @private
@@ -88,7 +90,7 @@ module RSpec
88
90
  add_read_only_setting name
89
91
 
90
92
  Array(opts[:alias_with]).each do |alias_name|
91
- define_aliases(name, alias_name)
93
+ define_alias(name, alias_name)
92
94
  end
93
95
  end
94
96
 
@@ -98,7 +100,7 @@ module RSpec
98
100
  def self.add_read_only_setting(name, opts={})
99
101
  raise "Use the instance add_setting method if you want to set a default" if opts.key?(:default)
100
102
  define_reader name
101
- define_predicate_for name
103
+ define_predicate name
102
104
  end
103
105
 
104
106
  # @macro [attach] add_setting
@@ -240,6 +242,11 @@ module RSpec
240
242
  # @return [Integer]
241
243
  add_setting :failure_exit_code
242
244
 
245
+ # @macro add_setting
246
+ # The exit code to return if there are any errors outside examples (default: failure_exit_code)
247
+ # @return [Integer]
248
+ add_setting :error_exit_code
249
+
243
250
  # @macro add_setting
244
251
  # Whether or not to fail when there are no RSpec examples (default: false).
245
252
  # @return [Boolean]
@@ -312,7 +319,8 @@ module RSpec
312
319
  # Report the times for the slowest examples (default: `false`).
313
320
  # Use this to specify the number of examples to include in the profile.
314
321
  # @return [Boolean]
315
- add_setting :profile_examples
322
+ attr_writer :profile_examples
323
+ define_predicate :profile_examples
316
324
 
317
325
  # @macro add_setting
318
326
  # Run all examples if none match the configured filters
@@ -520,6 +528,7 @@ module RSpec
520
528
  @pattern = '**{,/*/**}/*_spec.rb'
521
529
  @exclude_pattern = ''
522
530
  @failure_exit_code = 1
531
+ @error_exit_code = nil # so it can be overridden by failure exit code
523
532
  @fail_if_no_examples = false
524
533
  @spec_files_loaded = false
525
534
 
@@ -1350,6 +1359,12 @@ module RSpec
1350
1359
  # end
1351
1360
  # end
1352
1361
  #
1362
+ # module PreferencesHelpers
1363
+ # def preferences(user, preferences = {})
1364
+ # # ...
1365
+ # end
1366
+ # end
1367
+ #
1353
1368
  # module UserHelpers
1354
1369
  # def users(username)
1355
1370
  # # ...
@@ -1358,12 +1373,17 @@ module RSpec
1358
1373
  #
1359
1374
  # RSpec.configure do |config|
1360
1375
  # config.include(UserHelpers) # included in all groups
1376
+ #
1377
+ # # included in examples with `:preferences` metadata
1378
+ # config.include(PreferenceHelpers, :preferences)
1379
+ #
1380
+ # # included in examples with `:type => :request` metadata
1361
1381
  # config.include(AuthenticationHelpers, :type => :request)
1362
1382
  # end
1363
1383
  #
1364
- # describe "edit profile", :type => :request do
1384
+ # describe "edit profile", :preferences, :type => :request do
1365
1385
  # it "can be viewed by owning user" do
1366
- # login_as users(:jdoe)
1386
+ # login_as preferences(users(:jdoe), :lang => 'es')
1367
1387
  # get "/profiles/jdoe"
1368
1388
  # assert_select ".username", :text => 'jdoe'
1369
1389
  # end
@@ -1391,17 +1411,21 @@ module RSpec
1391
1411
  #
1392
1412
  # @example
1393
1413
  #
1394
- # RSpec.shared_context "example users" do
1414
+ # RSpec.shared_context "example admin user" do
1395
1415
  # let(:admin_user) { create_user(:admin) }
1416
+ # end
1417
+ #
1418
+ # RSpec.shared_context "example guest user" do
1396
1419
  # let(:guest_user) { create_user(:guest) }
1397
1420
  # end
1398
1421
  #
1399
1422
  # RSpec.configure do |config|
1400
- # config.include_context "example users", :type => :request
1423
+ # config.include_context "example guest user", :type => :request
1424
+ # config.include_context "example admin user", :admin, :type => :request
1401
1425
  # end
1402
1426
  #
1403
1427
  # RSpec.describe "The admin page", :type => :request do
1404
- # it "can be viewed by admins" do
1428
+ # it "can be viewed by admins", :admin do
1405
1429
  # login_with admin_user
1406
1430
  # get "/admin"
1407
1431
  # expect(response).to be_ok
@@ -1443,12 +1467,20 @@ module RSpec
1443
1467
  # end
1444
1468
  # end
1445
1469
  #
1470
+ # module PermissionHelpers
1471
+ # def define_permissions
1472
+ # # ...
1473
+ # end
1474
+ # end
1475
+ #
1446
1476
  # RSpec.configure do |config|
1447
1477
  # config.extend(UiHelpers, :type => :request)
1478
+ # config.extend(PermissionHelpers, :with_permissions, :type => :request)
1448
1479
  # end
1449
1480
  #
1450
- # describe "edit profile", :type => :request do
1481
+ # describe "edit profile", :with_permissions, :type => :request do
1451
1482
  # run_in_browser
1483
+ # define_permissions
1452
1484
  #
1453
1485
  # it "does stuff in the client" do
1454
1486
  # # ...
@@ -1906,7 +1938,8 @@ module RSpec
1906
1938
  #
1907
1939
  # This method differs from {Hooks#before} in only one way: it supports
1908
1940
  # the `:suite` scope. Hooks with the `:suite` scope will be run once before
1909
- # the first example of the entire suite is executed.
1941
+ # the first example of the entire suite is executed. Conditions passed along
1942
+ # with `:suite` are effectively ignored.
1910
1943
  #
1911
1944
  # @see #prepend_before
1912
1945
  # @see #after
@@ -1935,7 +1968,8 @@ module RSpec
1935
1968
  #
1936
1969
  # This method differs from {Hooks#prepend_before} in only one way: it supports
1937
1970
  # the `:suite` scope. Hooks with the `:suite` scope will be run once before
1938
- # the first example of the entire suite is executed.
1971
+ # the first example of the entire suite is executed. Conditions passed along
1972
+ # with `:suite` are effectively ignored.
1939
1973
  #
1940
1974
  # @see #before
1941
1975
  # @see #after
@@ -1959,7 +1993,8 @@ module RSpec
1959
1993
  #
1960
1994
  # This method differs from {Hooks#after} in only one way: it supports
1961
1995
  # the `:suite` scope. Hooks with the `:suite` scope will be run once after
1962
- # the last example of the entire suite is executed.
1996
+ # the last example of the entire suite is executed. Conditions passed along
1997
+ # with `:suite` are effectively ignored.
1963
1998
  #
1964
1999
  # @see #append_after
1965
2000
  # @see #before
@@ -1988,7 +2023,8 @@ module RSpec
1988
2023
  #
1989
2024
  # This method differs from {Hooks#append_after} in only one way: it supports
1990
2025
  # the `:suite` scope. Hooks with the `:suite` scope will be run once after
1991
- # the last example of the entire suite is executed.
2026
+ # the last example of the entire suite is executed. Conditions passed along
2027
+ # with `:suite` are effectively ignored.
1992
2028
  #
1993
2029
  # @see #append_after
1994
2030
  # @see #before
@@ -51,6 +51,7 @@ module RSpec
51
51
  argv << "--order" << @submitted_options[:order] if @submitted_options[:order]
52
52
 
53
53
  add_failure_exit_code(argv)
54
+ add_error_exit_code(argv)
54
55
  add_full_description(argv)
55
56
  add_filter(argv, :inclusion, @filter_manager.inclusions)
56
57
  add_filter(argv, :exclusion, @filter_manager.exclusions)
@@ -67,6 +68,12 @@ module RSpec
67
68
  argv << "--failure-exit-code" << @submitted_options[:failure_exit_code].to_s
68
69
  end
69
70
 
71
+ def add_error_exit_code(argv)
72
+ return unless @submitted_options[:error_exit_code]
73
+
74
+ argv << "--error-exit-code" << @submitted_options[:error_exit_code].to_s
75
+ end
76
+
70
77
  def add_full_description(argv)
71
78
  return unless @submitted_options[:full_description]
72
79
 
@@ -231,8 +231,13 @@ module RSpec
231
231
  @example_group_class
232
232
  end
233
233
 
234
- alias_method :pending?, :pending
235
- alias_method :skipped?, :skip
234
+ def pending?
235
+ !!pending
236
+ end
237
+
238
+ def skipped?
239
+ !!skip
240
+ end
236
241
 
237
242
  # @api private
238
243
  # instance_execs the block passed to the constructor in the context of
@@ -577,7 +582,9 @@ module RSpec
577
582
  # this indicates whether or not it now passes.
578
583
  attr_accessor :pending_fixed
579
584
 
580
- alias pending_fixed? pending_fixed
585
+ def pending_fixed?
586
+ !!pending_fixed
587
+ end
581
588
 
582
589
  # @return [Boolean] Indicates if the example was completely skipped
583
590
  # (typically done via `:skip` metadata or the `skip` method). Skipped examples
@@ -111,16 +111,14 @@ module RSpec
111
111
  # @overload $1
112
112
  # @overload $1(&example_implementation)
113
113
  # @param example_implementation [Block] The implementation of the example.
114
- # @overload $1(doc_string, *metadata_keys, metadata={})
114
+ # @overload $1(doc_string, *metadata)
115
115
  # @param doc_string [String] The example's doc string.
116
- # @param metadata [Hash] Metadata for the example.
117
- # @param metadata_keys [Array<Symbol>] Metadata tags for the example.
118
- # Will be transformed into hash entries with `true` values.
119
- # @overload $1(doc_string, *metadata_keys, metadata={}, &example_implementation)
116
+ # @param metadata [Array<Symbol>, Hash] Metadata for the example.
117
+ # Symbols will be transformed into hash entries with `true` values.
118
+ # @overload $1(doc_string, *metadata, &example_implementation)
120
119
  # @param doc_string [String] The example's doc string.
121
- # @param metadata [Hash] Metadata for the example.
122
- # @param metadata_keys [Array<Symbol>] Metadata tags for the example.
123
- # Will be transformed into hash entries with `true` values.
120
+ # @param metadata [Array<Symbol>, Hash] Metadata for the example.
121
+ # Symbols will be transformed into hash entries with `true` values.
124
122
  # @param example_implementation [Block] The implementation of the example.
125
123
  # @yield [Example] the example object
126
124
  # @example
@@ -139,6 +137,11 @@ module RSpec
139
137
  # $1 "does something" do |ex|
140
138
  # # ex is the Example object that contains metadata about the example
141
139
  # end
140
+ #
141
+ # @example
142
+ # $1 "does something", :slow, :load_factor => 100 do
143
+ # end
144
+ #
142
145
  def self.define_example_method(name, extra_options={})
143
146
  idempotently_define_singleton_method(name) do |*all_args, &block|
144
147
  desc, *args = *all_args
@@ -204,11 +207,10 @@ module RSpec
204
207
  # @overload $1
205
208
  # @overload $1(&example_group_definition)
206
209
  # @param example_group_definition [Block] The definition of the example group.
207
- # @overload $1(doc_string, *metadata_keys, metadata={}, &example_implementation)
210
+ # @overload $1(doc_string, *metadata, &example_implementation)
208
211
  # @param doc_string [String] The group's doc string.
209
- # @param metadata [Hash] Metadata for the group.
210
- # @param metadata_keys [Array<Symbol>] Metadata tags for the group.
211
- # Will be transformed into hash entries with `true` values.
212
+ # @param metadata [Array<Symbol>, Hash] Metadata for the group.
213
+ # Symbols will be transformed into hash entries with `true` values.
212
214
  # @param example_group_definition [Block] The definition of the example group.
213
215
  #
214
216
  # Generates a subclass of this example group which inherits
@@ -223,12 +225,21 @@ module RSpec
223
225
  # do_something_before
224
226
  # end
225
227
  #
228
+ # before(:example, :clean_env) do
229
+ # env.clear!
230
+ # end
231
+ #
226
232
  # let(:thing) { Thing.new }
227
233
  #
228
234
  # $1 "attribute (of something)" do
229
235
  # # examples in the group get the before hook
230
236
  # # declared above, and can access `thing`
231
237
  # end
238
+ #
239
+ # $1 "needs additional setup", :clean_env, :implementation => JSON do
240
+ # # specifies that hooks with matching metadata
241
+ # # should be be run additionally
242
+ # end
232
243
  # end
233
244
  #
234
245
  # @see DSL#describe
@@ -750,8 +761,9 @@ module RSpec
750
761
  "on an example group (e.g. a `describe` or `context` block)."
751
762
  end
752
763
 
753
- super
764
+ super(name, *args)
754
765
  end
766
+ ruby2_keywords :method_missing if respond_to?(:ruby2_keywords, true)
755
767
  end
756
768
  # rubocop:enable Metrics/ClassLength
757
769
 
@@ -113,7 +113,7 @@ module RSpec
113
113
 
114
114
  # @private
115
115
  class FilterRules
116
- PROC_HEX_NUMBER = /0x[0-9a-f]+@/
116
+ PROC_HEX_NUMBER = /0x[0-9a-f]+@?/
117
117
  PROJECT_DIR = File.expand_path('.')
118
118
 
119
119
  attr_accessor :opposite
@@ -1,4 +1,5 @@
1
1
  RSpec::Support.require_rspec_support "directory_maker"
2
+
2
3
  # ## Built-in Formatters
3
4
  #
4
5
  # * progress (default) - Prints dots for passing examples, `F` for failures, `*`
@@ -43,7 +43,7 @@ module RSpec
43
43
 
44
44
  if RSpec::Support::RubyFeatures.supports_exception_cause?
45
45
  def formatted_cause(exception)
46
- last_cause = final_exception(exception)
46
+ last_cause = final_exception(exception, [exception])
47
47
  cause = []
48
48
 
49
49
  if exception.cause
@@ -51,11 +51,13 @@ module RSpec
51
51
  cause << '--- Caused by: ---'
52
52
  cause << "#{exception_class_name(last_cause)}:" unless exception_class_name(last_cause) =~ /RSpec/
53
53
 
54
- encoded_string(last_cause.message.to_s).split("\n").each do |line|
54
+ encoded_string(exception_message_string(last_cause)).split("\n").each do |line|
55
55
  cause << " #{line}"
56
56
  end
57
57
 
58
- cause << (" #{backtrace_formatter.format_backtrace(last_cause.backtrace, example.metadata).first}")
58
+ unless last_cause.backtrace.empty?
59
+ cause << (" #{backtrace_formatter.format_backtrace(last_cause.backtrace, example.metadata).first}")
60
+ end
59
61
  end
60
62
 
61
63
  cause
@@ -96,7 +98,8 @@ module RSpec
96
98
 
97
99
  def final_exception(exception, previous=[])
98
100
  cause = exception.cause
99
- if cause && !previous.include?(cause)
101
+
102
+ if cause && Exception === cause && !previous.include?(cause)
100
103
  previous << cause
101
104
  final_exception(cause, previous)
102
105
  else
@@ -171,13 +174,23 @@ module RSpec
171
174
  lines
172
175
  end
173
176
 
177
+ # rubocop:disable Lint/RescueException
178
+ def exception_message_string(exception)
179
+ exception.message.to_s
180
+ rescue Exception => other
181
+ "A #{exception.class} for which `exception.message.to_s` raises #{other.class}."
182
+ end
183
+ # rubocop:enable Lint/RescueException
184
+
174
185
  def exception_lines
175
- lines = []
176
- lines << "#{exception_class_name}:" unless exception_class_name =~ /RSpec/
177
- encoded_string(exception.message.to_s).split("\n").each do |line|
178
- lines << (line.empty? ? line : " #{line}")
186
+ @exception_lines ||= begin
187
+ lines = []
188
+ lines << "#{exception_class_name}:" unless exception_class_name =~ /RSpec/
189
+ encoded_string(exception_message_string(exception)).split("\n").each do |line|
190
+ lines << (line.empty? ? line : " #{line}")
191
+ end
192
+ lines
179
193
  end
180
- lines
181
194
  end
182
195
 
183
196
  def extra_failure_lines
@@ -13,13 +13,14 @@ module RSpec
13
13
  # @overload before(scope, &block)
14
14
  # @param scope [Symbol] `:example`, `:context`, or `:suite`
15
15
  # (defaults to `:example`)
16
- # @overload before(scope, conditions, &block)
16
+ # @overload before(scope, *conditions, &block)
17
17
  # @param scope [Symbol] `:example`, `:context`, or `:suite`
18
18
  # (defaults to `:example`)
19
- # @param conditions [Hash]
20
- # constrains this hook to examples matching these conditions e.g.
19
+ # @param conditions [Array<Symbol>, Hash] constrains this hook to
20
+ # examples matching these conditions e.g.
21
21
  # `before(:example, :ui => true) { ... }` will only run with examples
22
- # or groups declared with `:ui => true`.
22
+ # or groups declared with `:ui => true`. Symbols will be transformed
23
+ # into hash entries with `true` values.
23
24
  # @overload before(conditions, &block)
24
25
  # @param conditions [Hash]
25
26
  # constrains this hook to examples matching these conditions e.g.
@@ -59,9 +60,10 @@ module RSpec
59
60
  # before(:example) # Declared in a parent group.
60
61
  # before(:example) # Declared in the current group.
61
62
  #
62
- # If more than one `before` is declared within any one scope, they are run
63
- # in the order in which they are declared. Any `around` hooks will execute
64
- # later than any `before` hook regardless of scope.
63
+ # If more than one `before` is declared within any one example group, they
64
+ # are run in the order in which they are declared. Any `around` hooks will
65
+ # execute after `before` context hooks but before any `before` example
66
+ # hook regardless of where they are declared.
65
67
  #
66
68
  # ### Conditions
67
69
  #
@@ -214,13 +216,14 @@ module RSpec
214
216
  # @overload after(scope, &block)
215
217
  # @param scope [Symbol] `:example`, `:context`, or `:suite` (defaults to
216
218
  # `:example`)
217
- # @overload after(scope, conditions, &block)
219
+ # @overload after(scope, *conditions, &block)
218
220
  # @param scope [Symbol] `:example`, `:context`, or `:suite` (defaults to
219
221
  # `:example`)
220
- # @param conditions [Hash]
221
- # constrains this hook to examples matching these conditions e.g.
222
+ # @param conditions [Array<Symbol>, Hash] constrains this hook to
223
+ # examples matching these conditions e.g.
222
224
  # `after(:example, :ui => true) { ... }` will only run with examples
223
- # or groups declared with `:ui => true`.
225
+ # or groups declared with `:ui => true`. Symbols will be transformed
226
+ # into hash entries with `true` values.
224
227
  # @overload after(conditions, &block)
225
228
  # @param conditions [Hash]
226
229
  # constrains this hook to examples matching these conditions e.g.
@@ -261,9 +264,10 @@ module RSpec
261
264
  # after(:suite) # Declared in RSpec.configure.
262
265
  #
263
266
  # This is the reverse of the order in which `before` hooks are run.
264
- # Similarly, if more than one `after` is declared within any one scope,
265
- # they are run in reverse order of that in which they are declared. Also
266
- # `around` hooks will all have run before any after hooks are invoked.
267
+ # Similarly, if more than one `after` is declared within any example
268
+ # group, they are run in reverse order of that in which they are declared.
269
+ # Also `around` hooks will run after any `after` example hooks are
270
+ # invoked but before any `after` context hooks.
267
271
  #
268
272
  # @note The `:example` and `:context` scopes are also available as
269
273
  # `:each` and `:all`, respectively. Use whichever you prefer.
@@ -290,13 +294,15 @@ module RSpec
290
294
  # @param scope [Symbol] `:example` (defaults to `:example`)
291
295
  # present for syntax parity with `before` and `after`, but
292
296
  # `:example`/`:each` is the only supported value.
293
- # @overload around(scope, conditions, &block)
297
+ # @overload around(scope, *conditions, &block)
294
298
  # @param scope [Symbol] `:example` (defaults to `:example`)
295
299
  # present for syntax parity with `before` and `after`, but
296
300
  # `:example`/`:each` is the only supported value.
297
- # @param conditions [Hash] constrains this hook to examples matching
298
- # these conditions e.g. `around(:example, :ui => true) { ... }` will
299
- # only run with examples or groups declared with `:ui => true`.
301
+ # @param conditions [Array<Symbol>, Hash] constrains this hook to
302
+ # examples matching these conditions e.g.
303
+ # `around(:example, :ui => true) { ... }` will only run with examples
304
+ # or groups declared with `:ui => true`. Symbols will be transformed
305
+ # into hash entries with `true` values.
300
306
  # @overload around(conditions, &block)
301
307
  # @param conditions [Hash] constrains this hook to examples matching
302
308
  # these conditions e.g. `around(:example, :ui => true) { ... }` will
@@ -306,7 +312,7 @@ module RSpec
306
312
  #
307
313
  # @note the syntax of `around` is similar to that of `before` and `after`
308
314
  # but the semantics are quite different. `before` and `after` hooks are
309
- # run in the context of of the examples with which they are associated,
315
+ # run in the context of the examples with which they are associated,
310
316
  # whereas `around` hooks are actually responsible for running the
311
317
  # examples. Consequently, `around` hooks do not have direct access to
312
318
  # resources that are made available within the examples and their
@@ -333,8 +339,11 @@ module RSpec
333
339
  #
334
340
  # ### Order
335
341
  #
336
- # All `around` hooks execute immediately surrounding an example, this means
337
- # that all `before` hooks will have run and no `after` hooks will have run yet.
342
+ # The `around` hooks execute surrounding an example and its hooks.
343
+ #
344
+ # This means after any `before` context hooks, but before any `before`
345
+ # example hooks, and similarly after any `after` example hooks but before
346
+ # any `after` context hooks.
338
347
  #
339
348
  # They are not a synonym for `before`/`after`.
340
349
  def around(*args, &block)
@@ -448,6 +457,11 @@ module RSpec
448
457
  "`#{position}(:suite)` hook, registered on an example " \
449
458
  "group, will be ignored."
450
459
  return
460
+ elsif scope == :context && position == :around
461
+ # TODO: consider making this an error in RSpec 4. For SemVer reasons,
462
+ # we are only warning in RSpec 3.
463
+ RSpec.warn_with "WARNING: `around(:context)` hooks are not supported and " \
464
+ "behave like `around(:example)."
451
465
  end
452
466
 
453
467
  hook = HOOK_TYPES[position][scope].new(block, options)
@@ -37,7 +37,7 @@ module RSpec
37
37
  runner, options.args, formatter
38
38
  )
39
39
 
40
- success ? 0 : 1
40
+ runner.exit_code(success)
41
41
  end
42
42
 
43
43
  private
@@ -22,9 +22,8 @@ module RSpec::Core
22
22
  begin
23
23
  parser(options).parse!(args)
24
24
  rescue OptionParser::InvalidOption => e
25
- failure = e.message
26
- failure << " (defined in #{source})" if source
27
- abort "#{failure}\n\nPlease use --help for a listing of valid options"
25
+ abort "#{e.message}#{" (defined in #{source})" if source}\n\n" \
26
+ "Please use --help for a listing of valid options"
28
27
  end
29
28
 
30
29
  options[:files_or_directories_to_run] = args
@@ -96,6 +95,11 @@ module RSpec::Core
96
95
  options[:failure_exit_code] = code
97
96
  end
98
97
 
98
+ parser.on('--error-exit-code CODE', Integer,
99
+ 'Override the exit code used when there are errors loading or running specs outside of examples.') do |code|
100
+ options[:error_exit_code] = code
101
+ end
102
+
99
103
  parser.on('-X', '--[no-]drb', 'Run examples via DRb.') do |use_drb|
100
104
  options[:drb] = use_drb
101
105
  options[:runner] = RSpec::Core::Invocations::DRbWithFallback.new if use_drb
@@ -122,7 +122,7 @@ module RSpec
122
122
  if ENV['SPEC']
123
123
  FileList[ENV['SPEC']].sort
124
124
  elsif String === pattern && !File.exist?(pattern)
125
- return if rspec_opts =~ /--pattern/
125
+ return if [*rspec_opts].any? { |opt| opt =~ /--pattern/ }
126
126
  "--pattern #{escape pattern}"
127
127
  else
128
128
  # Before RSpec 3.1, we used `FileList` to get the list of matched
@@ -84,7 +84,7 @@ module RSpec
84
84
  # @param out [IO] output stream
85
85
  def run(err, out)
86
86
  setup(err, out)
87
- return @configuration.reporter.exit_early(@configuration.failure_exit_code) if RSpec.world.wants_to_quit
87
+ return @configuration.reporter.exit_early(exit_code) if RSpec.world.wants_to_quit
88
88
 
89
89
  run_specs(@world.ordered_example_groups).tap do
90
90
  persist_example_statuses
@@ -112,7 +112,7 @@ module RSpec
112
112
  # failed.
113
113
  def run_specs(example_groups)
114
114
  examples_count = @world.example_count(example_groups)
115
- success = @configuration.reporter.report(examples_count) do |reporter|
115
+ examples_passed = @configuration.reporter.report(examples_count) do |reporter|
116
116
  @configuration.with_suite_hooks do
117
117
  if examples_count == 0 && @configuration.fail_if_no_examples
118
118
  return @configuration.failure_exit_code
@@ -120,9 +120,9 @@ module RSpec
120
120
 
121
121
  example_groups.map { |g| g.run(reporter) }.all?
122
122
  end
123
- end && !@world.non_example_failure
123
+ end
124
124
 
125
- success ? 0 : @configuration.failure_exit_code
125
+ exit_code(examples_passed)
126
126
  end
127
127
 
128
128
  # @private
@@ -186,6 +186,14 @@ module RSpec
186
186
  end
187
187
  end
188
188
 
189
+ # @private
190
+ def exit_code(examples_passed=false)
191
+ return @configuration.error_exit_code || @configuration.failure_exit_code if @world.non_example_failure
192
+ return @configuration.failure_exit_code unless examples_passed
193
+
194
+ 0
195
+ end
196
+
189
197
  private
190
198
 
191
199
  def persist_example_statuses
@@ -1,3 +1,5 @@
1
+ RSpec::Support.require_rspec_support "with_keywords_when_needed"
2
+
1
3
  module RSpec
2
4
  module Core
3
5
  # Represents some functionality that is shared with multiple example groups.
@@ -33,7 +35,7 @@ module RSpec
33
35
  klass.update_inherited_metadata(@metadata) unless @metadata.empty?
34
36
 
35
37
  SharedExampleGroupInclusionStackFrame.with_frame(@description, inclusion_line) do
36
- klass.class_exec(*args, &@definition)
38
+ RSpec::Support::WithKeywordsWhenNeeded.class_exec(klass, *args, &@definition)
37
39
  klass.class_exec(&customization_block) if customization_block
38
40
  end
39
41
  end
@@ -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.9.0'
6
+ STRING = '3.10.0'
7
7
  end
8
8
  end
9
9
  end
@@ -5,7 +5,7 @@ module RSpec
5
5
  # Internal container for global non-configuration data.
6
6
  class World
7
7
  # @private
8
- attr_reader :example_groups, :filtered_examples
8
+ attr_reader :example_groups, :filtered_examples, :example_group_counts_by_spec_file
9
9
 
10
10
  # Used internally to determine what to do when a SIGINT is received.
11
11
  attr_accessor :wants_to_quit
@@ -17,6 +17,7 @@ module RSpec
17
17
  attr_accessor :non_example_failure
18
18
 
19
19
  def initialize(configuration=RSpec.configuration)
20
+ @wants_to_quit = false
20
21
  @configuration = configuration
21
22
  configuration.world = self
22
23
  @example_groups = []
@@ -53,6 +54,7 @@ module RSpec
53
54
  example_groups.clear
54
55
  @sources_by_path.clear if defined?(@sources_by_path)
55
56
  @syntax_highlighter = nil
57
+ @example_group_counts_by_spec_file = Hash.new(0)
56
58
  end
57
59
 
58
60
  # @private
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.9.0
4
+ version: 3.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Baker
8
8
  - David Chelimsky
9
9
  - Chad Humphries
10
10
  - Myron Marston
11
- autorequire:
11
+ autorequire:
12
12
  bindir: exe
13
13
  cert_chain:
14
14
  - |
@@ -46,7 +46,7 @@ cert_chain:
46
46
  ZsVDj6a7lH3cNqtWXZxrb2wO38qV5AkYj8SQK7Hj3/Yui9myUX3crr+PdetazSqQ
47
47
  F3MdtaDehhjC
48
48
  -----END CERTIFICATE-----
49
- date: 2019-10-07 00:00:00.000000000 Z
49
+ date: 2020-10-30 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.9.0
57
+ version: 3.10.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.9.0
64
+ version: 3.10.0
65
65
  - !ruby/object:Gem::Dependency
66
66
  name: cucumber
67
67
  requirement: !ruby/object:Gem::Requirement
@@ -267,11 +267,11 @@ licenses:
267
267
  - MIT
268
268
  metadata:
269
269
  bug_tracker_uri: https://github.com/rspec/rspec-core/issues
270
- changelog_uri: https://github.com/rspec/rspec-core/blob/v3.9.0/Changelog.md
270
+ changelog_uri: https://github.com/rspec/rspec-core/blob/v3.10.0/Changelog.md
271
271
  documentation_uri: https://rspec.info/documentation/
272
272
  mailing_list_uri: https://groups.google.com/forum/#!forum/rspec
273
273
  source_code_uri: https://github.com/rspec/rspec-core
274
- post_install_message:
274
+ post_install_message:
275
275
  rdoc_options:
276
276
  - "--charset=UTF-8"
277
277
  require_paths:
@@ -287,8 +287,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
287
287
  - !ruby/object:Gem::Version
288
288
  version: '0'
289
289
  requirements: []
290
- rubygems_version: 3.0.6
291
- signing_key:
290
+ rubygems_version: 3.1.3
291
+ signing_key:
292
292
  specification_version: 4
293
- summary: rspec-core-3.9.0
293
+ summary: rspec-core-3.10.0
294
294
  test_files: []
metadata.gz.sig CHANGED
Binary file