rspec-sleeping_king_studios 1.0.1 → 2.0.0.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +27 -1
- data/README.md +24 -29
- data/lib/rspec/sleeping_king_studios/matchers/active_model/have_errors.rb +6 -6
- data/lib/rspec/sleeping_king_studios/matchers/base_matcher.rb +11 -8
- data/lib/rspec/sleeping_king_studios/matchers/built_in/be_kind_of.rb +6 -6
- data/lib/rspec/sleeping_king_studios/matchers/built_in/include.rb +34 -45
- data/lib/rspec/sleeping_king_studios/matchers/built_in/respond_to.rb +12 -36
- data/lib/rspec/sleeping_king_studios/matchers/core/be_boolean.rb +6 -6
- data/lib/rspec/sleeping_king_studios/matchers/core/construct.rb +6 -6
- data/lib/rspec/sleeping_king_studios/matchers/core/have_property.rb +6 -7
- data/lib/rspec/sleeping_king_studios/matchers/core/have_reader.rb +6 -7
- data/lib/rspec/sleeping_king_studios/matchers/core/have_writer.rb +6 -7
- data/lib/rspec/sleeping_king_studios/matchers/meta/fail_with_actual.rb +28 -63
- data/lib/rspec/sleeping_king_studios/matchers/meta/pass_with_actual.rb +14 -15
- data/lib/rspec/sleeping_king_studios/version.rb +1 -1
- data/lib/rspec/sleeping_king_studios.rb +0 -2
- metadata +7 -21
- data/lib/rspec/sleeping_king_studios/mocks/custom_double.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cbf466af0152a14ef3bc8c347801fde6920ed6e9
|
4
|
+
data.tar.gz: 376e2f08164ead08c9c45b40dbb905059b3604c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb509c9eadc232566f2e7cd186ae526f3985c22afc507a3f4773236155ed9e173e0858b1125186831897fa75571d7c477d87e91a07052e6c30390cf9f30faa60
|
7
|
+
data.tar.gz: bf36d933af302a1f19266b148631c7c023ae855433bfa3e888e88f11287048bac924e221cb2e30c0d0ea7ce2e340098611e4b3b80e1365747cf67ea00e86c052
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,30 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 2.0.0.alpha
|
4
|
+
|
5
|
+
Update the entire library to support RSpec 3. Most of the updates are purely
|
6
|
+
internal, but there are a few changes that are not backward compatible to be
|
7
|
+
aware of.
|
8
|
+
|
9
|
+
### Matchers
|
10
|
+
|
11
|
+
All matchers have been updated to support the RSpec 3 matcher API.
|
12
|
+
|
13
|
+
#### fail_with_actual Matcher
|
14
|
+
|
15
|
+
Now correctly handles the #does_not_match? case for the new matcher API.
|
16
|
+
|
17
|
+
#### respond\_to Matcher
|
18
|
+
|
19
|
+
The #and fluent method has been removed, and the #a_block method for verifying
|
20
|
+
the presence of a block argument has been renamed to #with_a_block.
|
21
|
+
|
22
|
+
### Mocks
|
23
|
+
|
24
|
+
The #custom_double mock method has been completely removed. The recommended
|
25
|
+
solution for that use case is `double('My Double').extend(MyModule)`, for some
|
26
|
+
`MyModule` that implements the desired actual (non-stubbed) functionality.
|
27
|
+
|
3
28
|
## 1.0.1
|
4
29
|
|
5
30
|
### New Features
|
@@ -8,7 +33,8 @@
|
|
8
33
|
arguments, of the form def foo(bar:, baz:). If the class constructor or
|
9
34
|
method requires one or more keyword arguments, and one or more of those
|
10
35
|
keywords are not provided when checking arguments using the #with
|
11
|
-
method, the matcher will fail with the message "missing keywords" and a list
|
36
|
+
method, the matcher will fail with the message "missing keywords" and a list
|
37
|
+
of the keywords that were not provided as arguments to #with.
|
12
38
|
|
13
39
|
## 1.0.0
|
14
40
|
|
data/README.md
CHANGED
@@ -10,32 +10,27 @@ Currently, the following versions of Ruby are officially supported:
|
|
10
10
|
* 2.0.0
|
11
11
|
* 2.1.0
|
12
12
|
|
13
|
-
##
|
13
|
+
## Contribute
|
14
14
|
|
15
|
-
|
15
|
+
- https://github.com/sleepingkingstudios/rspec-sleeping_king_studios
|
16
16
|
|
17
|
-
###
|
17
|
+
### A Note From The Developer
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
As the built-in 'double' method, but accepts a block that is passed to
|
26
|
-
Class.new when the double is created, allowing you to create functional class
|
27
|
-
and instance methods on the double. Useful when you need to test a function or
|
28
|
-
sequence that repeatedly updates or checks the state of the injected object.
|
29
|
-
|
30
|
-
**How To Use:**
|
31
|
-
|
32
|
-
custom_double('My Double', :foo => "Foo") { attr_accessor :bar }
|
19
|
+
Hi, I'm Rob Smith, the maintainer of this library. As a professional Ruby
|
20
|
+
developer, I use these tools every day. If you find this project helpful in
|
21
|
+
your own work, or if you have any questions, suggestions or critiques, please
|
22
|
+
feel free to get in touch! I can be reached on GitHub (see above, and feel
|
23
|
+
encouraged to submit bug reports or merge requests there) or via email at
|
24
|
+
merlin@sleepingkingstudios.com. I look forward to hearing from you!
|
33
25
|
|
34
26
|
## The Matchers
|
35
27
|
|
36
28
|
To enable a custom matcher, simply require the associated file. Matchers can be
|
37
29
|
required individually or by category:
|
38
30
|
|
31
|
+
require 'rspec/sleeping_king_studios'
|
32
|
+
#=> requires all features, including matchers
|
33
|
+
|
39
34
|
require 'rspec/sleeping_king_studios/matchers/core'
|
40
35
|
#=> requires all of the core matchers
|
41
36
|
|
@@ -111,19 +106,19 @@ accepted by the method, and whether the method accepts a block argument.
|
|
111
106
|
|
112
107
|
**How To Use:**
|
113
108
|
|
114
|
-
expect(instance).to respond_to(:foo).with(2..3).arguments.
|
109
|
+
expect(instance).to respond_to(:foo).with(2..3).arguments.with_a_block
|
115
110
|
|
116
111
|
**Chaining:**
|
117
112
|
|
118
|
-
* **a\_block:** No parameters. Verifies that the method requires a block
|
119
|
-
argument of the form &my_argument. _Important note:_ A negative result does
|
120
|
-
_not* mean the method cannot accept a block, merely that it does not require
|
121
|
-
one. Also, does _not_ check whether the block is called or yielded.
|
122
113
|
* **with:** Expects one Integer or Range argument. If an Integer, verifies that
|
123
114
|
the method accepts that number of arguments; if a Range, verifies that the
|
124
115
|
method accepts both the minimum and maximum number of arguments.
|
116
|
+
* **with\_a\_block:** No parameters. Verifies that the method requires a block
|
117
|
+
argument of the form &my_argument. _Important note:_ A negative result does
|
118
|
+
_not* mean the method cannot accept a block, merely that it does not require
|
119
|
+
one. Also, does _not_ check whether the block is called or yielded.
|
125
120
|
|
126
|
-
##### Ruby 2.0
|
121
|
+
##### Ruby 2.0+
|
127
122
|
|
128
123
|
Has additional functionality to support Ruby 2.0 keyword arguments.
|
129
124
|
|
@@ -177,7 +172,7 @@ optional number of arguments.
|
|
177
172
|
verifies that the constructor accepts both the minimum and maximum number of
|
178
173
|
arguments.
|
179
174
|
|
180
|
-
##### Ruby 2.0
|
175
|
+
##### Ruby 2.0+
|
181
176
|
|
182
177
|
Has additional functionality to support Ruby 2.0 keyword arguments.
|
183
178
|
|
@@ -289,12 +284,12 @@ pass\_with\_actual matcher, below.
|
|
289
284
|
expect(matcher).to fail_with_actual(actual).with_message(/expected to/)
|
290
285
|
|
291
286
|
**Parameters:** Matcher. Expects an object that, at minimum, responds to
|
292
|
-
:matches? and :failure\_message
|
287
|
+
:matches? and :failure\_message.
|
293
288
|
|
294
289
|
**Chaining:**
|
295
290
|
|
296
291
|
* **with\_message:** Expects one String or Regexp argument, which is matched
|
297
|
-
against the given matcher's failure\_message
|
292
|
+
against the given matcher's failure\_message.
|
298
293
|
|
299
294
|
#### pass\_with\_actual Matcher
|
300
295
|
|
@@ -309,15 +304,15 @@ fail\_with\_actual matcher, above.
|
|
309
304
|
|
310
305
|
**How To Use:**
|
311
306
|
|
312
|
-
expect(matcher).to pass_with_actual(actual)
|
307
|
+
expect(matcher).to pass_with_actual(actual).with_message(/expected not to/)
|
313
308
|
|
314
309
|
**Parameters:** Matcher. Expects an object that, at minimum, responds to
|
315
|
-
:matches? and :failure\_message\
|
310
|
+
:matches? and :failure\_message\_when\_negated.
|
316
311
|
|
317
312
|
**Chaining:**
|
318
313
|
|
319
314
|
* **with\_message:** Expects one String or Regexp argument, which is matched
|
320
|
-
against the given matcher's failure\_message\
|
315
|
+
against the given matcher's failure\_message\_when\_negated.
|
321
316
|
|
322
317
|
## License
|
323
318
|
|
@@ -89,8 +89,8 @@ module RSpec::SleepingKingStudios::Matchers::ActiveModel
|
|
89
89
|
self
|
90
90
|
end # method with_message
|
91
91
|
|
92
|
-
# @see BaseMatcher#
|
93
|
-
def
|
92
|
+
# @see BaseMatcher#failure_message
|
93
|
+
def failure_message
|
94
94
|
# Failure cases:
|
95
95
|
# * object is not a model ("to respond to valid")
|
96
96
|
# * expected one or more errors, but received none ("to have errors")
|
@@ -104,10 +104,10 @@ module RSpec::SleepingKingStudios::Matchers::ActiveModel
|
|
104
104
|
else
|
105
105
|
"expected #{@actual.inspect} to have errors#{expected_errors_message}#{received_errors_message}"
|
106
106
|
end # if-elsif-else
|
107
|
-
end # method
|
107
|
+
end # method failure_message
|
108
108
|
|
109
|
-
# @see BaseMatcher#
|
110
|
-
def
|
109
|
+
# @see BaseMatcher#failure_message_when_negated
|
110
|
+
def failure_message_when_negated
|
111
111
|
# Failure cases:
|
112
112
|
# * expected one or more errors, received one or more ("not to have
|
113
113
|
# errors")
|
@@ -121,7 +121,7 @@ module RSpec::SleepingKingStudios::Matchers::ActiveModel
|
|
121
121
|
else
|
122
122
|
return "expected #{@actual.inspect} not to have errors#{expected_errors_message}#{received_errors_message}"
|
123
123
|
end # if-else
|
124
|
-
end # method
|
124
|
+
end # method failure_message_when_negated
|
125
125
|
|
126
126
|
private
|
127
127
|
|
@@ -7,14 +7,17 @@ module RSpec::SleepingKingStudios::Matchers
|
|
7
7
|
#
|
8
8
|
# @since 1.0.0
|
9
9
|
class BaseMatcher
|
10
|
-
|
11
|
-
end # constructor
|
10
|
+
include RSpec::Matchers::Pretty
|
12
11
|
|
13
|
-
|
12
|
+
attr_reader :actual
|
13
|
+
|
14
|
+
# A short string that describes the purpose of the matcher. Borrowed from
|
15
|
+
# RSpec::Matchers::BuiltIn::BaseMatcher.
|
14
16
|
#
|
15
17
|
# @return [String] the matcher description
|
16
18
|
def description
|
17
|
-
|
19
|
+
return name_to_sentence unless defined?(@expected)
|
20
|
+
"#{name_to_sentence}#{to_sentence @expected}"
|
18
21
|
end # method description
|
19
22
|
|
20
23
|
# Tests the actual object to see if it matches the defined condition(s).
|
@@ -30,14 +33,14 @@ module RSpec::SleepingKingStudios::Matchers
|
|
30
33
|
|
31
34
|
# Message for when the object does not match, but was expected to. Make
|
32
35
|
# sure to always call #matches? first to set up the matcher state.
|
33
|
-
def
|
36
|
+
def failure_message
|
34
37
|
"expected #{@actual.inspect} to #{description}"
|
35
|
-
end # method
|
38
|
+
end # method failure_message
|
36
39
|
|
37
40
|
# Message for when the object matches, but was expected not to. Make sure
|
38
41
|
# to always call #matches? first to set up the matcher state.
|
39
|
-
def
|
42
|
+
def failure_message_when_negated
|
40
43
|
"expected #{@actual.inspect} not to #{description}"
|
41
|
-
end # method
|
44
|
+
end # method failure_message_when_negated
|
42
45
|
end # class
|
43
46
|
end # module
|
@@ -18,15 +18,15 @@ module RSpec::SleepingKingStudios::Matchers::BuiltIn
|
|
18
18
|
match_type? expected
|
19
19
|
end # method match
|
20
20
|
|
21
|
-
# @see BaseMatcher#
|
22
|
-
def
|
21
|
+
# @see BaseMatcher#failure_message
|
22
|
+
def failure_message
|
23
23
|
"expected #{@actual.inspect} to be #{type_string}"
|
24
|
-
end # method
|
24
|
+
end # method failure_message
|
25
25
|
|
26
|
-
# @see BaseMatcher#
|
27
|
-
def
|
26
|
+
# @see BaseMatcher#failure_message_when_negated
|
27
|
+
def failure_message_when_negated
|
28
28
|
"expected #{@actual.inspect} not to be #{type_string}"
|
29
|
-
end # method
|
29
|
+
end # method failure_message_when_negated
|
30
30
|
|
31
31
|
private
|
32
32
|
|
@@ -17,69 +17,58 @@ module RSpec::SleepingKingStudios::Matchers::BuiltIn
|
|
17
17
|
super *expected
|
18
18
|
end # constructor
|
19
19
|
|
20
|
-
# Checks if the object includes the specified objects. Proc expectations
|
21
|
-
# are evaluated by passing each item to proc#call.
|
22
|
-
#
|
23
|
-
# @param [Object] actual the object to check
|
24
|
-
#
|
25
|
-
# @return [Boolean] true if for each item expectation, the object contains
|
26
|
-
# an item matching that expectation; otherwise false
|
27
|
-
def matches? actual
|
28
|
-
super
|
29
|
-
end # method matches?
|
30
|
-
|
31
20
|
# @private
|
32
|
-
def
|
33
|
-
"include"
|
34
|
-
end # method name
|
35
|
-
|
36
|
-
# @private
|
37
|
-
def to_word item
|
21
|
+
def to_word expected_item
|
38
22
|
case
|
39
|
-
when is_matcher_with_description?(
|
40
|
-
|
41
|
-
when Proc ===
|
42
|
-
"matching block"
|
23
|
+
when is_matcher_with_description?(expected_item)
|
24
|
+
expected_item.description
|
25
|
+
when Proc === expected_item
|
26
|
+
"an item matching the block"
|
43
27
|
else
|
44
|
-
|
28
|
+
expected_item.inspect
|
45
29
|
end # case
|
46
30
|
end # method to_word
|
47
31
|
|
48
|
-
# @see BaseMatcher#
|
49
|
-
def
|
32
|
+
# @see BaseMatcher#failure_message
|
33
|
+
def failure_message
|
50
34
|
return "expected #{@actual.inspect} to respond to :include?" if false === @includes
|
51
35
|
|
52
36
|
super
|
53
37
|
end # method failure_message_for_should
|
54
38
|
|
55
|
-
# @see BaseMatcher#
|
56
|
-
def
|
39
|
+
# @see BaseMatcher#failure_message_when_negated
|
40
|
+
def failure_message_when_negated
|
57
41
|
super
|
58
42
|
end # method
|
59
43
|
|
60
44
|
private
|
61
45
|
|
62
|
-
def perform_match
|
63
|
-
|
64
|
-
if comparing_proc?
|
65
|
-
|
66
|
-
elsif
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
elsif comparing_hash_keys?(
|
71
|
-
|
72
|
-
elsif comparing_with_matcher?(actual, expected)
|
73
|
-
actual.any? { |value| expected.matches?(value) }
|
46
|
+
def perform_match(predicate, hash_subset_predicate)
|
47
|
+
expected.__send__(predicate) do |expected_item|
|
48
|
+
if comparing_proc?(expected_item)
|
49
|
+
actual_matches_proc?(expected_item)
|
50
|
+
elsif comparing_hash_to_a_subset?(expected_item)
|
51
|
+
expected_item.__send__(hash_subset_predicate) do |(key, value)|
|
52
|
+
actual_hash_includes?(key, value)
|
53
|
+
end
|
54
|
+
elsif comparing_hash_keys?(expected_item)
|
55
|
+
actual_hash_has_key?(expected_item)
|
74
56
|
else
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
57
|
+
actual_collection_includes?(expected_item)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def actual_collection_includes? expected_item
|
63
|
+
(@includes = actual.respond_to?(:include?)) && super
|
64
|
+
end # method actual_collection_includes?
|
65
|
+
|
66
|
+
def actual_matches_proc? expected_item
|
67
|
+
!!actual.detect(&expected_item)
|
68
|
+
end # method actual_matches_proc?
|
80
69
|
|
81
|
-
def comparing_proc?
|
82
|
-
|
70
|
+
def comparing_proc? expected_item
|
71
|
+
expected_item.is_a?(Proc)
|
83
72
|
end # method comparing_proc?
|
84
73
|
end # class
|
85
74
|
end # module
|
@@ -8,17 +8,6 @@ module RSpec::SleepingKingStudios::Matchers::BuiltIn
|
|
8
8
|
class RespondToMatcher < RSpec::Matchers::BuiltIn::RespondTo
|
9
9
|
include RSpec::SleepingKingStudios::Matchers::Shared::MatchParameters
|
10
10
|
|
11
|
-
# Checks if the object responds to the specified message. If so, checks the
|
12
|
-
# parameters against the expected parameters, if any.
|
13
|
-
#
|
14
|
-
# @param [Object] actual the object to check
|
15
|
-
#
|
16
|
-
# @return [Boolean] true if the object responds to the message and accepts
|
17
|
-
# the specified parameters; otherwise false
|
18
|
-
def matches? actual
|
19
|
-
super
|
20
|
-
end # method matches?
|
21
|
-
|
22
11
|
# @overload with count
|
23
12
|
# Adds a parameter count expectation.
|
24
13
|
#
|
@@ -53,30 +42,17 @@ module RSpec::SleepingKingStudios::Matchers::BuiltIn
|
|
53
42
|
# expectation if it expects a parameter of the form &block.
|
54
43
|
#
|
55
44
|
# @return [RespondToMatcher] self
|
56
|
-
def
|
45
|
+
def with_a_block
|
57
46
|
@expected_block = true
|
58
47
|
self
|
59
|
-
end # method
|
60
|
-
|
61
|
-
# Convenience method for more fluent specs. Does nothing and returns self.
|
62
|
-
#
|
63
|
-
# @return [RespondToMatcher] self
|
64
|
-
def arguments
|
65
|
-
self
|
66
|
-
end # method arguments
|
48
|
+
end # method with_a_block
|
67
49
|
|
68
|
-
#
|
69
|
-
|
70
|
-
# @return [RespondToMatcher] self
|
71
|
-
def and
|
72
|
-
self
|
73
|
-
end # method arguments
|
74
|
-
|
75
|
-
# @see BaseMatcher#failure_message_for_should
|
76
|
-
def failure_message_for_should
|
77
|
-
messages = []
|
50
|
+
# @see BaseMatcher#failure_message
|
51
|
+
def failure_message
|
78
52
|
@failing_method_names ||= []
|
79
|
-
@failing_method_names
|
53
|
+
methods, messages = @names - @failing_method_names, []
|
54
|
+
|
55
|
+
methods.map do |method|
|
80
56
|
message = "expected #{@actual.inspect} to respond to #{method.inspect}"
|
81
57
|
if @actual.respond_to?(method)
|
82
58
|
message << " with arguments:\n#{format_errors_for_method method}"
|
@@ -84,14 +60,14 @@ module RSpec::SleepingKingStudios::Matchers::BuiltIn
|
|
84
60
|
messages << message
|
85
61
|
end # method
|
86
62
|
messages.join "\n"
|
87
|
-
end # method
|
63
|
+
end # method failure_message
|
88
64
|
|
89
|
-
# @see BaseMatcher#
|
90
|
-
def
|
65
|
+
# @see BaseMatcher#failure_message_when_negated
|
66
|
+
def failure_message_when_negated
|
91
67
|
@failing_method_names ||= []
|
92
68
|
methods, messages = @names - @failing_method_names, []
|
93
69
|
|
94
|
-
|
70
|
+
methods.map do |method|
|
95
71
|
message = "expected #{@actual.inspect} not to respond to #{method.inspect}"
|
96
72
|
unless (formatted = format_expected_arguments).empty?
|
97
73
|
message << " with #{formatted}"
|
@@ -99,7 +75,7 @@ module RSpec::SleepingKingStudios::Matchers::BuiltIn
|
|
99
75
|
messages << message
|
100
76
|
end # method
|
101
77
|
messages.join "\n"
|
102
|
-
end # method
|
78
|
+
end # method failure_message_when_negated
|
103
79
|
|
104
80
|
private
|
105
81
|
|
@@ -19,15 +19,15 @@ module RSpec::SleepingKingStudios::Matchers::Core
|
|
19
19
|
true === actual || false === actual
|
20
20
|
end # method matches?
|
21
21
|
|
22
|
-
# @see BaseMatcher#
|
23
|
-
def
|
22
|
+
# @see BaseMatcher#failure_message
|
23
|
+
def failure_message
|
24
24
|
"expected #{@actual.inspect} to be true or false"
|
25
|
-
end # method
|
25
|
+
end # method failure_message
|
26
26
|
|
27
|
-
# @see BaseMatcher#
|
28
|
-
def
|
27
|
+
# @see BaseMatcher#failure_message_when_negated
|
28
|
+
def failure_message_when_negated
|
29
29
|
"expected #{@actual.inspect} not to be true or false"
|
30
|
-
end # method
|
30
|
+
end # method failure_message_when_negated
|
31
31
|
end # class
|
32
32
|
end # module
|
33
33
|
|
@@ -51,21 +51,21 @@ module RSpec::SleepingKingStudios::Matchers::Core
|
|
51
51
|
self
|
52
52
|
end # method arguments
|
53
53
|
|
54
|
-
# @see BaseMatcher#
|
55
|
-
def
|
54
|
+
# @see BaseMatcher#failure_message
|
55
|
+
def failure_message
|
56
56
|
message = "expected #{@actual.inspect} to construct"
|
57
57
|
message << " with arguments:\n#{format_errors}" if @actual.respond_to?(:new)
|
58
58
|
message
|
59
|
-
end # method
|
59
|
+
end # method failure_message
|
60
60
|
|
61
|
-
# @see BaseMatcher#
|
62
|
-
def
|
61
|
+
# @see BaseMatcher#failure_message_when_negated
|
62
|
+
def failure_message_when_negated
|
63
63
|
message = "expected #{@actual.inspect} not to construct"
|
64
64
|
unless (formatted = format_expected_arguments).empty?
|
65
65
|
message << " with #{formatted}"
|
66
66
|
end # unless
|
67
67
|
message
|
68
|
-
end # method
|
68
|
+
end # method failure_message_when_negated
|
69
69
|
|
70
70
|
private
|
71
71
|
|
@@ -13,7 +13,6 @@ module RSpec::SleepingKingStudios::Matchers::Core
|
|
13
13
|
# @param [String, Symbol] expected the property to check for on the actual
|
14
14
|
# object
|
15
15
|
def initialize expected
|
16
|
-
super
|
17
16
|
@expected = expected.intern
|
18
17
|
end # method initialize
|
19
18
|
|
@@ -54,8 +53,8 @@ module RSpec::SleepingKingStudios::Matchers::Core
|
|
54
53
|
self
|
55
54
|
end # method with
|
56
55
|
|
57
|
-
# @see BaseMatcher#
|
58
|
-
def
|
56
|
+
# @see BaseMatcher#failure_message
|
57
|
+
def failure_message
|
59
58
|
methods = []
|
60
59
|
methods << ":#{@expected}" unless @match_reader
|
61
60
|
methods << ":#{@expected}=" unless @match_writer
|
@@ -65,14 +64,14 @@ module RSpec::SleepingKingStudios::Matchers::Core
|
|
65
64
|
"unexpected value for #{@actual.inspect}\##{@expected}" +
|
66
65
|
"\n expected: #{@value.inspect}" +
|
67
66
|
"\n got: #{@actual.send(@expected).inspect}"
|
68
|
-
end #
|
67
|
+
end # failure_message
|
69
68
|
|
70
|
-
# @see BaseMatcher#
|
71
|
-
def
|
69
|
+
# @see BaseMatcher#failure_message_when_negated
|
70
|
+
def failure_message_when_negated
|
72
71
|
message = "expected #{@actual.inspect} not to respond to :#{@expected} or :#{@expected}="
|
73
72
|
message << " with value #{@value.inspect}" if @value_set
|
74
73
|
message
|
75
|
-
end #
|
74
|
+
end # failure_message_when_negated
|
76
75
|
end # class
|
77
76
|
end # module
|
78
77
|
|
@@ -12,7 +12,6 @@ module RSpec::SleepingKingStudios::Matchers::Core
|
|
12
12
|
# @param [String, Symbol] expected the property to check for on the actual
|
13
13
|
# object
|
14
14
|
def initialize expected
|
15
|
-
super
|
16
15
|
@expected = expected.intern
|
17
16
|
end # method initialize
|
18
17
|
|
@@ -48,8 +47,8 @@ module RSpec::SleepingKingStudios::Matchers::Core
|
|
48
47
|
self
|
49
48
|
end # method with
|
50
49
|
|
51
|
-
# @see BaseMatcher#
|
52
|
-
def
|
50
|
+
# @see BaseMatcher#failure_message
|
51
|
+
def failure_message
|
53
52
|
unless @match_reader
|
54
53
|
return "expected #{@actual} to respond to #{@expected.inspect}"
|
55
54
|
end # unless
|
@@ -57,14 +56,14 @@ module RSpec::SleepingKingStudios::Matchers::Core
|
|
57
56
|
"unexpected value for #{@actual}\##{@expected}\n" +
|
58
57
|
" expected: #{@value.inspect}\n" +
|
59
58
|
" got: #{@actual.send(@expected).inspect}"
|
60
|
-
end # method
|
59
|
+
end # method failure_message
|
61
60
|
|
62
|
-
# @see BaseMatcher#
|
63
|
-
def
|
61
|
+
# @see BaseMatcher#failure_message_when_negated
|
62
|
+
def failure_message_when_negated
|
64
63
|
message = "expected #{@actual} not to respond to #{@expected.inspect}"
|
65
64
|
message << " with value #{@value.inspect}" if @value_set
|
66
65
|
message
|
67
|
-
end # method
|
66
|
+
end # method failure_message
|
68
67
|
end # class
|
69
68
|
end # module
|
70
69
|
|
@@ -12,7 +12,6 @@ module RSpec::SleepingKingStudios::Matchers::Core
|
|
12
12
|
# @param [String, Symbol] expected the property to check for on the actual
|
13
13
|
# object
|
14
14
|
def initialize expected
|
15
|
-
super
|
16
15
|
@expected = expected.to_s.gsub(/=$/,'').intern
|
17
16
|
end # method initialize
|
18
17
|
|
@@ -70,8 +69,8 @@ module RSpec::SleepingKingStudios::Matchers::Core
|
|
70
69
|
self
|
71
70
|
end # method with
|
72
71
|
|
73
|
-
# @see BaseMatcher#
|
74
|
-
def
|
72
|
+
# @see BaseMatcher#failure_message
|
73
|
+
def failure_message
|
75
74
|
return "expected #{@actual.inspect} to respond to #{@expected.inspect}=" unless @match_writer
|
76
75
|
|
77
76
|
unless @actual.respond_to?(@expected) || @value_block.respond_to?(:call)
|
@@ -82,14 +81,14 @@ module RSpec::SleepingKingStudios::Matchers::Core
|
|
82
81
|
return "unexpected value for #{@actual.inspect}#foo=\n" +
|
83
82
|
" expected: #{@value.inspect}\n" +
|
84
83
|
" got: #{@actual_value.inspect}"
|
85
|
-
end # method
|
84
|
+
end # method failure_message
|
86
85
|
|
87
|
-
# @see BaseMatcher#
|
88
|
-
def
|
86
|
+
# @see BaseMatcher#failure_message_when_negated
|
87
|
+
def failure_message_when_negated
|
89
88
|
message = "expected #{@actual} not to respond to #{@expected.inspect}="
|
90
89
|
message << " with value #{@value.inspect}" if @value_set && @match_writer
|
91
90
|
message
|
92
|
-
end # method
|
91
|
+
end # method failure_message
|
93
92
|
end # class
|
94
93
|
end # module
|
95
94
|
|
@@ -18,34 +18,34 @@ module RSpec::SleepingKingStudios::Matchers::Meta
|
|
18
18
|
class FailWithActualMatcher < RSpec::SleepingKingStudios::Matchers::BaseMatcher
|
19
19
|
# @param [Object] expected the actual object to check the matcher against
|
20
20
|
def initialize expected
|
21
|
-
super
|
22
21
|
@expected = expected
|
23
22
|
end # method initialize
|
24
23
|
|
25
24
|
# Checks if the matcher evaluates to false with the expected object. If a
|
26
25
|
# message expectation is set, checks the value of
|
27
|
-
# #
|
26
|
+
# #failure_message against the expected message.
|
28
27
|
#
|
29
28
|
# @param [Object] actual the RSpec matcher to check; should respond to
|
30
|
-
# :matches? and :
|
29
|
+
# :matches? and :failure_message, as a minimum
|
31
30
|
#
|
32
31
|
# @return [Boolean] true if the matcher evaluates to false and the
|
33
|
-
# matcher's #
|
32
|
+
# matcher's #failure_message matches the expected message
|
34
33
|
# (if any); otherwise false
|
35
34
|
def matches? actual
|
36
35
|
super
|
37
|
-
|
36
|
+
|
37
|
+
return false if matches_actual?
|
38
38
|
|
39
39
|
if @message.is_a? Regexp
|
40
|
-
!!(@actual.
|
40
|
+
!!(@actual.failure_message =~ @message)
|
41
41
|
elsif @message
|
42
|
-
@actual.
|
42
|
+
@actual.failure_message == @message.to_s
|
43
43
|
else
|
44
44
|
true
|
45
45
|
end # if-elsif-else
|
46
46
|
end # method matches?
|
47
47
|
|
48
|
-
def
|
48
|
+
def failure_message
|
49
49
|
if @matches
|
50
50
|
"expected #{@actual} not to match #{@expected}"
|
51
51
|
else
|
@@ -54,15 +54,15 @@ module RSpec::SleepingKingStudios::Matchers::Meta
|
|
54
54
|
"expected message#{@message.is_a?(Regexp) ? " matching" : ""}:\n#{
|
55
55
|
message_text.lines.map { |line| "#{" " * 2}#{line}" }.join
|
56
56
|
}\nreceived message:\n#{
|
57
|
-
@actual.
|
57
|
+
@actual.failure_message.lines.map { |line| "#{" " * 2}#{line}" }.join
|
58
58
|
}"
|
59
59
|
end # if-else
|
60
|
-
end # method
|
60
|
+
end # method failure_message
|
61
61
|
|
62
|
-
# @see BaseMatcher#
|
63
|
-
def
|
62
|
+
# @see BaseMatcher#failure_message_when_negated
|
63
|
+
def failure_message_when_negated
|
64
64
|
"failure: testing positive condition with negative matcher\n~> use the :pass_with_actual matcher instead"
|
65
|
-
end # method
|
65
|
+
end # method failure_message_when_negated
|
66
66
|
|
67
67
|
# The expected failure message for should when the matcher is called via
|
68
68
|
# expect#to.
|
@@ -72,7 +72,7 @@ module RSpec::SleepingKingStudios::Matchers::Meta
|
|
72
72
|
attr_reader :message
|
73
73
|
|
74
74
|
# Sets up a message expectation. When the matcher is called with the
|
75
|
-
# provided actual object, the matcher's
|
75
|
+
# provided actual object, the matcher's failure_message
|
76
76
|
# message is compared to the provided message.
|
77
77
|
#
|
78
78
|
# @param [String, Regexp] message the message to compare
|
@@ -82,6 +82,20 @@ module RSpec::SleepingKingStudios::Matchers::Meta
|
|
82
82
|
@message = message
|
83
83
|
self
|
84
84
|
end # method with_message
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
# Handles the actual matching through #does_not_match? if the matcher
|
89
|
+
# supports that method, otherwise falls back to @matches?.
|
90
|
+
#
|
91
|
+
# @return [Boolean]
|
92
|
+
def matches_actual?
|
93
|
+
if @actual.respond_to?(:does_not_match?)
|
94
|
+
@matches = !@actual.does_not_match?(@expected)
|
95
|
+
else
|
96
|
+
@matches = @actual.matches?(@expected)
|
97
|
+
end # if-else
|
98
|
+
end # method matches_actual?
|
85
99
|
end # class
|
86
100
|
end # module
|
87
101
|
|
@@ -91,52 +105,3 @@ module RSpec::SleepingKingStudios::Matchers
|
|
91
105
|
Meta::FailWithActualMatcher.new expected
|
92
106
|
end # method fail_with_actual
|
93
107
|
end # module
|
94
|
-
|
95
|
-
=begin
|
96
|
-
RSpec::Matchers.define :fail_with_actual do |actual|
|
97
|
-
match do |matcher|
|
98
|
-
@matcher = matcher
|
99
|
-
@actual = actual
|
100
|
-
|
101
|
-
next false if @matches = @matcher.matches?(@actual)
|
102
|
-
|
103
|
-
text = @matcher.failure_message_for_should
|
104
|
-
if @message.is_a? Regexp
|
105
|
-
!!(text =~ @message)
|
106
|
-
elsif @message
|
107
|
-
text == @message.to_s
|
108
|
-
else
|
109
|
-
true
|
110
|
-
end # if-elsif-else
|
111
|
-
end # match
|
112
|
-
|
113
|
-
failure_message_for_should do
|
114
|
-
if @matches = @matcher.matches?(@actual)
|
115
|
-
"expected #{@matcher} not to match #{@actual}"
|
116
|
-
else
|
117
|
-
message_text = @message.is_a?(Regexp) ? @message.inspect : @message.to_s
|
118
|
-
|
119
|
-
"expected message#{@message.is_a?(Regexp) ? " matching" : ""}:\n#{
|
120
|
-
message_text.lines.map { |line| "#{" " * 2}#{line}" }.join
|
121
|
-
}\nreceived message:\n#{
|
122
|
-
@matcher.failure_message_for_should.lines.map { |line| "#{" " * 2}#{line}" }.join
|
123
|
-
}"
|
124
|
-
end # if-else
|
125
|
-
end # method failure_message_for_should
|
126
|
-
|
127
|
-
failure_message_for_should_not do
|
128
|
-
"failure: testing positive condition with negative matcher\n~> use the :pass_with_actual matcher instead"
|
129
|
-
end # method failure_message_for_should_not
|
130
|
-
|
131
|
-
def message
|
132
|
-
@message
|
133
|
-
end # reader message
|
134
|
-
|
135
|
-
# The text of the tested matcher's :failure_message_for_should, when the
|
136
|
-
# tested matcher correctly fails to match the actual object.
|
137
|
-
def with_message message
|
138
|
-
@message = message
|
139
|
-
self
|
140
|
-
end # method with_message
|
141
|
-
end # matcher pass
|
142
|
-
=end
|
@@ -18,54 +18,53 @@ module RSpec::SleepingKingStudios::Matchers::Meta
|
|
18
18
|
class PassWithActualMatcher < RSpec::SleepingKingStudios::Matchers::BaseMatcher
|
19
19
|
# @param [Object] expected the actual object to check the matcher against
|
20
20
|
def initialize expected
|
21
|
-
super
|
22
21
|
@expected = expected
|
23
22
|
end # method initialize
|
24
23
|
|
25
24
|
# Checks if the matcher evaluates to true with the expected object. If a
|
26
25
|
# message expectation is set, checks the value of
|
27
|
-
# #
|
26
|
+
# #failure_message_when_negated against the expected message.
|
28
27
|
#
|
29
28
|
# @param [Object] actual the RSpec matcher to check; should respond to
|
30
|
-
# :matches? and :
|
29
|
+
# :matches? and :failure_message_when_negated, as a minimum
|
31
30
|
#
|
32
31
|
# @return [Boolean] true if the matcher evaluates to true and the matcher's
|
33
|
-
# #
|
32
|
+
# #failure_message_when_negated matches the expected message (if any);
|
34
33
|
# otherwise false
|
35
34
|
def matches? actual
|
36
35
|
super
|
37
36
|
return false unless @matches = @actual.matches?(@expected)
|
38
37
|
|
39
38
|
if @message.is_a? Regexp
|
40
|
-
!!(@actual.
|
39
|
+
!!(@actual.failure_message_when_negated =~ @message)
|
41
40
|
elsif @message
|
42
|
-
@actual.
|
41
|
+
@actual.failure_message_when_negated == @message.to_s
|
43
42
|
else
|
44
43
|
true
|
45
44
|
end # if-elsif-else
|
46
45
|
end # method matches?
|
47
46
|
|
48
|
-
# @see BaseMatcher#
|
49
|
-
def
|
47
|
+
# @see BaseMatcher#failure_message_when_negated
|
48
|
+
def failure_message
|
50
49
|
if @matches
|
51
50
|
message_text = @message.is_a?(Regexp) ? @message.inspect : @message.to_s
|
52
51
|
|
53
52
|
"expected message#{@message.is_a?(Regexp) ? " matching" : ""}:\n#{
|
54
53
|
message_text.lines.map { |line| "#{" " * 2}#{line}" }.join
|
55
54
|
}\nreceived message:\n#{
|
56
|
-
@actual.
|
55
|
+
@actual.failure_message_when_negated.lines.map { |line| "#{" " * 2}#{line}" }.join
|
57
56
|
}"
|
58
57
|
else
|
59
|
-
failure_message = @actual.
|
58
|
+
failure_message = @actual.failure_message
|
60
59
|
failure_message = failure_message.lines.map { |line| "#{" " * 4}#{line}" }.join("\n")
|
61
60
|
"expected #{@actual} to match #{@expected}\n message:\n#{failure_message}"
|
62
61
|
end # if-else
|
63
|
-
end # method
|
62
|
+
end # method failure_message
|
64
63
|
|
65
|
-
# @see BaseMatcher#
|
66
|
-
def
|
64
|
+
# @see BaseMatcher#failure_message_when_negated
|
65
|
+
def failure_message_when_negated
|
67
66
|
"failure: testing negative condition with positive matcher\n~> use the :fail_with_actual matcher instead"
|
68
|
-
end # method
|
67
|
+
end # method failure_message_when_negated
|
69
68
|
|
70
69
|
# The expected failure message for should_not when the matcher is called
|
71
70
|
# via expect#not_to.
|
@@ -75,7 +74,7 @@ module RSpec::SleepingKingStudios::Matchers::Meta
|
|
75
74
|
attr_reader :message
|
76
75
|
|
77
76
|
# Sets up a message expectation. When the matcher is called with the
|
78
|
-
# provided actual object, the matcher's
|
77
|
+
# provided actual object, the matcher's failure_message_when_negated
|
79
78
|
# message is compared to the provided message.
|
80
79
|
#
|
81
80
|
# @param [String, Regexp] message the message to compare
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-sleeping_king_studios
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0.alpha
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob "Merlin" Smith
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-06-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '3.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '3.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activemodel
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,20 +52,6 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '4.2'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: fuubar
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 1.1.1
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 1.1.1
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: pry
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -121,7 +107,6 @@ files:
|
|
121
107
|
- lib/rspec/sleeping_king_studios/matchers/require.rb
|
122
108
|
- lib/rspec/sleeping_king_studios/matchers/shared/match_parameters.rb
|
123
109
|
- lib/rspec/sleeping_king_studios/matchers/shared/require.rb
|
124
|
-
- lib/rspec/sleeping_king_studios/mocks/custom_double.rb
|
125
110
|
- lib/rspec/sleeping_king_studios/require.rb
|
126
111
|
- lib/rspec/sleeping_king_studios/version.rb
|
127
112
|
homepage: http://sleepingkingstudios.com
|
@@ -139,9 +124,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
139
124
|
version: '0'
|
140
125
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
126
|
requirements:
|
142
|
-
- - "
|
127
|
+
- - ">"
|
143
128
|
- !ruby/object:Gem::Version
|
144
|
-
version:
|
129
|
+
version: 1.3.1
|
145
130
|
requirements: []
|
146
131
|
rubyforge_project:
|
147
132
|
rubygems_version: 2.2.1
|
@@ -149,3 +134,4 @@ signing_key:
|
|
149
134
|
specification_version: 4
|
150
135
|
summary: A collection of RSpec patches and custom matchers.
|
151
136
|
test_files: []
|
137
|
+
has_rdoc:
|
@@ -1,13 +0,0 @@
|
|
1
|
-
# lib/rspec/sleeping_king_studios/mocks/custom_double.rb
|
2
|
-
|
3
|
-
module RSpec
|
4
|
-
module Mocks
|
5
|
-
module ExampleMethods
|
6
|
-
def custom_double(*args, &block)
|
7
|
-
args << {} unless Hash === args.last
|
8
|
-
args.last[:__declared_as] = "Custom Double"
|
9
|
-
Class.new(&block).new.tap { |obj| RSpec::Mocks::TestDouble.extend_onto obj, *args }
|
10
|
-
end # method
|
11
|
-
end # module
|
12
|
-
end # module
|
13
|
-
end # module
|