rspec-expectations 3.1.2 → 3.2.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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/Changelog.md +45 -0
- data/README.md +17 -6
- data/lib/rspec/expectations.rb +2 -1
- data/lib/rspec/expectations/configuration.rb +1 -1
- data/lib/rspec/expectations/fail_with.rb +1 -2
- data/lib/rspec/expectations/handler.rb +13 -10
- data/lib/rspec/expectations/minitest_integration.rb +1 -0
- data/lib/rspec/expectations/syntax.rb +1 -1
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/matchers.rb +37 -49
- data/lib/rspec/matchers/built_in.rb +2 -2
- data/lib/rspec/matchers/built_in/be.rb +6 -10
- data/lib/rspec/matchers/built_in/compound.rb +38 -3
- data/lib/rspec/matchers/built_in/have_attributes.rb +34 -5
- data/lib/rspec/matchers/built_in/include.rb +3 -3
- data/lib/rspec/matchers/built_in/output.rb +41 -0
- data/lib/rspec/matchers/built_in/{start_and_end_with.rb → start_or_end_with.rb} +17 -7
- data/lib/rspec/matchers/built_in/yield.rb +8 -12
- data/lib/rspec/matchers/dsl.rb +56 -7
- data/lib/rspec/matchers/expecteds_for_multiple_diffs.rb +79 -0
- data/lib/rspec/matchers/matcher_protocol.rb +66 -66
- metadata +41 -28
- metadata.gz.sig +0 -0
@@ -0,0 +1,79 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Matchers
|
3
|
+
# @api private
|
4
|
+
# Handles list of expected values when there is a need to render
|
5
|
+
# multiple diffs. Also can handle one value.
|
6
|
+
class ExpectedsForMultipleDiffs
|
7
|
+
# @private
|
8
|
+
# Default diff label when there is only one matcher in diff
|
9
|
+
# output
|
10
|
+
DEFAULT_DIFF_LABEL = "Diff:".freeze
|
11
|
+
|
12
|
+
# @private
|
13
|
+
# Maximum readable matcher description length
|
14
|
+
DESCRIPTION_MAX_LENGTH = 65
|
15
|
+
|
16
|
+
def initialize(expected_list)
|
17
|
+
@expected_list = expected_list
|
18
|
+
end
|
19
|
+
|
20
|
+
# @api private
|
21
|
+
# Wraps provided expected value in instance of
|
22
|
+
# ExpectedForMultipleDiffs. If provided value is already an
|
23
|
+
# ExpectedForMultipleDiffs then it just returns it.
|
24
|
+
# @param [Any] expected value to be wrapped
|
25
|
+
# @return [RSpec::Matchers::ExpectedsForMultipleDiffs]
|
26
|
+
def self.from(expected)
|
27
|
+
return expected if self === expected
|
28
|
+
new([[expected, DEFAULT_DIFF_LABEL]])
|
29
|
+
end
|
30
|
+
|
31
|
+
# @api private
|
32
|
+
# Wraps provided matcher list in instance of
|
33
|
+
# ExpectedForMultipleDiffs.
|
34
|
+
# @param [Array<Any>] matchers list of matchers to wrap
|
35
|
+
# @return [RSpec::Matchers::ExpectedsForMultipleDiffs]
|
36
|
+
def self.for_many_matchers(matchers)
|
37
|
+
new(matchers.map { |m| [m.expected, diff_label_for(m)] })
|
38
|
+
end
|
39
|
+
|
40
|
+
# @api private
|
41
|
+
# Returns message with diff(s) appended for provided differ
|
42
|
+
# factory and actual value if there are any
|
43
|
+
# @param [String] message original failure message
|
44
|
+
# @param [Proc] differ
|
45
|
+
# @param [Any] actual value
|
46
|
+
# @return [String]
|
47
|
+
def message_with_diff(message, differ, actual)
|
48
|
+
diff = diffs(differ, actual)
|
49
|
+
message = "#{message}\n#{diff}" unless diff.empty?
|
50
|
+
message
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def self.diff_label_for(matcher)
|
56
|
+
"Diff for (#{truncated(description_for(matcher))}):"
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.description_for(matcher)
|
60
|
+
matcher.description
|
61
|
+
rescue NoMethodError
|
62
|
+
matcher.inspect
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.truncated(description)
|
66
|
+
return description if description.length <= DESCRIPTION_MAX_LENGTH
|
67
|
+
description[0...DESCRIPTION_MAX_LENGTH - 3] << "..."
|
68
|
+
end
|
69
|
+
|
70
|
+
def diffs(differ, actual)
|
71
|
+
@expected_list.map do |(expected, diff_label)|
|
72
|
+
diff = differ.diff(actual, expected)
|
73
|
+
next if diff.empty?
|
74
|
+
"#{diff_label}#{diff}"
|
75
|
+
end.compact.join("\n")
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -7,91 +7,91 @@ module RSpec
|
|
7
7
|
class MatcherProtocol
|
8
8
|
# @!group Required Methods
|
9
9
|
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
10
|
+
# @!method matches?(actual)
|
11
|
+
# @param actual [Object] The object being matched against.
|
12
|
+
# @yield For an expression like `expect(x).to matcher do...end`, the `do/end`
|
13
|
+
# block binds to `to`. It passes that block, if there is one, on to this method.
|
14
|
+
# @return [Boolean] true if this matcher matches the provided object.
|
15
15
|
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
16
|
+
# @!method failure_message
|
17
|
+
# This will only be called if {#matches?} returns false.
|
18
|
+
# @return [String] Explanation for the failure.
|
19
19
|
|
20
20
|
# @!endgroup
|
21
21
|
|
22
22
|
# @!group Optional Methods
|
23
23
|
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
24
|
+
# @!method does_not_match?(actual)
|
25
|
+
# In a negative expectation such as `expect(x).not_to foo`, RSpec will
|
26
|
+
# call `foo.does_not_match?(x)` if this method is defined. If it's not
|
27
|
+
# defined it will fall back to using `!foo.matches?(x)`. This allows you
|
28
|
+
# to provide custom logic for the negative case.
|
29
29
|
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
30
|
+
# @param actual [Object] The object being matched against.
|
31
|
+
# @yield For an expression like `expect(x).not_to matcher do...end`, the `do/end`
|
32
|
+
# block binds to `not_to`. It passes that block, if there is one, on to this method.
|
33
|
+
# @return [Boolean] true if this matcher does not match the provided object.
|
34
34
|
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
35
|
+
# @!method failure_message_when_negated
|
36
|
+
# This will only be called when a negative match fails.
|
37
|
+
# @return [String] Explanation for the failure.
|
38
|
+
# @note This method is listed as optional because matchers do not have to
|
39
|
+
# support negation. But if your matcher does support negation, this is a
|
40
|
+
# required method -- otherwise, you'll get a `NoMethodError`.
|
41
41
|
|
42
|
-
#
|
43
|
-
#
|
42
|
+
# @!method description
|
43
|
+
# The description is used for two things:
|
44
44
|
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
45
|
+
# * When using RSpec's one-liner syntax
|
46
|
+
# (e.g. `it { is_expected.to matcher }`), the description
|
47
|
+
# is used to generate the example's doc string since you
|
48
|
+
# have not provided one.
|
49
|
+
# * In a composed matcher expression, the description is used
|
50
|
+
# as part of the failure message (and description) of the outer
|
51
|
+
# matcher.
|
52
52
|
#
|
53
|
-
#
|
53
|
+
# @return [String] Description of the matcher.
|
54
54
|
|
55
|
-
#
|
56
|
-
#
|
57
|
-
#
|
58
|
-
#
|
59
|
-
#
|
60
|
-
#
|
61
|
-
#
|
55
|
+
# @!method supports_block_expectations?
|
56
|
+
# Indicates that this matcher can be used in a block expectation expression,
|
57
|
+
# such as `expect { foo }.to raise_error`. Generally speaking, this is
|
58
|
+
# only needed for matchers which operate on a side effect of a block, rather
|
59
|
+
# than on a particular object.
|
60
|
+
# @return [Boolean] true if this matcher can be used in block expressions.
|
61
|
+
# @note If not defined, RSpec assumes a value of `false` for this method.
|
62
62
|
|
63
|
-
#
|
64
|
-
#
|
65
|
-
#
|
66
|
-
#
|
63
|
+
# @!method expects_call_stack_jump?
|
64
|
+
# Indicates that when this matcher is used in a block expectation
|
65
|
+
# expression, it expects the block to use a ruby construct that causes
|
66
|
+
# a call stack jump (such as raising an error or throwing a symbol).
|
67
67
|
#
|
68
|
-
#
|
69
|
-
#
|
68
|
+
# This is used internally for compound block expressions, as matchers
|
69
|
+
# which expect call stack jumps must be treated with care to work properly.
|
70
70
|
#
|
71
|
-
#
|
71
|
+
# @return [Boolean] true if the matcher expects a call stack jump
|
72
72
|
#
|
73
|
-
#
|
74
|
-
#
|
73
|
+
# @note This method is very rarely used or needed.
|
74
|
+
# @note If not defined, RSpec assumes a value of `false` for this method.
|
75
75
|
|
76
|
-
#
|
77
|
-
#
|
78
|
-
#
|
79
|
-
#
|
80
|
-
#
|
76
|
+
# @!method diffable?
|
77
|
+
# @return [Boolean] true if `actual` and `expected` can be diffed.
|
78
|
+
# Indicates that this matcher provides `actual` and `expected` attributes,
|
79
|
+
# and that the values returned by these can be usefully diffed, which can
|
80
|
+
# be included in the output.
|
81
81
|
|
82
|
-
#
|
83
|
-
#
|
84
|
-
#
|
85
|
-
#
|
86
|
-
#
|
87
|
-
#
|
82
|
+
# @!method actual
|
83
|
+
# @return [String, Object] If an object (rather than a string) is provided,
|
84
|
+
# RSpec will use the `pp` library to convert it to multi-line output in
|
85
|
+
# order to diff.
|
86
|
+
# The actual value for the purposes of a diff.
|
87
|
+
# @note This method is required if `diffable?` returns true.
|
88
88
|
|
89
|
-
#
|
90
|
-
#
|
91
|
-
#
|
92
|
-
#
|
93
|
-
#
|
94
|
-
#
|
89
|
+
# @!method expected
|
90
|
+
# @return [String, Object] If an object (rather than a string) is provided,
|
91
|
+
# RSpec will use the `pp` library to convert it to multi-line output in
|
92
|
+
# order to diff.
|
93
|
+
# The expected value for the purposes of a diff.
|
94
|
+
# @note This method is required if `diffable?` returns true.
|
95
95
|
|
96
96
|
# @!endgroup
|
97
97
|
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.
|
4
|
+
version: 3.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Baker
|
@@ -12,28 +12,40 @@ bindir: bin
|
|
12
12
|
cert_chain:
|
13
13
|
- |
|
14
14
|
-----BEGIN CERTIFICATE-----
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
15
|
+
MIIF1TCCA72gAwIBAgIJAPXjfUbCjdXUMA0GCSqGSIb3DQEBBQUAMIGAMQswCQYD
|
16
|
+
VQQGEwJVUzETMBEGA1UECAwKV2FzaGluZ3RvbjEQMA4GA1UEBwwHU2VhdHRsZTEO
|
17
|
+
MAwGA1UECgwFUlNwZWMxEzARBgNVBAMMCnJzcGVjLmluZm8xJTAjBgkqhkiG9w0B
|
18
|
+
CQEWFnJzcGVjQGdvb2dsZWdyb3Vwcy5jb20wHhcNMTQxMjIzMDkzNTIyWhcNMjQx
|
19
|
+
MjIyMDkzNTIyWjCBgDELMAkGA1UEBhMCVVMxEzARBgNVBAgMCldhc2hpbmd0b24x
|
20
|
+
EDAOBgNVBAcMB1NlYXR0bGUxDjAMBgNVBAoMBVJTcGVjMRMwEQYDVQQDDApyc3Bl
|
21
|
+
Yy5pbmZvMSUwIwYJKoZIhvcNAQkBFhZyc3BlY0Bnb29nbGVncm91cHMuY29tMIIC
|
22
|
+
IjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAsSmjgcHaKlD0jizRJowi2bGI
|
23
|
+
KMOHnJoExxRNHHxH+3w9kkl95YldvDRVX495b13ZCzwRe0AyqX24wq04tp0G5Z5C
|
24
|
+
e/w2pnNK4ol1eECPwQu+YGpepeODlZICL5gwQspe0cDifbBnHx5QySMiPpvx6bC0
|
25
|
+
tQTox0ppDIaMhch8IPCwyoE4DQK5bpsdwnLSHTsQjUIb7IM8tUMpd/iKrJgNffwc
|
26
|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fCIKrGpd/0CAdmYnJlx59Fk/
|
41
|
+
UbD3Eyx4psBSkU+WKO0Uf+3zNI7N/nVeNIwU/Ft+l8l7/K+427656c+ZGWDO0Gt/
|
42
|
+
BeEOSTDKP7qQ1T+JvMrBcBQo+i0cnRT10J1aoV90BhxsvWTRizIbugbaqR6Tq3bj
|
43
|
+
Akt00cIlNSplL6DenIAKSh5kF7s0tRD0tC3bNkZmNjNGkdoGEcUODEpTB3RHKKiu
|
44
|
+
e6k2Jg6m00z5vGFQhOnROG/QaUzMA3A3mFBe1RHFo07xd0pFeoeWL3vF69Gx9Jwp
|
45
|
+
ZsVDj6a7lH3cNqtWXZxrb2wO38qV5AkYj8SQK7Hj3/Yui9myUX3crr+PdetazSqQ
|
46
|
+
F3MdtaDehhjC
|
35
47
|
-----END CERTIFICATE-----
|
36
|
-
date:
|
48
|
+
date: 2015-02-03 00:00:00.000000000 Z
|
37
49
|
dependencies:
|
38
50
|
- !ruby/object:Gem::Dependency
|
39
51
|
name: rspec-support
|
@@ -41,14 +53,14 @@ dependencies:
|
|
41
53
|
requirements:
|
42
54
|
- - "~>"
|
43
55
|
- !ruby/object:Gem::Version
|
44
|
-
version: 3.
|
56
|
+
version: 3.2.0
|
45
57
|
type: :runtime
|
46
58
|
prerelease: false
|
47
59
|
version_requirements: !ruby/object:Gem::Requirement
|
48
60
|
requirements:
|
49
61
|
- - "~>"
|
50
62
|
- !ruby/object:Gem::Version
|
51
|
-
version: 3.
|
63
|
+
version: 3.2.0
|
52
64
|
- !ruby/object:Gem::Dependency
|
53
65
|
name: diff-lcs
|
54
66
|
requirement: !ruby/object:Gem::Requirement
|
@@ -103,14 +115,14 @@ dependencies:
|
|
103
115
|
requirements:
|
104
116
|
- - "~>"
|
105
117
|
- !ruby/object:Gem::Version
|
106
|
-
version: '0.
|
118
|
+
version: '0.6'
|
107
119
|
type: :development
|
108
120
|
prerelease: false
|
109
121
|
version_requirements: !ruby/object:Gem::Requirement
|
110
122
|
requirements:
|
111
123
|
- - "~>"
|
112
124
|
- !ruby/object:Gem::Version
|
113
|
-
version: '0.
|
125
|
+
version: '0.6'
|
114
126
|
- !ruby/object:Gem::Dependency
|
115
127
|
name: minitest
|
116
128
|
requirement: !ruby/object:Gem::Requirement
|
@@ -172,11 +184,12 @@ files:
|
|
172
184
|
- lib/rspec/matchers/built_in/raise_error.rb
|
173
185
|
- lib/rspec/matchers/built_in/respond_to.rb
|
174
186
|
- lib/rspec/matchers/built_in/satisfy.rb
|
175
|
-
- lib/rspec/matchers/built_in/
|
187
|
+
- lib/rspec/matchers/built_in/start_or_end_with.rb
|
176
188
|
- lib/rspec/matchers/built_in/throw_symbol.rb
|
177
189
|
- lib/rspec/matchers/built_in/yield.rb
|
178
190
|
- lib/rspec/matchers/composable.rb
|
179
191
|
- lib/rspec/matchers/dsl.rb
|
192
|
+
- lib/rspec/matchers/expecteds_for_multiple_diffs.rb
|
180
193
|
- lib/rspec/matchers/generated_descriptions.rb
|
181
194
|
- lib/rspec/matchers/matcher_delegator.rb
|
182
195
|
- lib/rspec/matchers/matcher_protocol.rb
|
@@ -205,6 +218,6 @@ rubyforge_project: rspec
|
|
205
218
|
rubygems_version: 2.2.2
|
206
219
|
signing_key:
|
207
220
|
specification_version: 4
|
208
|
-
summary: rspec-expectations-3.
|
221
|
+
summary: rspec-expectations-3.2.0
|
209
222
|
test_files: []
|
210
223
|
has_rdoc:
|
metadata.gz.sig
CHANGED
Binary file
|