rspec-expectations 3.5.0.beta1 → 3.5.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 72c2b975192766df01f56f479ba2bf0ded3d6d4a
4
- data.tar.gz: da2cd30524e919d4a790636f81ff1e785d876474
3
+ metadata.gz: 78f6f9a82ac0ab92dc9ad76030846c26f2f614d8
4
+ data.tar.gz: ff97acba6c6cc32e8390f68e41d4986da7328323
5
5
  SHA512:
6
- metadata.gz: 0af3c1a4f19bcd46ecbb103e235db61c518307ef410e33574151cd3fa1c6774db6cad1efb3120c4921e59fb609145a09864ee558abf80141ccd08753655a0448
7
- data.tar.gz: cf16751b9bc189992934d343c557ed21964d54991d70619babe415fd724f305749cddb960a9d1346f36417b62f912ec6526b0f8cfa9ff1e417fa214771d2930f
6
+ metadata.gz: 0ed056aabff3b938a44a25e11160435561730eda169a5ef34a2cf0849a08bbf1a4c926e7715529179f2c9c2eb7735972d634d8c2f364fda0b1106945e8d5a442
7
+ data.tar.gz: 6e4167883a703dcb4486ad9a9061b2c00535d60c96c04d486eccf37beb13ecde7edcf75f422e357d7359afd2064e2d44d552357604aca33ef7720644ed017ce0
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/Changelog.md CHANGED
@@ -1,6 +1,19 @@
1
1
  ### 3.5.0 Development
2
2
  [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v3.5.0.beta1...master)
3
3
 
4
+ Enhancements:
5
+
6
+ * Add the ability to raise an error on encountering false positives via
7
+ `RSpec::Configuration#on_potential_false_positives = :raise`. (Jon Rowe, #900)
8
+ * When using the custom matcher DSL, support new
9
+ `notify_expectation_failures: true` option for the `match` method to
10
+ allow expectation failures to be raised as normal instead of being
11
+ converted into a `false` return value for `matches?`. (Jon Rowe, #892)
12
+
13
+ Bug Fixes:
14
+
15
+ * Allow `should` deprecation check to work on `BasicObject`s. (James Coleman, #898)
16
+
4
17
  ### 3.5.0.beta1 / 2016-02-06
5
18
  [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v3.4.0...v3.5.0.beta1)
6
19
 
@@ -18,8 +18,16 @@ module RSpec
18
18
  #
19
19
  # RSpec::Expectations.configuration
20
20
  class Configuration
21
+ # @private
22
+ FALSE_POSITIVE_BEHAVIOURS =
23
+ {
24
+ :warn => lambda { |message| RSpec.warning message },
25
+ :raise => lambda { |message| raise ArgumentError, message },
26
+ :nothing => lambda { |_| true },
27
+ }
28
+
21
29
  def initialize
22
- @warn_about_potential_false_positives = true
30
+ @on_potential_false_positives = :warn
23
31
  end
24
32
 
25
33
  # Configures the supported syntax.
@@ -141,14 +149,43 @@ module RSpec
141
149
  # Configures whether RSpec will warn about matcher use which will
142
150
  # potentially cause false positives in tests.
143
151
  #
144
- # @param value [Boolean]
145
- attr_writer :warn_about_potential_false_positives
152
+ # @param [Boolean] boolean
153
+ def warn_about_potential_false_positives=(boolean)
154
+ if boolean
155
+ self.on_potential_false_positives = :warn
156
+ elsif warn_about_potential_false_positives?
157
+ self.on_potential_false_positives = :nothing
158
+ else
159
+ # no-op, handler is something else
160
+ end
161
+ end
162
+ #
163
+ # Configures what RSpec will do about matcher use which will
164
+ # potentially cause false positives in tests.
165
+ #
166
+ # @param [Symbol] behavior can be set to :warn, :raise or :nothing
167
+ def on_potential_false_positives=(behavior)
168
+ unless FALSE_POSITIVE_BEHAVIOURS.key?(behavior)
169
+ raise ArgumentError, "Supported values are: #{FALSE_POSITIVE_BEHAVIOURS.keys}"
170
+ end
171
+ @on_potential_false_positives = behavior
172
+ end
173
+
174
+ # Indicates what RSpec will do about matcher use which will
175
+ # potentially cause false positives in tests, generally you want to
176
+ # avoid such scenarios so this defaults to `true`.
177
+ attr_reader :on_potential_false_positives
146
178
 
147
179
  # Indicates whether RSpec will warn about matcher use which will
148
180
  # potentially cause false positives in tests, generally you want to
149
181
  # avoid such scenarios so this defaults to `true`.
150
182
  def warn_about_potential_false_positives?
151
- @warn_about_potential_false_positives
183
+ on_potential_false_positives == :warn
184
+ end
185
+
186
+ # @private
187
+ def false_positives_handler
188
+ FALSE_POSITIVE_BEHAVIOURS.fetch(@on_potential_false_positives)
152
189
  end
153
190
  end
154
191
 
@@ -41,12 +41,12 @@ module RSpec
41
41
 
42
42
  syntax_host.module_exec do
43
43
  def should(matcher=nil, message=nil, &block)
44
- ::RSpec::Expectations::Syntax.warn_about_should_unless_configured(__method__)
44
+ ::RSpec::Expectations::Syntax.warn_about_should_unless_configured(::Kernel.__method__)
45
45
  ::RSpec::Expectations::PositiveExpectationHandler.handle_matcher(self, matcher, message, &block)
46
46
  end
47
47
 
48
48
  def should_not(matcher=nil, message=nil, &block)
49
- ::RSpec::Expectations::Syntax.warn_about_should_unless_configured(__method__)
49
+ ::RSpec::Expectations::Syntax.warn_about_should_unless_configured(::Kernel.__method__)
50
50
  ::RSpec::Expectations::NegativeExpectationHandler.handle_matcher(self, matcher, message, &block)
51
51
  end
52
52
  end
@@ -2,7 +2,7 @@ module RSpec
2
2
  module Expectations
3
3
  # @private
4
4
  module Version
5
- STRING = '3.5.0.beta1'
5
+ STRING = '3.5.0.beta2'
6
6
  end
7
7
  end
8
8
  end
@@ -12,8 +12,7 @@ module RSpec
12
12
  def initialize(expected_error_or_message=nil, expected_message=nil, &block)
13
13
  @block = block
14
14
  @actual_error = nil
15
- @warn_about_bare_error = warn_about_potential_false_positives? &&
16
- expected_error_or_message.nil?
15
+ @warn_about_bare_error = expected_error_or_message.nil?
17
16
 
18
17
  case expected_error_or_message
19
18
  when nil
@@ -133,7 +132,6 @@ module RSpec
133
132
  end
134
133
 
135
134
  def warn_for_false_positives
136
- return unless warn_about_potential_false_positives?
137
135
  expression = if expecting_specific_exception? && @expected_message
138
136
  "`expect { }.not_to raise_error(SpecificErrorClass, message)`"
139
137
  elsif expecting_specific_exception?
@@ -147,8 +145,8 @@ module RSpec
147
145
  warn_about_negative_false_positive expression
148
146
  end
149
147
 
150
- def warn_about_potential_false_positives?
151
- RSpec::Expectations.configuration.warn_about_potential_false_positives?
148
+ def handle_warning(message)
149
+ RSpec::Expectations.configuration.false_positives_handler.call(message)
152
150
  end
153
151
 
154
152
  def warning_about_bare_error
@@ -156,28 +154,28 @@ module RSpec
156
154
  end
157
155
 
158
156
  def warn_about_bare_error
159
- RSpec.warning("Using the `raise_error` matcher without providing a specific " \
160
- "error or message risks false positives, since `raise_error` " \
161
- "will match when Ruby raises a `NoMethodError`, `NameError` or " \
162
- "`ArgumentError`, potentially allowing the expectation to pass " \
163
- "without even executing the method you are intending to call. " \
164
- "#{warning}"\
165
- "Instead consider providing a specific error class or message. " \
166
- "This message can be suppressed by setting: " \
167
- "`RSpec::Expectations.configuration.warn_about_potential_false" \
168
- "_positives = false`")
157
+ handle_warning("Using the `raise_error` matcher without providing a specific " \
158
+ "error or message risks false positives, since `raise_error` " \
159
+ "will match when Ruby raises a `NoMethodError`, `NameError` or " \
160
+ "`ArgumentError`, potentially allowing the expectation to pass " \
161
+ "without even executing the method you are intending to call. " \
162
+ "#{warning}"\
163
+ "Instead consider providing a specific error class or message. " \
164
+ "This message can be suppressed by setting: " \
165
+ "`RSpec::Expectations.configuration.on_potential_false" \
166
+ "_positives = :nothing`")
169
167
  end
170
168
 
171
169
  def warn_about_negative_false_positive(expression)
172
- RSpec.warning("Using #{expression} risks false positives, since literally " \
173
- "any other error would cause the expectation to pass, " \
174
- "including those raised by Ruby (e.g. NoMethodError, NameError " \
175
- "and ArgumentError), meaning the code you are intending to test " \
176
- "may not even get reached. Instead consider using " \
177
- "`expect {}.not_to raise_error` or `expect { }.to raise_error" \
178
- "(DifferentSpecificErrorClass)`. This message can be suppressed by " \
179
- "setting: `RSpec::Expectations.configuration.warn_about_potential_false" \
180
- "_positives = false`")
170
+ handle_warning("Using #{expression} risks false positives, since literally " \
171
+ "any other error would cause the expectation to pass, " \
172
+ "including those raised by Ruby (e.g. NoMethodError, NameError " \
173
+ "and ArgumentError), meaning the code you are intending to test " \
174
+ "may not even get reached. Instead consider using " \
175
+ "`expect {}.not_to raise_error` or `expect { }.to raise_error" \
176
+ "(DifferentSpecificErrorClass)`. This message can be suppressed by " \
177
+ "setting: `RSpec::Expectations.configuration.on_potential_false" \
178
+ "_positives = :nothing`")
181
179
  end
182
180
 
183
181
  def expected_error
@@ -55,16 +55,23 @@ module RSpec
55
55
  # expect(3).to be_even # fails
56
56
  # expect(4).not_to be_even # fails
57
57
  #
58
+ # By default the match block will swallow expectation errors (e.g.
59
+ # caused by using an expectation such as `expect(1).to eq 2`), if you
60
+ # with to allow these to bubble up, pass in the option
61
+ # `:notify_expectation_failures => true`.
62
+ #
63
+ # @param [Hash] options for defining the behavior of the match block.
58
64
  # @yield [Object] actual the actual value (i.e. the value wrapped by `expect`)
59
- def match(&match_block)
65
+ def match(options={}, &match_block)
60
66
  define_user_override(:matches?, match_block) do |actual|
61
- begin
62
- @actual = actual
63
- RSpec::Support.with_failure_notifier(RAISE_NOTIFIER) do
67
+ @actual = actual
68
+ RSpec::Support.with_failure_notifier(RAISE_NOTIFIER) do
69
+ begin
64
70
  super(*actual_arg_for(match_block))
71
+ rescue RSpec::Expectations::ExpectationNotMetError
72
+ raise if options[:notify_expectation_failures]
73
+ false
65
74
  end
66
- rescue RSpec::Expectations::ExpectationNotMetError
67
- false
68
75
  end
69
76
  end
70
77
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-expectations
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.5.0.beta1
4
+ version: 3.5.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Baker
@@ -45,7 +45,7 @@ cert_chain:
45
45
  ZsVDj6a7lH3cNqtWXZxrb2wO38qV5AkYj8SQK7Hj3/Yui9myUX3crr+PdetazSqQ
46
46
  F3MdtaDehhjC
47
47
  -----END CERTIFICATE-----
48
- date: 2016-02-06 00:00:00.000000000 Z
48
+ date: 2016-03-10 00:00:00.000000000 Z
49
49
  dependencies:
50
50
  - !ruby/object:Gem::Dependency
51
51
  name: rspec-support
@@ -53,14 +53,14 @@ dependencies:
53
53
  requirements:
54
54
  - - '='
55
55
  - !ruby/object:Gem::Version
56
- version: 3.5.0.beta1
56
+ version: 3.5.0.beta2
57
57
  type: :runtime
58
58
  prerelease: false
59
59
  version_requirements: !ruby/object:Gem::Requirement
60
60
  requirements:
61
61
  - - '='
62
62
  - !ruby/object:Gem::Version
63
- version: 3.5.0.beta1
63
+ version: 3.5.0.beta2
64
64
  - !ruby/object:Gem::Dependency
65
65
  name: diff-lcs
66
66
  requirement: !ruby/object:Gem::Requirement
@@ -217,9 +217,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
217
217
  version: 1.3.1
218
218
  requirements: []
219
219
  rubyforge_project:
220
- rubygems_version: 2.4.5.1
220
+ rubygems_version: 2.5.1
221
221
  signing_key:
222
222
  specification_version: 4
223
- summary: rspec-expectations-3.5.0.beta1
223
+ summary: rspec-expectations-3.5.0.beta2
224
224
  test_files: []
225
225
  has_rdoc:
metadata.gz.sig CHANGED
Binary file