rspec-expectations 3.0.0.beta2 → 3.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +2 -2
- data/.yardopts +0 -1
- data/Changelog.md +115 -35
- data/README.md +2 -2
- data/lib/rspec/expectations.rb +13 -8
- data/lib/rspec/{matchers → expectations}/configuration.rb +38 -13
- data/lib/rspec/expectations/expectation_target.rb +72 -8
- data/lib/rspec/expectations/fail_with.rb +10 -52
- data/lib/rspec/expectations/handler.rb +9 -11
- data/lib/rspec/expectations/syntax.rb +37 -35
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/matchers.rb +60 -9
- data/lib/rspec/matchers/aliased_matcher.rb +6 -0
- data/lib/rspec/matchers/built_in.rb +9 -1
- data/lib/rspec/matchers/built_in/all.rb +78 -0
- data/lib/rspec/matchers/built_in/base_matcher.rb +39 -1
- data/lib/rspec/matchers/built_in/be.rb +117 -42
- data/lib/rspec/matchers/built_in/be_between.rb +22 -0
- data/lib/rspec/matchers/built_in/be_instance_of.rb +11 -3
- data/lib/rspec/matchers/built_in/be_kind_of.rb +5 -0
- data/lib/rspec/matchers/built_in/be_within.rb +26 -6
- data/lib/rspec/matchers/built_in/change.rb +89 -13
- data/lib/rspec/matchers/built_in/compound.rb +19 -3
- data/lib/rspec/matchers/built_in/contain_exactly.rb +17 -6
- data/lib/rspec/matchers/built_in/cover.rb +3 -0
- data/lib/rspec/matchers/built_in/eq.rb +20 -5
- data/lib/rspec/matchers/built_in/eql.rb +15 -3
- data/lib/rspec/matchers/built_in/equal.rb +23 -6
- data/lib/rspec/matchers/built_in/exist.rb +74 -10
- data/lib/rspec/matchers/built_in/has.rb +58 -3
- data/lib/rspec/matchers/built_in/include.rb +16 -1
- data/lib/rspec/matchers/built_in/match.rb +14 -4
- data/lib/rspec/matchers/built_in/operators.rb +16 -0
- data/lib/rspec/matchers/built_in/output.rb +47 -5
- data/lib/rspec/matchers/built_in/raise_error.rb +40 -23
- data/lib/rspec/matchers/built_in/respond_to.rb +37 -16
- data/lib/rspec/matchers/built_in/satisfy.rb +15 -0
- data/lib/rspec/matchers/built_in/start_and_end_with.rb +29 -14
- data/lib/rspec/matchers/built_in/throw_symbol.rb +32 -3
- data/lib/rspec/matchers/built_in/yield.rb +148 -44
- data/lib/rspec/matchers/composable.rb +48 -7
- data/lib/rspec/matchers/dsl.rb +45 -17
- data/lib/rspec/matchers/generated_descriptions.rb +7 -0
- data/lib/rspec/matchers/matcher_delegator.rb +6 -2
- data/lib/rspec/matchers/pretty.rb +15 -19
- metadata +33 -236
- metadata.gz.sig +0 -0
- data/features/README.md +0 -48
- data/features/Upgrade.md +0 -53
- data/features/built_in_matchers/README.md +0 -96
- data/features/built_in_matchers/be.feature +0 -175
- data/features/built_in_matchers/be_within.feature +0 -48
- data/features/built_in_matchers/comparisons.feature +0 -97
- data/features/built_in_matchers/contain_exactly.feature +0 -46
- data/features/built_in_matchers/cover.feature +0 -47
- data/features/built_in_matchers/end_with.feature +0 -48
- data/features/built_in_matchers/equality.feature +0 -136
- data/features/built_in_matchers/exist.feature +0 -45
- data/features/built_in_matchers/expect_change.feature +0 -59
- data/features/built_in_matchers/expect_error.feature +0 -144
- data/features/built_in_matchers/include.feature +0 -126
- data/features/built_in_matchers/match.feature +0 -51
- data/features/built_in_matchers/output.feature +0 -70
- data/features/built_in_matchers/predicates.feature +0 -161
- data/features/built_in_matchers/respond_to.feature +0 -84
- data/features/built_in_matchers/satisfy.feature +0 -33
- data/features/built_in_matchers/start_with.feature +0 -48
- data/features/built_in_matchers/throw_symbol.feature +0 -91
- data/features/built_in_matchers/types.feature +0 -116
- data/features/built_in_matchers/yield.feature +0 -161
- data/features/composing_matchers.feature +0 -250
- data/features/compound_expectations.feature +0 -45
- data/features/custom_matchers/access_running_example.feature +0 -53
- data/features/custom_matchers/define_diffable_matcher.feature +0 -27
- data/features/custom_matchers/define_matcher.feature +0 -340
- data/features/custom_matchers/define_matcher_outside_rspec.feature +0 -34
- data/features/custom_matchers/define_matcher_with_fluent_interface.feature +0 -24
- data/features/customized_message.feature +0 -39
- data/features/diffing.feature +0 -85
- data/features/implicit_docstrings.feature +0 -52
- data/features/step_definitions/additional_cli_steps.rb +0 -22
- data/features/support/env.rb +0 -21
- data/features/support/rubinius.rb +0 -6
- data/features/syntax_configuration.feature +0 -71
- data/features/test_frameworks/minitest.feature +0 -44
- data/lib/rspec-expectations.rb +0 -1
- data/lib/rspec/expectations/diff_presenter.rb +0 -141
- data/lib/rspec/expectations/differ.rb +0 -44
- data/lib/rspec/expectations/encoded_string.rb +0 -56
- data/spec/rspec/expectations/diff_presenter_spec.rb +0 -249
- data/spec/rspec/expectations/encoded_string_spec.rb +0 -74
- data/spec/rspec/expectations/expectation_target_spec.rb +0 -82
- data/spec/rspec/expectations/extensions/kernel_spec.rb +0 -67
- data/spec/rspec/expectations/fail_with_spec.rb +0 -114
- data/spec/rspec/expectations/handler_spec.rb +0 -205
- data/spec/rspec/expectations/minitest_integration_spec.rb +0 -27
- data/spec/rspec/expectations/syntax_spec.rb +0 -89
- data/spec/rspec/expectations_spec.rb +0 -12
- data/spec/rspec/matchers/aliased_matcher_spec.rb +0 -48
- data/spec/rspec/matchers/aliases_spec.rb +0 -449
- data/spec/rspec/matchers/built_in/base_matcher_spec.rb +0 -83
- data/spec/rspec/matchers/built_in/be_between_spec.rb +0 -159
- data/spec/rspec/matchers/built_in/be_instance_of_spec.rb +0 -63
- data/spec/rspec/matchers/built_in/be_kind_of_spec.rb +0 -41
- data/spec/rspec/matchers/built_in/be_spec.rb +0 -592
- data/spec/rspec/matchers/built_in/be_within_spec.rb +0 -141
- data/spec/rspec/matchers/built_in/change_spec.rb +0 -808
- data/spec/rspec/matchers/built_in/compound_spec.rb +0 -292
- data/spec/rspec/matchers/built_in/contain_exactly_spec.rb +0 -441
- data/spec/rspec/matchers/built_in/cover_spec.rb +0 -69
- data/spec/rspec/matchers/built_in/eq_spec.rb +0 -156
- data/spec/rspec/matchers/built_in/eql_spec.rb +0 -41
- data/spec/rspec/matchers/built_in/equal_spec.rb +0 -106
- data/spec/rspec/matchers/built_in/exist_spec.rb +0 -124
- data/spec/rspec/matchers/built_in/has_spec.rb +0 -161
- data/spec/rspec/matchers/built_in/include_spec.rb +0 -540
- data/spec/rspec/matchers/built_in/match_spec.rb +0 -102
- data/spec/rspec/matchers/built_in/operators_spec.rb +0 -252
- data/spec/rspec/matchers/built_in/output_spec.rb +0 -165
- data/spec/rspec/matchers/built_in/raise_error_spec.rb +0 -461
- data/spec/rspec/matchers/built_in/respond_to_spec.rb +0 -292
- data/spec/rspec/matchers/built_in/satisfy_spec.rb +0 -44
- data/spec/rspec/matchers/built_in/start_and_end_with_spec.rb +0 -253
- data/spec/rspec/matchers/built_in/throw_symbol_spec.rb +0 -135
- data/spec/rspec/matchers/built_in/yield_spec.rb +0 -627
- data/spec/rspec/matchers/configuration_spec.rb +0 -213
- data/spec/rspec/matchers/description_generation_spec.rb +0 -191
- data/spec/rspec/matchers/dsl_spec.rb +0 -895
- data/spec/rspec/matchers/legacy_spec.rb +0 -101
- data/spec/rspec/matchers_spec.rb +0 -74
- data/spec/spec_helper.rb +0 -85
- data/spec/support/matchers.rb +0 -22
- data/spec/support/shared_examples.rb +0 -35
@@ -1,12 +1,23 @@
|
|
1
1
|
module RSpec
|
2
2
|
module Matchers
|
3
3
|
module BuiltIn
|
4
|
+
# @api private
|
5
|
+
# Provides the implementation for `be_between`.
|
6
|
+
# Not intended to be instantiated directly.
|
4
7
|
class BeBetween < BaseMatcher
|
5
8
|
def initialize(min, max)
|
6
9
|
@min, @max = min, max
|
7
10
|
inclusive
|
8
11
|
end
|
9
12
|
|
13
|
+
# @api public
|
14
|
+
# Makes the between comparison inclusive.
|
15
|
+
#
|
16
|
+
# @example
|
17
|
+
# expect(3).to be_between(2, 3).inclusive
|
18
|
+
#
|
19
|
+
# @note The matcher is inclusive by default; this simply provides
|
20
|
+
# a way to be more explicit about it.
|
10
21
|
def inclusive
|
11
22
|
@less_than_operator = :<=
|
12
23
|
@greater_than_operator = :>=
|
@@ -14,6 +25,11 @@ module RSpec
|
|
14
25
|
self
|
15
26
|
end
|
16
27
|
|
28
|
+
# @api public
|
29
|
+
# Makes the between comparison exclusive.
|
30
|
+
#
|
31
|
+
# @example
|
32
|
+
# expect(3).to be_between(2, 4).exclusive
|
17
33
|
def exclusive
|
18
34
|
@less_than_operator = :<
|
19
35
|
@greater_than_operator = :>
|
@@ -21,6 +37,8 @@ module RSpec
|
|
21
37
|
self
|
22
38
|
end
|
23
39
|
|
40
|
+
# @api private
|
41
|
+
# @return [Boolean]
|
24
42
|
def matches?(actual)
|
25
43
|
@actual = actual
|
26
44
|
comparable? && compare
|
@@ -28,10 +46,14 @@ module RSpec
|
|
28
46
|
false
|
29
47
|
end
|
30
48
|
|
49
|
+
# @api private
|
50
|
+
# @return [String]
|
31
51
|
def failure_message
|
32
52
|
"#{super}#{not_comparable_clause}"
|
33
53
|
end
|
34
54
|
|
55
|
+
# @api private
|
56
|
+
# @return [String]
|
35
57
|
def description
|
36
58
|
"be between #{@min.inspect} and #{@max.inspect} (#{@mode})"
|
37
59
|
end
|
@@ -1,14 +1,22 @@
|
|
1
1
|
module RSpec
|
2
2
|
module Matchers
|
3
3
|
module BuiltIn
|
4
|
+
# @api private
|
5
|
+
# Provides the implementation for `be_an_instance_of`.
|
6
|
+
# Not intended to be instantiated directly.
|
4
7
|
class BeAnInstanceOf < BaseMatcher
|
5
|
-
def match(expected, actual)
|
6
|
-
actual.instance_of? expected
|
7
|
-
end
|
8
8
|
|
9
|
+
# @api private
|
10
|
+
# @return [String]
|
9
11
|
def description
|
10
12
|
"be an instance of #{expected}"
|
11
13
|
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def match(expected, actual)
|
18
|
+
actual.instance_of? expected
|
19
|
+
end
|
12
20
|
end
|
13
21
|
end
|
14
22
|
end
|
@@ -1,7 +1,12 @@
|
|
1
1
|
module RSpec
|
2
2
|
module Matchers
|
3
3
|
module BuiltIn
|
4
|
+
# @api private
|
5
|
+
# Provides the implementation for `be_a_kind_of`.
|
6
|
+
# Not intended to be instantiated directly.
|
4
7
|
class BeAKindOf < BaseMatcher
|
8
|
+
|
9
|
+
private
|
5
10
|
def match(expected, actual)
|
6
11
|
actual.kind_of? expected
|
7
12
|
end
|
@@ -1,6 +1,9 @@
|
|
1
1
|
module RSpec
|
2
2
|
module Matchers
|
3
3
|
module BuiltIn
|
4
|
+
# @api private
|
5
|
+
# Provides the implementation for `be_within`.
|
6
|
+
# Not intended to be instantiated directly.
|
4
7
|
class BeWithin
|
5
8
|
include Composable
|
6
9
|
|
@@ -8,12 +11,8 @@ module RSpec
|
|
8
11
|
@delta = delta
|
9
12
|
end
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
raise needs_expected unless defined? @expected
|
14
|
-
numeric? && (@actual - @expected).abs <= @tolerance
|
15
|
-
end
|
16
|
-
|
14
|
+
# @api public
|
15
|
+
# Sets the expected value.
|
17
16
|
def of(expected)
|
18
17
|
@expected = expected
|
19
18
|
@tolerance = @delta
|
@@ -21,6 +20,9 @@ module RSpec
|
|
21
20
|
self
|
22
21
|
end
|
23
22
|
|
23
|
+
# @api public
|
24
|
+
# Sets the expected value, and makes the matcher do
|
25
|
+
# a percent comparison.
|
24
26
|
def percent_of(expected)
|
25
27
|
@expected = expected
|
26
28
|
@tolerance = @delta * @expected.abs / 100.0
|
@@ -28,18 +30,36 @@ module RSpec
|
|
28
30
|
self
|
29
31
|
end
|
30
32
|
|
33
|
+
# @private
|
34
|
+
def matches?(actual)
|
35
|
+
@actual = actual
|
36
|
+
raise needs_expected unless defined? @expected
|
37
|
+
numeric? && (@actual - @expected).abs <= @tolerance
|
38
|
+
end
|
39
|
+
|
40
|
+
# @api private
|
41
|
+
# @return [String]
|
31
42
|
def failure_message
|
32
43
|
"expected #{@actual.inspect} to #{description}#{not_numeric_clause}"
|
33
44
|
end
|
34
45
|
|
46
|
+
# @api private
|
47
|
+
# @return [String]
|
35
48
|
def failure_message_when_negated
|
36
49
|
"expected #{@actual.inspect} not to #{description}"
|
37
50
|
end
|
38
51
|
|
52
|
+
# @api private
|
53
|
+
# @return [String]
|
39
54
|
def description
|
40
55
|
"be within #{@delta}#{@unit} of #{@expected}"
|
41
56
|
end
|
42
57
|
|
58
|
+
# @private
|
59
|
+
def supports_block_expectations?
|
60
|
+
false
|
61
|
+
end
|
62
|
+
|
43
63
|
private
|
44
64
|
|
45
65
|
def numeric?
|
@@ -1,10 +1,13 @@
|
|
1
1
|
module RSpec
|
2
2
|
module Matchers
|
3
3
|
module BuiltIn
|
4
|
-
#
|
4
|
+
# @api private
|
5
|
+
# Provides the implementation for `change`.
|
6
|
+
# Not intended to be instantiated directly.
|
5
7
|
class Change
|
6
8
|
include Composable
|
7
9
|
|
10
|
+
# @api public
|
8
11
|
# Specifies the delta of the expected change.
|
9
12
|
def by(expected_delta)
|
10
13
|
ChangeRelatively.new(@change_details, expected_delta, :by) do |actual_delta|
|
@@ -12,6 +15,7 @@ module RSpec
|
|
12
15
|
end
|
13
16
|
end
|
14
17
|
|
18
|
+
# @api public
|
15
19
|
# Specifies a minimum delta of the expected change.
|
16
20
|
def by_at_least(minimum)
|
17
21
|
ChangeRelatively.new(@change_details, minimum, :by_at_least) do |actual_delta|
|
@@ -19,6 +23,7 @@ module RSpec
|
|
19
23
|
end
|
20
24
|
end
|
21
25
|
|
26
|
+
# @api public
|
22
27
|
# Specifies a maximum delta of the expected change.
|
23
28
|
def by_at_most(maximum)
|
24
29
|
ChangeRelatively.new(@change_details, maximum, :by_at_most) do |actual_delta|
|
@@ -26,38 +31,55 @@ module RSpec
|
|
26
31
|
end
|
27
32
|
end
|
28
33
|
|
34
|
+
# @api public
|
29
35
|
# Specifies the new value you expect.
|
30
36
|
def to(value)
|
31
37
|
ChangeToValue.new(@change_details, value)
|
32
38
|
end
|
33
39
|
|
40
|
+
# @api public
|
34
41
|
# Specifies the original value.
|
35
42
|
def from(value)
|
36
43
|
ChangeFromValue.new(@change_details, value)
|
37
44
|
end
|
38
45
|
|
39
|
-
# @
|
46
|
+
# @private
|
40
47
|
def matches?(event_proc)
|
48
|
+
@event_proc = event_proc
|
49
|
+
return false unless Proc === event_proc
|
41
50
|
raise_block_syntax_error if block_given?
|
42
51
|
@change_details.perform_change(event_proc)
|
43
52
|
@change_details.changed?
|
44
53
|
end
|
45
54
|
|
55
|
+
def does_not_match?(event_proc)
|
56
|
+
raise_block_syntax_error if block_given?
|
57
|
+
!matches?(event_proc) && Proc === event_proc
|
58
|
+
end
|
59
|
+
|
46
60
|
# @api private
|
61
|
+
# @return [String]
|
47
62
|
def failure_message
|
48
|
-
"expected #{@change_details.message} to have changed, but
|
63
|
+
"expected #{@change_details.message} to have changed, but #{positive_failure_reason}"
|
49
64
|
end
|
50
65
|
|
51
66
|
# @api private
|
67
|
+
# @return [String]
|
52
68
|
def failure_message_when_negated
|
53
|
-
"expected #{@change_details.message} not to have changed, but
|
69
|
+
"expected #{@change_details.message} not to have changed, but #{negative_failure_reason}"
|
54
70
|
end
|
55
71
|
|
56
72
|
# @api private
|
73
|
+
# @return [String]
|
57
74
|
def description
|
58
75
|
"change #{@change_details.message}"
|
59
76
|
end
|
60
77
|
|
78
|
+
# @private
|
79
|
+
def supports_block_expectations?
|
80
|
+
true
|
81
|
+
end
|
82
|
+
|
61
83
|
private
|
62
84
|
|
63
85
|
def initialize(receiver=nil, message=nil, &block)
|
@@ -68,6 +90,16 @@ module RSpec
|
|
68
90
|
raise SyntaxError,
|
69
91
|
"The block passed to the `change` matcher must use `{ ... }` instead of do/end"
|
70
92
|
end
|
93
|
+
|
94
|
+
def positive_failure_reason
|
95
|
+
return "was not given a block" unless Proc === @event_proc
|
96
|
+
"is still #{description_of @change_details.actual_before}"
|
97
|
+
end
|
98
|
+
|
99
|
+
def negative_failure_reason
|
100
|
+
return "was not given a block" unless Proc === @event_proc
|
101
|
+
"did change from #{description_of @change_details.actual_before} to #{description_of @change_details.actual_after}"
|
102
|
+
end
|
71
103
|
end
|
72
104
|
|
73
105
|
# Used to specify a relative change.
|
@@ -82,30 +114,47 @@ module RSpec
|
|
82
114
|
@comparer = comparer
|
83
115
|
end
|
84
116
|
|
117
|
+
# @private
|
85
118
|
def failure_message
|
86
|
-
"expected #{@change_details.message} to have changed #{@relativity.to_s.gsub("_", " ")} #{description_of @expected_delta}, "
|
87
|
-
"but was changed by #{description_of @change_details.actual_delta}"
|
119
|
+
"expected #{@change_details.message} to have changed #{@relativity.to_s.gsub("_", " ")} #{description_of @expected_delta}, but #{failure_reason}"
|
88
120
|
end
|
89
121
|
|
122
|
+
# @private
|
90
123
|
def matches?(event_proc)
|
124
|
+
@event_proc = event_proc
|
125
|
+
return false unless Proc === event_proc
|
91
126
|
@change_details.perform_change(event_proc)
|
92
127
|
@comparer.call(@change_details.actual_delta)
|
93
128
|
end
|
94
129
|
|
130
|
+
# @private
|
95
131
|
def does_not_match?(event_proc)
|
96
132
|
raise NotImplementedError, "`expect { }.not_to change { }.#{@relativity}()` is not supported"
|
97
133
|
end
|
98
134
|
|
99
|
-
# @
|
135
|
+
# @private
|
100
136
|
def description
|
101
137
|
"change #{@change_details.message} #{@relativity.to_s.gsub("_", " ")} #{description_of @expected_delta}"
|
102
138
|
end
|
139
|
+
|
140
|
+
# @private
|
141
|
+
def supports_block_expectations?
|
142
|
+
true
|
143
|
+
end
|
144
|
+
|
145
|
+
private
|
146
|
+
|
147
|
+
def failure_reason
|
148
|
+
return "was not given a block" unless Proc === @event_proc
|
149
|
+
"was changed by #{description_of @change_details.actual_delta}"
|
150
|
+
end
|
103
151
|
end
|
104
152
|
|
105
|
-
# Base class for specifying a change from and/or to specific values.
|
106
153
|
# @api private
|
154
|
+
# Base class for specifying a change from and/or to specific values.
|
107
155
|
class SpecificValuesChange
|
108
156
|
include Composable
|
157
|
+
# @private
|
109
158
|
MATCH_ANYTHING = ::Object.ancestors.last
|
110
159
|
|
111
160
|
def initialize(change_details, from, to)
|
@@ -114,21 +163,32 @@ module RSpec
|
|
114
163
|
@expected_after = to
|
115
164
|
end
|
116
165
|
|
166
|
+
# @private
|
117
167
|
def matches?(event_proc)
|
168
|
+
@event_proc = event_proc
|
169
|
+
return false unless Proc === event_proc
|
118
170
|
@change_details.perform_change(event_proc)
|
119
171
|
@change_details.changed? && matches_before? && matches_after?
|
120
172
|
end
|
121
173
|
|
174
|
+
# @private
|
122
175
|
def description
|
123
176
|
"change #{@change_details.message} #{change_description}"
|
124
177
|
end
|
125
178
|
|
179
|
+
# @private
|
126
180
|
def failure_message
|
127
|
-
return
|
128
|
-
return
|
181
|
+
return not_given_a_block_failure unless Proc === @event_proc
|
182
|
+
return before_value_failure unless matches_before?
|
183
|
+
return did_not_change_failure unless @change_details.changed?
|
129
184
|
after_value_failure
|
130
185
|
end
|
131
186
|
|
187
|
+
# @private
|
188
|
+
def supports_block_expectations?
|
189
|
+
true
|
190
|
+
end
|
191
|
+
|
132
192
|
private
|
133
193
|
|
134
194
|
def matches_before?
|
@@ -154,33 +214,44 @@ module RSpec
|
|
154
214
|
def did_change_failure
|
155
215
|
"expected #{@change_details.message} not to have changed, but did change from #{description_of @change_details.actual_before} to #{description_of @change_details.actual_after}"
|
156
216
|
end
|
217
|
+
|
218
|
+
def not_given_a_block_failure
|
219
|
+
"expected #{@change_details.message} to have changed #{change_description}, but was not given a block"
|
220
|
+
end
|
157
221
|
end
|
158
222
|
|
223
|
+
# @api private
|
159
224
|
# Used to specify a change from a specific value
|
160
225
|
# (and, optionally, to a specific value).
|
161
|
-
# @api private
|
162
226
|
class ChangeFromValue < SpecificValuesChange
|
163
227
|
def initialize(change_details, expected_before)
|
164
228
|
@description_suffix = nil
|
165
229
|
super(change_details, expected_before, MATCH_ANYTHING)
|
166
230
|
end
|
167
231
|
|
232
|
+
# @api public
|
233
|
+
# Specifies the new value you expect.
|
168
234
|
def to(value)
|
169
235
|
@expected_after = value
|
170
236
|
@description_suffix = " to #{description_of value}"
|
171
237
|
self
|
172
238
|
end
|
173
239
|
|
240
|
+
# @private
|
174
241
|
def does_not_match?(event_proc)
|
175
242
|
if @description_suffix
|
176
243
|
raise NotImplementedError, "`expect { }.not_to change { }.to()` is not supported"
|
177
244
|
end
|
178
245
|
|
246
|
+
@event_proc = event_proc
|
247
|
+
return false unless Proc === event_proc
|
179
248
|
@change_details.perform_change(event_proc)
|
180
249
|
!@change_details.changed? && matches_before?
|
181
250
|
end
|
182
251
|
|
252
|
+
# @private
|
183
253
|
def failure_message_when_negated
|
254
|
+
return not_given_a_block_failure unless Proc === @event_proc
|
184
255
|
return before_value_failure unless matches_before?
|
185
256
|
did_change_failure
|
186
257
|
end
|
@@ -192,21 +263,24 @@ module RSpec
|
|
192
263
|
end
|
193
264
|
end
|
194
265
|
|
266
|
+
# @api private
|
195
267
|
# Used to specify a change to a specific value
|
196
268
|
# (and, optionally, from a specific value).
|
197
|
-
# @api private
|
198
269
|
class ChangeToValue < SpecificValuesChange
|
199
270
|
def initialize(change_details, expected_after)
|
200
271
|
@description_suffix = nil
|
201
272
|
super(change_details, MATCH_ANYTHING, expected_after)
|
202
273
|
end
|
203
274
|
|
275
|
+
# @api public
|
276
|
+
# Specifies the original value.
|
204
277
|
def from(value)
|
205
278
|
@expected_before = value
|
206
279
|
@description_suffix = " from #{description_of value}"
|
207
280
|
self
|
208
281
|
end
|
209
282
|
|
283
|
+
# @private
|
210
284
|
def does_not_match?(event_proc)
|
211
285
|
raise NotImplementedError, "`expect { }.not_to change { }.to()` is not supported"
|
212
286
|
end
|
@@ -218,8 +292,8 @@ module RSpec
|
|
218
292
|
end
|
219
293
|
end
|
220
294
|
|
295
|
+
# @private
|
221
296
|
# Encapsulates the details of the before/after values.
|
222
|
-
# @api private
|
223
297
|
class ChangeDetails
|
224
298
|
attr_reader :message, :actual_before, :actual_after
|
225
299
|
|
@@ -246,6 +320,8 @@ module RSpec
|
|
246
320
|
|
247
321
|
def evaluate_value_proc
|
248
322
|
case val = @value_proc.call
|
323
|
+
when IO # enumerable, but we don't want to dup it.
|
324
|
+
val
|
249
325
|
when Enumerable, String
|
250
326
|
val.dup
|
251
327
|
else
|
@@ -1,9 +1,10 @@
|
|
1
1
|
module RSpec
|
2
2
|
module Matchers
|
3
3
|
module BuiltIn
|
4
|
-
# Base class for `and` and `or` compound matchers.
|
5
4
|
# @api private
|
5
|
+
# Base class for `and` and `or` compound matchers.
|
6
6
|
class Compound < BaseMatcher
|
7
|
+
# @private
|
7
8
|
attr_reader :matcher_1, :matcher_2
|
8
9
|
|
9
10
|
def initialize(matcher_1, matcher_2)
|
@@ -11,17 +12,26 @@ module RSpec
|
|
11
12
|
@matcher_2 = matcher_2
|
12
13
|
end
|
13
14
|
|
15
|
+
# @private
|
14
16
|
def does_not_match?(actual)
|
15
17
|
raise NotImplementedError,
|
16
18
|
"`expect(...).not_to matcher.#{conjunction} matcher` is not supported"
|
17
19
|
end
|
18
20
|
|
21
|
+
# @api private
|
22
|
+
# @return [String]
|
19
23
|
def description
|
20
24
|
singleline_message(matcher_1.description, matcher_2.description)
|
21
25
|
end
|
22
26
|
|
23
27
|
private
|
24
28
|
|
29
|
+
def initialize_copy(other)
|
30
|
+
@matcher_1 = @matcher_1.clone
|
31
|
+
@matcher_2 = @matcher_2.clone
|
32
|
+
super
|
33
|
+
end
|
34
|
+
|
25
35
|
def indent_multiline_message(message)
|
26
36
|
message.lines.map do |line|
|
27
37
|
line =~ /\S/ ? ' ' + line : line
|
@@ -55,9 +65,12 @@ module RSpec
|
|
55
65
|
[message_1, conjunction, message_2].join(' ')
|
56
66
|
end
|
57
67
|
|
58
|
-
# Matcher used to represent a compound `and` expectation.
|
59
68
|
# @api public
|
69
|
+
# Matcher used to represent a compound `and` expectation.
|
60
70
|
class And < self
|
71
|
+
|
72
|
+
# @api private
|
73
|
+
# @return [String]
|
61
74
|
def failure_message
|
62
75
|
if @matcher_1_matches
|
63
76
|
matcher_2.failure_message
|
@@ -82,9 +95,12 @@ module RSpec
|
|
82
95
|
end
|
83
96
|
end
|
84
97
|
|
85
|
-
# Matcher used to represent a compound `or` expectation.
|
86
98
|
# @api public
|
99
|
+
# Matcher used to represent a compound `or` expectation.
|
87
100
|
class Or < self
|
101
|
+
|
102
|
+
# @api private
|
103
|
+
# @return [String]
|
88
104
|
def failure_message
|
89
105
|
compound_failure_message
|
90
106
|
end
|