rspec-sleeping_king_studios 2.1.1 → 2.2.0.rc.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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +52 -0
  3. data/DEVELOPMENT.md +26 -17
  4. data/LICENSE +1 -1
  5. data/README.md +198 -19
  6. data/lib/rspec/sleeping_king_studios/configuration.rb +63 -2
  7. data/lib/rspec/sleeping_king_studios/examples/property_examples.rb +115 -27
  8. data/lib/rspec/sleeping_king_studios/examples/rspec_matcher_examples.rb +66 -51
  9. data/lib/rspec/sleeping_king_studios/matchers/active_model/have_errors.rb +8 -269
  10. data/lib/rspec/sleeping_king_studios/matchers/active_model/have_errors_matcher.rb +268 -0
  11. data/lib/rspec/sleeping_king_studios/matchers/base_matcher.rb +5 -15
  12. data/lib/rspec/sleeping_king_studios/matchers/built_in/be_kind_of.rb +3 -63
  13. data/lib/rspec/sleeping_king_studios/matchers/built_in/be_kind_of_matcher.rb +65 -0
  14. data/lib/rspec/sleeping_king_studios/matchers/built_in/include.rb +3 -108
  15. data/lib/rspec/sleeping_king_studios/matchers/built_in/include_matcher.rb +134 -0
  16. data/lib/rspec/sleeping_king_studios/matchers/built_in/respond_to.rb +3 -258
  17. data/lib/rspec/sleeping_king_studios/matchers/built_in/respond_to_matcher.rb +116 -0
  18. data/lib/rspec/sleeping_king_studios/matchers/core/alias_method.rb +11 -0
  19. data/lib/rspec/sleeping_king_studios/matchers/core/alias_method_matcher.rb +107 -0
  20. data/lib/rspec/sleeping_king_studios/matchers/core/be_boolean.rb +9 -36
  21. data/lib/rspec/sleeping_king_studios/matchers/core/be_boolean_matcher.rb +37 -0
  22. data/lib/rspec/sleeping_king_studios/matchers/core/construct.rb +3 -210
  23. data/lib/rspec/sleeping_king_studios/matchers/core/construct_matcher.rb +113 -0
  24. data/lib/rspec/sleeping_king_studios/matchers/core/delegate_method.rb +11 -0
  25. data/lib/rspec/sleeping_king_studios/matchers/core/delegate_method_matcher.rb +311 -0
  26. data/lib/rspec/sleeping_king_studios/matchers/core/have_constant.rb +16 -0
  27. data/lib/rspec/sleeping_king_studios/matchers/core/have_constant_matcher.rb +225 -0
  28. data/lib/rspec/sleeping_king_studios/matchers/core/have_predicate.rb +11 -0
  29. data/lib/rspec/sleeping_king_studios/matchers/core/have_predicate_matcher.rb +97 -0
  30. data/lib/rspec/sleeping_king_studios/matchers/core/have_property.rb +3 -104
  31. data/lib/rspec/sleeping_king_studios/matchers/core/have_property_matcher.rb +108 -0
  32. data/lib/rspec/sleeping_king_studios/matchers/core/have_reader.rb +3 -74
  33. data/lib/rspec/sleeping_king_studios/matchers/core/have_reader_matcher.rb +96 -0
  34. data/lib/rspec/sleeping_king_studios/matchers/core/have_writer.rb +4 -59
  35. data/lib/rspec/sleeping_king_studios/matchers/core/have_writer_matcher.rb +55 -0
  36. data/lib/rspec/sleeping_king_studios/matchers/description.rb +62 -0
  37. data/lib/rspec/sleeping_king_studios/matchers/macros.rb +32 -0
  38. data/lib/rspec/sleeping_king_studios/matchers/shared/match_parameters.rb +168 -66
  39. data/lib/rspec/sleeping_king_studios/matchers/shared/match_property.rb +25 -0
  40. data/lib/rspec/sleeping_king_studios/matchers.rb +0 -4
  41. data/lib/rspec/sleeping_king_studios/support/method_signature.rb +51 -0
  42. data/lib/rspec/sleeping_king_studios/support/method_signature_expectation.rb +158 -0
  43. data/lib/rspec/sleeping_king_studios/support.rb +9 -0
  44. data/lib/rspec/sleeping_king_studios/version.rb +10 -4
  45. metadata +46 -30
@@ -1,264 +1,9 @@
1
1
  # lib/rspec/sleeping_king_studios/matchers/built_in/respond_to.rb
2
2
 
3
- require 'rspec/sleeping_king_studios/matchers/base_matcher'
4
- require 'rspec/sleeping_king_studios/matchers/built_in'
5
- require 'rspec/sleeping_king_studios/matchers/shared/match_parameters'
6
- require 'sleeping_king_studios/tools/enumerable_tools'
7
- require 'sleeping_king_studios/tools/string_tools'
3
+ require 'rspec/sleeping_king_studios/matchers/built_in/respond_to_matcher'
4
+ require 'rspec/sleeping_king_studios/matchers/macros'
8
5
 
9
- module RSpec::SleepingKingStudios::Matchers::BuiltIn
10
- # Extensions to the built-in RSpec #respond_to matcher.
11
- class RespondToMatcher < RSpec::Matchers::BuiltIn::RespondTo
12
- include RSpec::SleepingKingStudios::Matchers::Shared::MatchParameters
13
- include SleepingKingStudios::Tools::EnumerableTools
14
- include SleepingKingStudios::Tools::StringTools
15
-
16
- def initialize *expected
17
- @include_all = [true, false].include?(expected.last) ? expected.pop : false
18
-
19
- super(*expected)
20
- end # constructor
21
-
22
- # (see BaseMatcher#description)
23
- def description
24
- expected_message = format_expected_arguments
25
- "respond to #{pp_names}#{expected_message.empty? ? '' : " with #{expected_message}"}"
26
- end # method description
27
-
28
- # Adds a parameter count expectation and/or one or more keyword
29
- # expectations.
30
- #
31
- # @overload with count
32
- # Adds a parameter count expectation.
33
- #
34
- # @param [Integer, Range, nil] count (optional) The number of expected
35
- # parameters.
36
- #
37
- # @return [RespondToMatcher] self
38
- # @overload with *keywords
39
- # Adds one or more keyword expectations.
40
- #
41
- # @param [Array<String, Symbol>] keywords List of keyword arguments
42
- # accepted by the method.
43
- #
44
- # @return [RespondToMatcher] self
45
- # @overload with count, *keywords
46
- # Adds a parameter count expectation and one or more keyword
47
- # expectations.
48
- #
49
- # @param [Integer, Range, nil] count (optional) The number of expected
50
- # parameters.
51
- # @param [Array<String, Symbol>] keywords List of keyword arguments
52
- # accepted by the method.
53
- #
54
- # @return [RespondToMatcher] self
55
- def with *keywords
56
- @expected_arity = keywords.shift if Integer === keywords.first || Range === keywords.first
57
-
58
- # TODO: Deprecate this behavior (for version 3.0?) - use the
59
- # #with_keywords or #and_keywords methods instead.
60
- (@expected_keywords ||= []).concat(keywords)
61
-
62
- self
63
- end # method with
64
-
65
- # Adds an unlimited parameter count expectation, e.g. that the method
66
- # supports splatted array arguments of the form *args.
67
- #
68
- # @return [RespondToMatcher] self
69
- def with_unlimited_arguments
70
- @expect_unlimited_arguments = true
71
-
72
- self
73
- end # method with_unlimited_arguments
74
- alias_method :and_unlimited_arguments, :with_unlimited_arguments
75
-
76
- # Adds one or more keyword expectations.
77
- #
78
- # @param [Array<String, Symbol>] keywords List of keyword arguments
79
- # accepted by the method.
80
- #
81
- # @return [RespondToMatcher] self
82
- def with_keywords *keywords
83
- (@expected_keywords ||= []).concat(keywords)
84
-
85
- self
86
- end # method with_keywords
87
- alias_method :and_keywords, :with_keywords
88
-
89
- # Adds an arbitrary keyword expectation, e.g. that the method supports
90
- # any keywords with splatted hash arguments of the form **kwargs.
91
- def with_arbitrary_keywords
92
- @expect_arbitrary_keywords = true
93
-
94
- self
95
- end # method with_arbitrary_keywords
96
- alias_method :and_arbitrary_keywords, :with_arbitrary_keywords
97
- alias_method :with_any_keywords, :with_arbitrary_keywords
98
- alias_method :and_any_keywords, :with_any_keywords
99
-
100
- # Adds a block expectation. The actual object will only match a block
101
- # expectation if it expects a parameter of the form &block.
102
- #
103
- # @return [RespondToMatcher] self
104
- def with_a_block
105
- @expected_block = true
106
- self
107
- end # method with_a_block
108
- alias_method :and_a_block, :with_a_block
109
-
110
- # (see BaseMatcher#failure_message)
111
- def failure_message
112
- @failing_method_names ||= []
113
- methods, messages = @failing_method_names, []
114
-
115
- methods.map do |method|
116
- message = "expected #{@actual.inspect} to respond to #{method.inspect}"
117
- if @actual.respond_to?(method, @include_all)
118
- message << " with arguments:\n#{format_errors_for_method method}"
119
- end # if-else
120
- messages << message
121
- end # method
122
-
123
- messages.join "\n"
124
- end # method failure_message
125
-
126
- # (see BaseMatcher#failure_message_when_negated)
127
- def failure_message_when_negated
128
- @failing_method_names ||= []
129
- methods, messages = @failing_method_names, []
130
-
131
- methods.map do |method|
132
- message = "expected #{@actual.inspect} not to respond to #{method.inspect}"
133
- unless (formatted = format_expected_arguments).empty?
134
- message << " with #{formatted}"
135
- end # unless
136
- messages << message
137
- end # method
138
-
139
- messages.join "\n"
140
- end # method failure_message_when_negated
141
-
142
- private
143
-
144
- def find_failing_method_names actual, filter_method
145
- @actual = actual
146
- @failing_method_reasons = {}
147
- @failing_method_names = @names.__send__(filter_method) do |name|
148
- @actual.respond_to?(name, @include_all) &&
149
- matches_arity?(actual, name) &&
150
- matches_keywords?(actual, name) &&
151
- matches_block?(actual, name)
152
- end # send
153
- end # method find_failing_method_names
154
-
155
- def matches_arity? actual, name
156
- return true unless @expected_arity || @expect_unlimited_arguments
157
-
158
- if result = check_method_arity(actual.method(name), @expected_arity, expect_unlimited_arguments: @expect_unlimited_arguments)
159
- (@failing_method_reasons[name] ||= {}).update result
160
- return false
161
- end # if
162
-
163
- true
164
- end # method matches_arity?
165
-
166
- def matches_keywords? actual, name
167
- return true unless @expected_keywords ||
168
- @expect_arbitrary_keywords ||
169
- (@expected_arity && RUBY_VERSION >= "2.1.0")
170
-
171
- if result = check_method_keywords(actual.method(name), @expected_keywords, expect_arbitrary_keywords: @expect_arbitrary_keywords)
172
- (@failing_method_reasons[name] ||= {}).update result
173
- return false
174
- end # if
175
-
176
- true
177
- rescue NameError => error
178
- if error.name == name
179
- # Actual responds to name, but doesn't actually have a method defined
180
- # there. Possibly using #method_missing or a test double. We obviously
181
- # can't test that, so bail.
182
- true
183
- else
184
- raise error
185
- end # if-else
186
- end # method matches_keywords?
187
-
188
- def matches_block? actual, name
189
- return true unless @expected_block
190
-
191
- if result = check_method_block(@actual.method(name))
192
- (@failing_method_reasons[name] ||= {}).update result
193
- return false
194
- end # if
195
-
196
- true
197
- end # method matches_block?
198
-
199
- def format_expected_arguments
200
- messages = []
201
-
202
- if !@expected_arity.nil?
203
- messages << "#{@expected_arity.inspect} #{pluralize @expected_arity, 'argument', 'arguments'}"
204
- end # if
205
-
206
- if @expect_unlimited_arguments
207
- messages << 'unlimited arguments'
208
- end # if
209
-
210
- if !(@expected_keywords.nil? || @expected_keywords.empty?)
211
- messages << "#{pluralize @expected_keywords.count, 'keyword', 'keywords'} #{humanize_list @expected_keywords.map(&:inspect)}"
212
- end # if
213
-
214
- if @expect_arbitrary_keywords
215
- messages << 'arbitrary keywords'
216
- end # if
217
-
218
- if @expected_block
219
- messages << "a block"
220
- end # if
221
-
222
- humanize_list messages
223
- end # method format_expected_arguments
224
-
225
- def format_errors_for_method method
226
- reasons, messages = @failing_method_reasons[method], []
227
-
228
- if hsh = reasons.fetch(:not_enough_args, false)
229
- messages << " expected at least #{hsh[:count]} arguments, but received #{hsh[:arity]}"
230
- end # if
231
-
232
- if hsh = reasons.fetch(:too_many_args, false)
233
- messages << " expected at most #{hsh[:count]} arguments, but received #{hsh[:arity]}"
234
- end # if
235
-
236
- if hsh = reasons.fetch(:expected_unlimited_arguments, false)
237
- messages << " expected at most #{hsh[:count]} arguments, but received unlimited arguments"
238
- end # if
239
-
240
- if reasons.fetch(:expected_arbitrary_keywords, false)
241
- messages << " expected arbitrary keywords"
242
- end # if
243
-
244
- if ary = reasons.fetch(:missing_keywords, false)
245
- messages << " missing #{pluralize ary.count, 'keyword', 'keywords'} #{humanize_list ary.map(&:inspect)}"
246
- end # if
247
-
248
- if ary = reasons.fetch(:unexpected_keywords, false)
249
- messages << " unexpected #{pluralize ary.count, 'keyword', 'keywords'} #{humanize_list ary.map(&:inspect)}"
250
- end # if
251
-
252
- if reasons.fetch(:expected_block, false)
253
- messages << " unexpected block"
254
- end # if
255
-
256
- messages.join "\n"
257
- end # method format_errors_for_method
258
- end # class
259
- end # module
260
-
261
- module RSpec::SleepingKingStudios::Matchers
6
+ module RSpec::SleepingKingStudios::Matchers::Macros
262
7
  # @see RSpec::SleepingKingStudios::Matchers::BuiltIn::RespondToMatcher#matches?
263
8
  def respond_to *expected
264
9
  RSpec::SleepingKingStudios::Matchers::BuiltIn::RespondToMatcher.new *expected
@@ -0,0 +1,116 @@
1
+ # lib/rspec/sleeping_king_studios/matchers/built_in/respond_to_matcher.rb
2
+
3
+ require 'rspec/sleeping_king_studios/matchers/base_matcher'
4
+ require 'rspec/sleeping_king_studios/matchers/built_in'
5
+ require 'rspec/sleeping_king_studios/matchers/shared/match_parameters'
6
+
7
+ module RSpec::SleepingKingStudios::Matchers::BuiltIn
8
+ # Extensions to the built-in RSpec #respond_to matcher.
9
+ class RespondToMatcher < RSpec::Matchers::BuiltIn::RespondTo
10
+ include RSpec::SleepingKingStudios::Matchers::Shared::MatchParameters
11
+
12
+ def initialize *expected
13
+ @include_all = [true, false].include?(expected.last) ? expected.pop : false
14
+
15
+ super(*expected)
16
+ end # constructor
17
+
18
+ # (see BaseMatcher#description)
19
+ def description
20
+ message = "respond to #{pp_names}"
21
+
22
+ if method_signature_expectation?
23
+ message << ' ' << method_signature_expectation.description
24
+ end # if
25
+
26
+ message
27
+ end # method description
28
+
29
+ # (see BaseMatcher#failure_message)
30
+ def failure_message
31
+ method_names = @failing_method_names || []
32
+ messages = []
33
+
34
+ method_names.map do |method_name|
35
+ message = "expected #{@actual.inspect} to respond to #{method_name.inspect}"
36
+ reasons = @failing_method_reasons[method_name] || {}
37
+
38
+ if reasons.key?(:does_not_respond_to_method)
39
+ message << ", but #{@actual.inspect} does not respond to #{method_name.inspect}"
40
+ elsif reasons.key?(:is_not_a_method)
41
+ message << ", but #{@actual.inspect} does not define a method at #{method_name.inspect}"
42
+ else
43
+ errors = @failing_method_reasons[method_name]
44
+
45
+ # TODO: Replace this with ", but received arguments did not match "\
46
+ # " method signature:"
47
+ message << " with arguments:\n" << format_errors(errors)
48
+ end # if-elsif-else
49
+
50
+ messages << message
51
+ end # method
52
+
53
+ messages.join "\n"
54
+ end # method failure_message
55
+
56
+ # (see BaseMatcher#failure_message_when_negated)
57
+ def failure_message_when_negated
58
+ @failing_method_names ||= []
59
+ methods, messages = @failing_method_names, []
60
+
61
+ methods.map do |method|
62
+ message = "expected #{@actual.inspect} not to respond to #{method.inspect}"
63
+
64
+ if method_signature_expectation?
65
+ message << ' ' << method_signature_expectation.description
66
+ end # if
67
+
68
+ messages << message
69
+ end # method
70
+
71
+ messages.join "\n"
72
+ end # method failure_message_when_negated
73
+
74
+ private
75
+
76
+ def find_failing_method_names actual, filter_method
77
+ @actual = actual
78
+ @failing_method_reasons = {}
79
+ @failing_method_names = @names.__send__(filter_method) do |method_name|
80
+ unless @actual.respond_to?(method_name, @include_all)
81
+ @failing_method_reasons[method_name] = {
82
+ :does_not_respond_to_method => true
83
+ } # end hash
84
+
85
+ next false
86
+ end # unless
87
+
88
+ method =
89
+ begin
90
+ actual.method(method_name)
91
+ rescue NameError
92
+ nil
93
+ end # unless
94
+
95
+ unless method.is_a?(Method)
96
+ @failing_method_reasons[method_name] = {
97
+ :is_not_a_method => true
98
+ } # end hash
99
+
100
+ next false
101
+ end # unless
102
+
103
+ next true unless method_signature_expectation?
104
+
105
+ unless check_method_signature(method)
106
+ @failing_method_reasons[method_name] =
107
+ method_signature_expectation.errors
108
+
109
+ next false
110
+ end # unless
111
+
112
+ true
113
+ end # send
114
+ end # method find_failing_method_names
115
+ end # class
116
+ end # module
@@ -0,0 +1,11 @@
1
+ # lib/rspec/sleeping_king_studios/matchers/core/alias_method.rb
2
+
3
+ require 'rspec/sleeping_king_studios/matchers/core/alias_method_matcher'
4
+ require 'rspec/sleeping_king_studios/matchers/macros'
5
+
6
+ module RSpec::SleepingKingStudios::Matchers::Macros
7
+ # @see RSpec::SleepingKingStudios::Matchers::Core::AliasMethodMatcher#matches?
8
+ def alias_method expected
9
+ RSpec::SleepingKingStudios::Matchers::Core::AliasMethodMatcher.new expected
10
+ end # method be_boolean
11
+ end # module
@@ -0,0 +1,107 @@
1
+ # lib/rspec/sleeping_king_studios/matchers/core/alias_method_matcher.rb
2
+
3
+ require 'rspec/sleeping_king_studios/matchers/base_matcher'
4
+ require 'rspec/sleeping_king_studios/matchers/core'
5
+
6
+ module RSpec::SleepingKingStudios::Matchers::Core
7
+ # Matcher for testing whether an object aliases a specified method using the
8
+ # specified other method name.
9
+ #
10
+ # @since 2.2.0
11
+ class AliasMethodMatcher < RSpec::SleepingKingStudios::Matchers::BaseMatcher
12
+ # @param [String, Symbol] expected The name of the method that is expected
13
+ # to be aliased.
14
+ def initialize expected
15
+ @old_method_name = @expected = expected.intern
16
+ @errors = {}
17
+ end # method initialize
18
+
19
+ # Specifies the name of the new method.
20
+ #
21
+ # @param [String, Symbol] new_method_name The method name.
22
+ #
23
+ # @return [AliasMethodMatcher] self
24
+ def as new_method_name
25
+ @new_method_name = new_method_name
26
+
27
+ self
28
+ end # method as
29
+
30
+ # (see BaseMatcher#description)
31
+ def description
32
+ str = "alias :#{old_method_name}"
33
+
34
+ str << " as #{new_method_name.inspect}" if new_method_name
35
+
36
+ str
37
+ end # method description
38
+
39
+ # (see BaseMatcher#failure_message)
40
+ def failure_message
41
+ message = "expected #{@actual.inspect} to alias :#{old_method_name}"
42
+
43
+ message << " as #{new_method_name.inspect}" if new_method_name
44
+
45
+ if @errors[:does_not_respond_to_old_method]
46
+ message << ", but did not respond to :#{old_method_name}"
47
+
48
+ return message
49
+ end # if
50
+
51
+ if @errors[:does_not_respond_to_new_method]
52
+ message << ", but did not respond to :#{new_method_name}"
53
+
54
+ return message
55
+ end # if
56
+
57
+ if @errors[:does_not_alias_method]
58
+ message <<
59
+ ", but :#{old_method_name} and :#{new_method_name} are different "\
60
+ "methods"
61
+
62
+ return message
63
+ end # if
64
+
65
+ message
66
+ end # method failure_message
67
+
68
+ # (see BaseMatcher#matches?)
69
+ def matches? actual
70
+ super
71
+
72
+ raise ArgumentError.new('must specify a new method name') if new_method_name.nil?
73
+
74
+ responds_to_methods? && aliases_method?
75
+ end # method matches?
76
+
77
+ private
78
+
79
+ attr_reader :old_method_name, :new_method_name
80
+
81
+ def aliases_method?
82
+ unless @actual.method(old_method_name) == @actual.method(new_method_name)
83
+ @errors[:does_not_alias_method] = true
84
+
85
+ return false
86
+ end # unless
87
+
88
+ true
89
+ end # method aliases_method?
90
+
91
+ def responds_to_methods?
92
+ unless @actual.respond_to?(old_method_name)
93
+ @errors[:does_not_respond_to_old_method] = true
94
+
95
+ return false
96
+ end # unless
97
+
98
+ unless @actual.respond_to?(new_method_name)
99
+ @errors[:does_not_respond_to_new_method] = true
100
+
101
+ return false
102
+ end # unless
103
+
104
+ true
105
+ end # method responds_to_methods?
106
+ end # class
107
+ end # module
@@ -1,46 +1,19 @@
1
1
  # lib/rspec/sleeping_king_studios/matchers/core/be_boolean.rb
2
2
 
3
- require 'rspec/sleeping_king_studios/matchers/base_matcher'
4
- require 'rspec/sleeping_king_studios/matchers/core'
3
+ require 'rspec/sleeping_king_studios/matchers/core/be_boolean_matcher'
4
+ require 'rspec/sleeping_king_studios/matchers/macros'
5
5
 
6
- module RSpec::SleepingKingStudios::Matchers::Core
7
- # Matcher for testing whether an object is true or false.
8
- #
9
- # @since 1.0.0
10
- class BeBooleanMatcher < RSpec::SleepingKingStudios::Matchers::BaseMatcher
11
- # (see BaseMatcher#description)
12
- def description
13
- 'be true or false'
14
- end # method description
15
-
16
- # Checks if the object is true or false.
17
- #
18
- # @param [Object] actual The object to check.
19
- #
20
- # @return [Boolean] True if the object is true or false, otherwise false.
21
- def matches? actual
22
- super
23
-
24
- true === actual || false === actual
25
- end # method matches?
26
-
27
- # (see BaseMatcher#failure_message)
28
- def failure_message
29
- "expected #{@actual.inspect} to be true or false"
30
- end # method failure_message
31
-
32
- # (see BaseMatcher#failure_message_when_negated)
33
- def failure_message_when_negated
34
- "expected #{@actual.inspect} not to be true or false"
35
- end # method failure_message_when_negated
36
- end # class
37
- end # module
38
-
39
- module RSpec::SleepingKingStudios::Matchers
6
+ module RSpec::SleepingKingStudios::Matchers::Macros
40
7
  # @see RSpec::SleepingKingStudios::Matchers::Core::BeBooleanMatcher#matches?
41
8
  def be_boolean
42
9
  RSpec::SleepingKingStudios::Matchers::Core::BeBooleanMatcher.new
43
10
  end # method be_boolean
44
11
 
45
12
  alias_method :be_bool, :be_boolean
13
+
14
+ # @!method a_boolean
15
+ # @see RSpec::SleepingKingStudios::Matchers::Core::BeBooleanMatcher#matches?
16
+ alias_matcher :a_boolean, :be_boolean do |description|
17
+ 'true or false'
18
+ end # alias
46
19
  end # module
@@ -0,0 +1,37 @@
1
+ # lib/rspec/sleeping_king_studios/matchers/core/be_boolean_matcher.rb
2
+
3
+ require 'rspec/sleeping_king_studios/matchers/base_matcher'
4
+ require 'rspec/sleeping_king_studios/matchers/core'
5
+
6
+ module RSpec::SleepingKingStudios::Matchers::Core
7
+ # Matcher for testing whether an object is true or false.
8
+ #
9
+ # @since 1.0.0
10
+ class BeBooleanMatcher < RSpec::SleepingKingStudios::Matchers::BaseMatcher
11
+ # (see BaseMatcher#description)
12
+ def description
13
+ 'be true or false'
14
+ end # method description
15
+
16
+ # Checks if the object is true or false.
17
+ #
18
+ # @param [Object] actual The object to check.
19
+ #
20
+ # @return [Boolean] True if the object is true or false, otherwise false.
21
+ def matches? actual
22
+ super
23
+
24
+ true === actual || false === actual
25
+ end # method matches?
26
+
27
+ # (see BaseMatcher#failure_message)
28
+ def failure_message
29
+ "expected #{@actual.inspect} to be true or false"
30
+ end # method failure_message
31
+
32
+ # (see BaseMatcher#failure_message_when_negated)
33
+ def failure_message_when_negated
34
+ "expected #{@actual.inspect} not to be true or false"
35
+ end # method failure_message_when_negated
36
+ end # class
37
+ end # module