rspec-expectations 3.0.4 → 3.12.3
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 +5 -5
- checksums.yaml.gz.sig +0 -0
- data/.document +1 -1
- data/.yardopts +1 -1
- data/Changelog.md +530 -5
- data/{License.txt → LICENSE.md} +5 -4
- data/README.md +73 -31
- data/lib/rspec/expectations/block_snippet_extractor.rb +253 -0
- data/lib/rspec/expectations/configuration.rb +96 -1
- data/lib/rspec/expectations/expectation_target.rb +82 -38
- data/lib/rspec/expectations/fail_with.rb +11 -6
- data/lib/rspec/expectations/failure_aggregator.rb +229 -0
- data/lib/rspec/expectations/handler.rb +36 -15
- data/lib/rspec/expectations/minitest_integration.rb +43 -2
- data/lib/rspec/expectations/syntax.rb +5 -5
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/expectations.rb +15 -1
- data/lib/rspec/matchers/aliased_matcher.rb +79 -4
- data/lib/rspec/matchers/built_in/all.rb +11 -0
- data/lib/rspec/matchers/built_in/base_matcher.rb +111 -28
- data/lib/rspec/matchers/built_in/be.rb +28 -114
- data/lib/rspec/matchers/built_in/be_between.rb +1 -1
- data/lib/rspec/matchers/built_in/be_instance_of.rb +5 -1
- data/lib/rspec/matchers/built_in/be_kind_of.rb +5 -1
- data/lib/rspec/matchers/built_in/be_within.rb +5 -12
- data/lib/rspec/matchers/built_in/change.rb +171 -63
- data/lib/rspec/matchers/built_in/compound.rb +201 -30
- data/lib/rspec/matchers/built_in/contain_exactly.rb +73 -12
- data/lib/rspec/matchers/built_in/count_expectation.rb +169 -0
- data/lib/rspec/matchers/built_in/eq.rb +3 -38
- data/lib/rspec/matchers/built_in/eql.rb +2 -2
- data/lib/rspec/matchers/built_in/equal.rb +3 -3
- data/lib/rspec/matchers/built_in/exist.rb +7 -3
- data/lib/rspec/matchers/built_in/has.rb +93 -30
- data/lib/rspec/matchers/built_in/have_attributes.rb +114 -0
- data/lib/rspec/matchers/built_in/include.rb +133 -25
- data/lib/rspec/matchers/built_in/match.rb +79 -2
- data/lib/rspec/matchers/built_in/operators.rb +14 -5
- data/lib/rspec/matchers/built_in/output.rb +59 -2
- data/lib/rspec/matchers/built_in/raise_error.rb +130 -27
- data/lib/rspec/matchers/built_in/respond_to.rb +117 -15
- data/lib/rspec/matchers/built_in/satisfy.rb +28 -14
- data/lib/rspec/matchers/built_in/{start_and_end_with.rb → start_or_end_with.rb} +20 -8
- data/lib/rspec/matchers/built_in/throw_symbol.rb +15 -5
- data/lib/rspec/matchers/built_in/yield.rb +129 -156
- data/lib/rspec/matchers/built_in.rb +5 -3
- data/lib/rspec/matchers/composable.rb +24 -36
- data/lib/rspec/matchers/dsl.rb +203 -37
- data/lib/rspec/matchers/english_phrasing.rb +58 -0
- data/lib/rspec/matchers/expecteds_for_multiple_diffs.rb +82 -0
- data/lib/rspec/matchers/fail_matchers.rb +42 -0
- data/lib/rspec/matchers/generated_descriptions.rb +1 -2
- data/lib/rspec/matchers/matcher_delegator.rb +3 -4
- data/lib/rspec/matchers/matcher_protocol.rb +105 -0
- data/lib/rspec/matchers.rb +267 -144
- data.tar.gz.sig +0 -0
- metadata +71 -49
- metadata.gz.sig +0 -0
- data/lib/rspec/matchers/pretty.rb +0 -77
@@ -3,6 +3,7 @@ module RSpec
|
|
3
3
|
# Provides the necessary plumbing to wrap a matcher with a decorator.
|
4
4
|
# @private
|
5
5
|
class MatcherDelegator
|
6
|
+
include Composable
|
6
7
|
attr_reader :base_matcher
|
7
8
|
|
8
9
|
def initialize(base_matcher)
|
@@ -18,19 +19,17 @@ module RSpec
|
|
18
19
|
super || base_matcher.respond_to?(name, include_all)
|
19
20
|
end
|
20
21
|
else
|
22
|
+
# :nocov:
|
21
23
|
def respond_to?(name, include_all=false)
|
22
24
|
super || base_matcher.respond_to?(name, include_all)
|
23
25
|
end
|
26
|
+
# :nocov:
|
24
27
|
end
|
25
28
|
|
26
29
|
def initialize_copy(other)
|
27
30
|
@base_matcher = @base_matcher.clone
|
28
31
|
super
|
29
32
|
end
|
30
|
-
|
31
|
-
# So `===` is delegated via `method_missing`.
|
32
|
-
undef ===
|
33
|
-
undef ==
|
34
33
|
end
|
35
34
|
end
|
36
35
|
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Matchers
|
3
|
+
# rspec-expectations can work with any matcher object that implements this protocol.
|
4
|
+
#
|
5
|
+
# @note This class is not loaded at runtime by rspec-expectations. It exists
|
6
|
+
# purely to provide documentation for the matcher protocol.
|
7
|
+
class MatcherProtocol
|
8
|
+
# @!group Required Methods
|
9
|
+
|
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
|
+
|
16
|
+
# @!method failure_message
|
17
|
+
# This will only be called if {#matches?} returns false.
|
18
|
+
# @return [String] Explanation for the failure.
|
19
|
+
|
20
|
+
# @!endgroup
|
21
|
+
|
22
|
+
# @!group Optional Methods
|
23
|
+
|
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
|
+
#
|
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
|
+
|
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
|
+
|
42
|
+
# @!method description
|
43
|
+
# The description is used for two things:
|
44
|
+
#
|
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
|
+
#
|
53
|
+
# @return [String] Description of the matcher.
|
54
|
+
|
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
|
+
|
63
|
+
# @!method supports_value_expectations?
|
64
|
+
# Indicates that this matcher can be used in a value expectation expression,
|
65
|
+
# such as `expect(foo).to eq(bar)`.
|
66
|
+
# @return [Boolean] true if this matcher can be used in value expressions.
|
67
|
+
# @note If not defined, RSpec assumes a value of `true` for this method.
|
68
|
+
|
69
|
+
# @!method expects_call_stack_jump?
|
70
|
+
# Indicates that when this matcher is used in a block expectation
|
71
|
+
# expression, it expects the block to use a ruby construct that causes
|
72
|
+
# a call stack jump (such as raising an error or throwing a symbol).
|
73
|
+
#
|
74
|
+
# This is used internally for compound block expressions, as matchers
|
75
|
+
# which expect call stack jumps must be treated with care to work properly.
|
76
|
+
#
|
77
|
+
# @return [Boolean] true if the matcher expects a call stack jump
|
78
|
+
#
|
79
|
+
# @note This method is very rarely used or needed.
|
80
|
+
# @note If not defined, RSpec assumes a value of `false` for this method.
|
81
|
+
|
82
|
+
# @!method diffable?
|
83
|
+
# @return [Boolean] true if `actual` and `expected` can be diffed.
|
84
|
+
# Indicates that this matcher provides `actual` and `expected` attributes,
|
85
|
+
# and that the values returned by these can be usefully diffed, which can
|
86
|
+
# be included in the output.
|
87
|
+
|
88
|
+
# @!method actual
|
89
|
+
# @return [String, Object] If an object (rather than a string) is provided,
|
90
|
+
# RSpec will use the `pp` library to convert it to multi-line output in
|
91
|
+
# order to diff.
|
92
|
+
# The actual value for the purposes of a diff.
|
93
|
+
# @note This method is required if `diffable?` returns true.
|
94
|
+
|
95
|
+
# @!method expected
|
96
|
+
# @return [String, Object] If an object (rather than a string) is provided,
|
97
|
+
# RSpec will use the `pp` library to convert it to multi-line output in
|
98
|
+
# order to diff.
|
99
|
+
# The expected value for the purposes of a diff.
|
100
|
+
# @note This method is required if `diffable?` returns true.
|
101
|
+
|
102
|
+
# @!endgroup
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|