rspec-expectations 3.0.0 → 3.0.1
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 +6 -14
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/Changelog.md +10 -0
- data/README.md +22 -1
- data/lib/rspec/expectations.rb +0 -1
- data/lib/rspec/expectations/configuration.rb +5 -8
- data/lib/rspec/expectations/expectation_target.rb +4 -6
- data/lib/rspec/expectations/fail_with.rb +5 -8
- data/lib/rspec/expectations/handler.rb +2 -4
- data/lib/rspec/expectations/minitest_integration.rb +5 -4
- data/lib/rspec/expectations/syntax.rb +13 -13
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/matchers.rb +10 -11
- data/lib/rspec/matchers/built_in/all.rb +3 -5
- data/lib/rspec/matchers/built_in/base_matcher.rb +3 -4
- data/lib/rspec/matchers/built_in/be.rb +3 -6
- data/lib/rspec/matchers/built_in/be_instance_of.rb +0 -1
- data/lib/rspec/matchers/built_in/be_kind_of.rb +1 -1
- data/lib/rspec/matchers/built_in/change.rb +4 -4
- data/lib/rspec/matchers/built_in/compound.rb +5 -8
- data/lib/rspec/matchers/built_in/contain_exactly.rb +10 -9
- data/lib/rspec/matchers/built_in/eq.rb +0 -1
- data/lib/rspec/matchers/built_in/eql.rb +0 -1
- data/lib/rspec/matchers/built_in/equal.rb +2 -3
- data/lib/rspec/matchers/built_in/exist.rb +0 -4
- data/lib/rspec/matchers/built_in/include.rb +3 -3
- data/lib/rspec/matchers/built_in/match.rb +0 -1
- data/lib/rspec/matchers/built_in/operators.rb +7 -7
- data/lib/rspec/matchers/built_in/output.rb +1 -1
- data/lib/rspec/matchers/built_in/raise_error.rb +15 -12
- data/lib/rspec/matchers/built_in/respond_to.rb +5 -3
- data/lib/rspec/matchers/built_in/start_and_end_with.rb +0 -2
- data/lib/rspec/matchers/built_in/throw_symbol.rb +9 -5
- data/lib/rspec/matchers/built_in/yield.rb +14 -15
- data/lib/rspec/matchers/composable.rb +4 -2
- data/lib/rspec/matchers/dsl.rb +1 -3
- data/lib/rspec/matchers/matcher_delegator.rb +0 -1
- data/lib/rspec/matchers/pretty.rb +11 -11
- metadata +49 -56
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
NjdiYjlhYzI4ZDk5YTMyZjFjMjA4OWJlOTQ3MzgwODNhZGNjMWM3ZmZmM2Q0
|
10
|
-
NzU3MWFmMzIzYjI0OGE1NzlkZTBlMDI2NmY4ZWUwMjlmN2Y3MTFjODkzOGQ4
|
11
|
-
NWQ3NzBhMmQzNGQ2ZjNmZjQ1MjRmMWJjMjE4OTBhNDMyOGJjZTU=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
MzIyOGQ2NjI3MzJmZjM5MTU1ZDdiOTFlZDY5NWMyN2RjOGE4NGNlNGRiYmZk
|
14
|
-
NWUxZmVkMTdhMGM5YjdiZmRmNWJmNmM0MDBmMWIyODhlZmM3MzIyYWY0ZmQx
|
15
|
-
NTJlYjVlZWQ0NzE4MzBiMjIxNDEyZTE3ZjE0ZDUxOGRkZDQ4MTE=
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d379423e0b4e64ab171259aadfc7c135fc10e1a5
|
4
|
+
data.tar.gz: 801537a8f0cb606eaa4b814f32eecd39e09ed431
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ca469b494c808f9f76aff95b1818459b1da61577825f6162e6fa4b5b33b4f9b8b728890da22388c177b2d05e04ca4b9378d528b1dfb02465a5679fef24084f8f
|
7
|
+
data.tar.gz: 9a97e088ce0fa1761ae2693d8cd61b42dcc3184f4137a4f578871d4df61c3c72f293aecfafd5e85eaf0e7d7179f6f18e7f46fa067626c6a0dd9043530b9cc857
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/Changelog.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
### 3.0.1 / 2014-06-12
|
2
|
+
[Full Changelog](http://github.com/rspec/rspec-expectations/compare/v3.0.0...v3.0.1)
|
3
|
+
|
4
|
+
Bug Fixes:
|
5
|
+
|
6
|
+
* Add a missing `require` that would cause the `respond_to` matcher to
|
7
|
+
fail when used in a project where the rest of RSpec (e.g. core and
|
8
|
+
expecatations) weren't being used. (Myron Marston, #566)
|
9
|
+
* Structs are no longer treated as arrays when diffed. (Jon Rowe, #576)
|
10
|
+
|
1
11
|
### 3.0.0 / 2014-06-01
|
2
12
|
[Full Changelog](http://github.com/rspec/rspec-expectations/compare/v3.0.0.rc1...v3.0.0)
|
3
13
|
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# RSpec Expectations [](http://travis-ci.org/rspec/rspec-expectations) [](https://codeclimate.com/github/rspec/rspec-expectations)
|
1
|
+
# RSpec Expectations [](http://travis-ci.org/rspec/rspec-expectations) [](https://codeclimate.com/github/rspec/rspec-expectations)
|
2
2
|
|
3
3
|
RSpec::Expectations lets you express expected outcomes on an object in an
|
4
4
|
example.
|
@@ -249,6 +249,27 @@ expect { |probe|
|
|
249
249
|
}.to yield_successive_args( a_value < 2, 2, a_value > 2 )
|
250
250
|
```
|
251
251
|
|
252
|
+
## Usage outside rspec-core
|
253
|
+
|
254
|
+
You always need to load `rspec/expectations` even if you only want to use one part of the library:
|
255
|
+
|
256
|
+
```ruby
|
257
|
+
require 'rspec/expectations'
|
258
|
+
```
|
259
|
+
|
260
|
+
Then simply include `RSpec::Matchers` in any class:
|
261
|
+
|
262
|
+
```ruby
|
263
|
+
class MyClass
|
264
|
+
include RSpec::Matchers
|
265
|
+
|
266
|
+
def do_something(arg)
|
267
|
+
expect(arg).to be > 0
|
268
|
+
# do other stuff
|
269
|
+
end
|
270
|
+
end
|
271
|
+
```
|
272
|
+
|
252
273
|
## Also see
|
253
274
|
|
254
275
|
* [http://github.com/rspec/rspec](http://github.com/rspec/rspec)
|
data/lib/rspec/expectations.rb
CHANGED
@@ -65,9 +65,7 @@ module RSpec
|
|
65
65
|
# Indicates whether or not diffs should be colored.
|
66
66
|
# Delegates to rspec-core's color option if rspec-core
|
67
67
|
# is loaded; otherwise you can set it here.
|
68
|
-
|
69
|
-
@color = value
|
70
|
-
end
|
68
|
+
attr_writer :color
|
71
69
|
|
72
70
|
# Indicates whether or not diffs should be colored.
|
73
71
|
# Delegates to rspec-core's color option if rspec-core
|
@@ -103,10 +101,10 @@ module RSpec
|
|
103
101
|
attr_writer :backtrace_formatter
|
104
102
|
def backtrace_formatter
|
105
103
|
@backtrace_formatter ||= if defined?(::RSpec.configuration.backtrace_formatter)
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
104
|
+
::RSpec.configuration.backtrace_formatter
|
105
|
+
else
|
106
|
+
NullBacktraceFormatter
|
107
|
+
end
|
110
108
|
end
|
111
109
|
|
112
110
|
# @private
|
@@ -135,4 +133,3 @@ module RSpec
|
|
135
133
|
configuration.reset_syntaxes_to_default
|
136
134
|
end
|
137
135
|
end
|
138
|
-
|
@@ -71,7 +71,7 @@ module RSpec
|
|
71
71
|
private
|
72
72
|
|
73
73
|
def prevent_operator_matchers(verb)
|
74
|
-
raise ArgumentError, "The expect syntax does not support operator matchers, "
|
74
|
+
raise ArgumentError, "The expect syntax does not support operator matchers, " \
|
75
75
|
"so you must pass a matcher to `##{verb}`."
|
76
76
|
end
|
77
77
|
end
|
@@ -98,10 +98,9 @@ module RSpec
|
|
98
98
|
def enforce_block_expectation(matcher)
|
99
99
|
return if supports_block_expectations?(matcher)
|
100
100
|
|
101
|
-
raise ExpectationNotMetError,
|
102
|
-
"
|
103
|
-
"
|
104
|
-
"`supports_block_expectations?`."
|
101
|
+
raise ExpectationNotMetError, "You must pass an argument rather than " \
|
102
|
+
"a block to use the provided matcher (#{description_of matcher}), or " \
|
103
|
+
"the matcher must implement `supports_block_expectations?`."
|
105
104
|
end
|
106
105
|
|
107
106
|
def supports_block_expectations?(matcher)
|
@@ -118,4 +117,3 @@ module RSpec
|
|
118
117
|
end
|
119
118
|
end
|
120
119
|
end
|
121
|
-
|
@@ -6,7 +6,7 @@ module RSpec
|
|
6
6
|
# @private
|
7
7
|
def differ
|
8
8
|
RSpec::Support::Differ.new(
|
9
|
-
:object_preparer => lambda {|object| RSpec::Matchers::Composable.surface_descriptions_in(object) },
|
9
|
+
:object_preparer => lambda { |object| RSpec::Matchers::Composable.surface_descriptions_in(object) },
|
10
10
|
:color => RSpec::Matchers.configuration.color?
|
11
11
|
)
|
12
12
|
end
|
@@ -19,18 +19,15 @@ module RSpec
|
|
19
19
|
# Adds a diff to the failure message when `expected` and `actual` are
|
20
20
|
# both present.
|
21
21
|
def fail_with(message, expected=nil, actual=nil)
|
22
|
-
|
23
|
-
raise ArgumentError, "Failure message is nil. Does your matcher define the "
|
22
|
+
unless message
|
23
|
+
raise ArgumentError, "Failure message is nil. Does your matcher define the " \
|
24
24
|
"appropriate failure_message[_when_negated] method to return a string?"
|
25
25
|
end
|
26
26
|
|
27
27
|
diff = differ.diff(actual, expected)
|
28
|
+
message = "#{message}\nDiff:#{diff}" unless diff.empty?
|
28
29
|
|
29
|
-
|
30
|
-
message = "#{message}\nDiff:#{diff}"
|
31
|
-
end
|
32
|
-
|
33
|
-
raise RSpec::Expectations::ExpectationNotMetError.new(message)
|
30
|
+
raise RSpec::Expectations::ExpectationNotMetError, message
|
34
31
|
end
|
35
32
|
end
|
36
33
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module RSpec
|
2
2
|
module Expectations
|
3
|
-
|
4
3
|
# @private
|
5
4
|
module ExpectationHelper
|
6
5
|
def self.check_message(msg)
|
@@ -46,7 +45,7 @@ module RSpec
|
|
46
45
|
matcher = ExpectationHelper.setup(self, initial_matcher, message)
|
47
46
|
|
48
47
|
return ::RSpec::Matchers::BuiltIn::PositiveOperatorMatcher.new(actual) unless initial_matcher
|
49
|
-
matcher.matches?(actual, &block)
|
48
|
+
matcher.matches?(actual, &block) || ExpectationHelper.handle_failure(matcher, message, :failure_message)
|
50
49
|
end
|
51
50
|
|
52
51
|
def self.verb
|
@@ -68,7 +67,7 @@ module RSpec
|
|
68
67
|
matcher = ExpectationHelper.setup(self, initial_matcher, message)
|
69
68
|
|
70
69
|
return ::RSpec::Matchers::BuiltIn::NegativeOperatorMatcher.new(actual) unless initial_matcher
|
71
|
-
!(does_not_match?(matcher, actual, &block)
|
70
|
+
!(does_not_match?(matcher, actual, &block) || ExpectationHelper.handle_failure(matcher, message, :failure_message_when_negated))
|
72
71
|
end
|
73
72
|
|
74
73
|
def self.does_not_match?(matcher, actual, &block)
|
@@ -160,4 +159,3 @@ module RSpec
|
|
160
159
|
end
|
161
160
|
end
|
162
161
|
end
|
163
|
-
|
@@ -9,8 +9,9 @@ Minitest::Test.class_eval do
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
module RSpec
|
13
|
-
|
14
|
-
|
12
|
+
module RSpec
|
13
|
+
module Expectations
|
14
|
+
remove_const :ExpectationNotMetError
|
15
|
+
ExpectationNotMetError = ::Minitest::Assertion
|
16
|
+
end
|
15
17
|
end
|
16
|
-
|
@@ -23,19 +23,19 @@ module RSpec
|
|
23
23
|
# Generates a deprecation warning for the given method if no warning
|
24
24
|
# has already been issued.
|
25
25
|
def warn_about_should_unless_configured(method_name)
|
26
|
-
|
27
|
-
RSpec.deprecate(
|
28
|
-
"Using `#{method_name}` from rspec-expectations' old `:should` syntax without explicitly enabling the syntax",
|
29
|
-
:replacement => "the new `:expect` syntax or explicitly enable `:should`"
|
30
|
-
)
|
26
|
+
return unless @warn_about_should
|
31
27
|
|
32
|
-
|
33
|
-
|
28
|
+
RSpec.deprecate(
|
29
|
+
"Using `#{method_name}` from rspec-expectations' old `:should` syntax without explicitly enabling the syntax",
|
30
|
+
:replacement => "the new `:expect` syntax or explicitly enable `:should`"
|
31
|
+
)
|
32
|
+
|
33
|
+
@warn_about_should = false
|
34
34
|
end
|
35
35
|
|
36
36
|
# @api private
|
37
37
|
# Enables the `should` syntax.
|
38
|
-
def enable_should(syntax_host
|
38
|
+
def enable_should(syntax_host=default_should_host)
|
39
39
|
@warn_about_should = false if syntax_host == default_should_host
|
40
40
|
return if should_enabled?(syntax_host)
|
41
41
|
|
@@ -54,7 +54,7 @@ module RSpec
|
|
54
54
|
|
55
55
|
# @api private
|
56
56
|
# Disables the `should` syntax.
|
57
|
-
def disable_should(syntax_host
|
57
|
+
def disable_should(syntax_host=default_should_host)
|
58
58
|
return unless should_enabled?(syntax_host)
|
59
59
|
|
60
60
|
syntax_host.module_exec do
|
@@ -65,7 +65,7 @@ module RSpec
|
|
65
65
|
|
66
66
|
# @api private
|
67
67
|
# Enables the `expect` syntax.
|
68
|
-
def enable_expect(syntax_host
|
68
|
+
def enable_expect(syntax_host=::RSpec::Matchers)
|
69
69
|
return if expect_enabled?(syntax_host)
|
70
70
|
|
71
71
|
syntax_host.module_exec do
|
@@ -77,7 +77,7 @@ module RSpec
|
|
77
77
|
|
78
78
|
# @api private
|
79
79
|
# Disables the `expect` syntax.
|
80
|
-
def disable_expect(syntax_host
|
80
|
+
def disable_expect(syntax_host=::RSpec::Matchers)
|
81
81
|
return unless expect_enabled?(syntax_host)
|
82
82
|
|
83
83
|
syntax_host.module_exec do
|
@@ -87,13 +87,13 @@ module RSpec
|
|
87
87
|
|
88
88
|
# @api private
|
89
89
|
# Indicates whether or not the `should` syntax is enabled.
|
90
|
-
def should_enabled?(syntax_host
|
90
|
+
def should_enabled?(syntax_host=default_should_host)
|
91
91
|
syntax_host.method_defined?(:should)
|
92
92
|
end
|
93
93
|
|
94
94
|
# @api private
|
95
95
|
# Indicates whether or not the `expect` syntax is enabled.
|
96
|
-
def expect_enabled?(syntax_host
|
96
|
+
def expect_enabled?(syntax_host=::RSpec::Matchers)
|
97
97
|
syntax_host.method_defined?(:expect)
|
98
98
|
end
|
99
99
|
end
|
data/lib/rspec/matchers.rb
CHANGED
@@ -301,8 +301,7 @@ module RSpec
|
|
301
301
|
# (e.g. be_empty), letting you choose the prefix that best suits the
|
302
302
|
# predicate.
|
303
303
|
def be(*args)
|
304
|
-
args.empty? ?
|
305
|
-
Matchers::BuiltIn::Be.new : equal(*args)
|
304
|
+
args.empty? ? Matchers::BuiltIn::Be.new : equal(*args)
|
306
305
|
end
|
307
306
|
alias_matcher :a_value, :be
|
308
307
|
|
@@ -322,7 +321,7 @@ module RSpec
|
|
322
321
|
def be_an_instance_of(expected)
|
323
322
|
BuiltIn::BeAnInstanceOf.new(expected)
|
324
323
|
end
|
325
|
-
alias_method
|
324
|
+
alias_method :be_instance_of, :be_an_instance_of
|
326
325
|
alias_matcher :an_instance_of, :be_an_instance_of
|
327
326
|
|
328
327
|
# Passes if actual.kind_of?(expected)
|
@@ -335,7 +334,7 @@ module RSpec
|
|
335
334
|
def be_a_kind_of(expected)
|
336
335
|
BuiltIn::BeAKindOf.new(expected)
|
337
336
|
end
|
338
|
-
alias_method
|
337
|
+
alias_method :be_kind_of, :be_a_kind_of
|
339
338
|
alias_matcher :a_kind_of, :be_a_kind_of
|
340
339
|
|
341
340
|
# Passes if actual.between?(min, max). Works with any Comparable object,
|
@@ -702,7 +701,7 @@ module RSpec
|
|
702
701
|
def raise_error(error=Exception, message=nil, &block)
|
703
702
|
BuiltIn::RaiseError.new(error, message, &block)
|
704
703
|
end
|
705
|
-
alias_method
|
704
|
+
alias_method :raise_exception, :raise_error
|
706
705
|
|
707
706
|
alias_matcher :a_block_raising, :raise_error do |desc|
|
708
707
|
desc.sub("raise", "a block raising")
|
@@ -895,12 +894,12 @@ module RSpec
|
|
895
894
|
|
896
895
|
def method_missing(method, *args, &block)
|
897
896
|
case method.to_s
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
897
|
+
when BE_PREDICATE_REGEX
|
898
|
+
BuiltIn::BePredicate.new(method, *args, &block)
|
899
|
+
when HAS_REGEX
|
900
|
+
BuiltIn::Has.new(method, *args, &block)
|
901
|
+
else
|
902
|
+
super
|
904
903
|
end
|
905
904
|
end
|
906
905
|
|
@@ -5,7 +5,6 @@ module RSpec
|
|
5
5
|
# Provides the implementation for `all`.
|
6
6
|
# Not intended to be instantiated directly.
|
7
7
|
class All < BaseMatcher
|
8
|
-
|
9
8
|
# @private
|
10
9
|
attr_reader :matcher, :failed_objects
|
11
10
|
|
@@ -15,7 +14,7 @@ module RSpec
|
|
15
14
|
end
|
16
15
|
|
17
16
|
# @private
|
18
|
-
def does_not_match?(
|
17
|
+
def does_not_match?(_actual)
|
19
18
|
raise NotImplementedError, '`expect().not_to all( matcher )` is not supported.'
|
20
19
|
end
|
21
20
|
|
@@ -38,7 +37,7 @@ module RSpec
|
|
38
37
|
|
39
38
|
private
|
40
39
|
|
41
|
-
def match(
|
40
|
+
def match(_expected, _actual)
|
42
41
|
index_failed_objects
|
43
42
|
failed_objects.empty?
|
44
43
|
end
|
@@ -52,7 +51,7 @@ module RSpec
|
|
52
51
|
end
|
53
52
|
|
54
53
|
def failure_message_for_item(index, failure_message)
|
55
|
-
failure_message = indent_multiline_message(
|
54
|
+
failure_message = indent_multiline_message(add_new_line_if_needed(failure_message))
|
56
55
|
indent_multiline_message("object at index #{index} failed to match:#{failure_message}")
|
57
56
|
end
|
58
57
|
|
@@ -71,7 +70,6 @@ module RSpec
|
|
71
70
|
@matcher = @matcher.clone
|
72
71
|
super
|
73
72
|
end
|
74
|
-
|
75
73
|
end
|
76
74
|
end
|
77
75
|
end
|
@@ -23,7 +23,7 @@ module RSpec
|
|
23
23
|
# @private
|
24
24
|
attr_reader :actual, :expected, :rescued_exception
|
25
25
|
|
26
|
-
def initialize(expected
|
26
|
+
def initialize(expected=UNDEFINED)
|
27
27
|
@expected = expected unless UNDEFINED.equal?(expected)
|
28
28
|
end
|
29
29
|
|
@@ -98,9 +98,8 @@ module RSpec
|
|
98
98
|
private
|
99
99
|
|
100
100
|
def assert_ivars(*expected_ivars)
|
101
|
-
|
102
|
-
|
103
|
-
end
|
101
|
+
return unless (expected_ivars - present_ivars).any?
|
102
|
+
raise "#{self.class.name} needs to supply#{to_sentence expected_ivars}"
|
104
103
|
end
|
105
104
|
|
106
105
|
if RUBY_VERSION.to_f < 1.9
|
@@ -5,7 +5,6 @@ module RSpec
|
|
5
5
|
# Provides the implementation for `be_truthy`.
|
6
6
|
# Not intended to be instantiated directly.
|
7
7
|
class BeTruthy < BaseMatcher
|
8
|
-
|
9
8
|
# @api private
|
10
9
|
# @return [String]
|
11
10
|
def failure_message
|
@@ -29,7 +28,6 @@ module RSpec
|
|
29
28
|
# Provides the implementation for `be_falsey`.
|
30
29
|
# Not intended to be instantiated directly.
|
31
30
|
class BeFalsey < BaseMatcher
|
32
|
-
|
33
31
|
# @api private
|
34
32
|
# @return [String]
|
35
33
|
def failure_message
|
@@ -53,7 +51,6 @@ module RSpec
|
|
53
51
|
# Provides the implementation for `be_nil`.
|
54
52
|
# Not intended to be instantiated directly.
|
55
53
|
class BeNil < BaseMatcher
|
56
|
-
|
57
54
|
# @api private
|
58
55
|
# @return [String]
|
59
56
|
def failure_message
|
@@ -75,7 +72,7 @@ module RSpec
|
|
75
72
|
|
76
73
|
# @private
|
77
74
|
module BeHelpers
|
78
|
-
|
75
|
+
private
|
79
76
|
|
80
77
|
def args_to_s
|
81
78
|
@args.empty? ? "" : parenthesize(inspected_args.join(', '))
|
@@ -86,7 +83,7 @@ module RSpec
|
|
86
83
|
end
|
87
84
|
|
88
85
|
def inspected_args
|
89
|
-
@args.
|
86
|
+
@args.map { |a| a.inspect }
|
90
87
|
end
|
91
88
|
|
92
89
|
def expected_to_sentence
|
@@ -104,7 +101,7 @@ module RSpec
|
|
104
101
|
class Be < BaseMatcher
|
105
102
|
include BeHelpers
|
106
103
|
|
107
|
-
def initialize(*args
|
104
|
+
def initialize(*args)
|
108
105
|
@args = args
|
109
106
|
end
|
110
107
|
|