rspec-sleeping_king_studios 2.0.0.beta.2 → 2.0.0.rc.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (27) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1 -1
  3. data/DEVELOPMENT.md +3 -7
  4. data/README.md +50 -89
  5. data/lib/rspec/sleeping_king_studios/all.rb +1 -0
  6. data/lib/rspec/sleeping_king_studios/concerns/all.rb +5 -0
  7. data/lib/rspec/sleeping_king_studios/{examples → concerns}/shared_example_group.rb +29 -3
  8. data/lib/rspec/sleeping_king_studios/concerns.rb +8 -0
  9. data/lib/rspec/sleeping_king_studios/configuration.rb +19 -1
  10. data/lib/rspec/sleeping_king_studios/examples/property_examples.rb +8 -2
  11. data/lib/rspec/sleeping_king_studios/examples/rspec_matcher_examples.rb +3 -2
  12. data/lib/rspec/sleeping_king_studios/matchers/active_model/have_errors/error_expectation.rb +16 -15
  13. data/lib/rspec/sleeping_king_studios/matchers/active_model/have_errors/message_expectation.rb +4 -4
  14. data/lib/rspec/sleeping_king_studios/matchers/active_model/have_errors.rb +14 -15
  15. data/lib/rspec/sleeping_king_studios/matchers/base_matcher.rb +6 -7
  16. data/lib/rspec/sleeping_king_studios/matchers/built_in/be_kind_of.rb +9 -10
  17. data/lib/rspec/sleeping_king_studios/matchers/built_in/include.rb +10 -7
  18. data/lib/rspec/sleeping_king_studios/matchers/built_in/respond_to.rb +10 -7
  19. data/lib/rspec/sleeping_king_studios/matchers/built_in.rb +1 -0
  20. data/lib/rspec/sleeping_king_studios/matchers/core/be_boolean.rb +5 -7
  21. data/lib/rspec/sleeping_king_studios/matchers/core/construct.rb +20 -19
  22. data/lib/rspec/sleeping_king_studios/matchers/core/have_property.rb +14 -15
  23. data/lib/rspec/sleeping_king_studios/matchers/core/have_reader.rb +12 -14
  24. data/lib/rspec/sleeping_king_studios/matchers/core.rb +1 -0
  25. data/lib/rspec/sleeping_king_studios/version.rb +12 -2
  26. data/lib/rspec/sleeping_king_studios.rb +1 -0
  27. metadata +9 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9ac96e7fae3fdf94aa39e7ebfecccfc39766ada0
4
- data.tar.gz: 0d96c3c2402360bbf600fce1bd882ea38d8f341f
3
+ metadata.gz: 8f8068de1e2622240688c78aaa24232869a3b9f0
4
+ data.tar.gz: 3244ec9495f61915abffb5cdc5fe791b03caad1c
5
5
  SHA512:
6
- metadata.gz: e5ed09efe3e51e5900e6332fe5e51677c17e47d874aa85304ddad33ab93c12b3f8c5006371e8e80df4efaeeeecdae1fb06fe02bf1a10663df24d7cb7a3b204ed
7
- data.tar.gz: 5d4abb850b85fbfffb3544268c4b47b07038816f03e2be7ded0a43ce1bf9963b566ca66db81fa6958eeb491667ac3621ccc8815dbb7807347a8ce2c60793405e
6
+ metadata.gz: 60e23c171168e16b0f0af51beb9dbb4b26713005cec1b245a8fcbca6160c2c63d22cfea679146ee304a871b6211f1fb9d1f3bad4017afdd676627febda51a4ee
7
+ data.tar.gz: ee596646cf418ef1a68eff366994efff79bc26c1b2bf650d73b7a0e18513b2e176c0571d26cc68cca5f7af714f1cc02708dcef0c4788df694e9c12d215f9932c
data/CHANGELOG.md CHANGED
@@ -10,7 +10,7 @@ Support for Ruby 1.9.3 is officially dropped.
10
10
 
11
11
  ### Concerns
12
12
 
13
- Added module RSpec::SleepingKingStudios::Examples::SharedExampleGroup as a mixin for defining scoped shared example groups. Extend into a module to define shared example groups scoped to that module (and automatically included in example groups when the module is included), or extend into an example group to allow aliasing shared example groups with alternate or more expressive names.
13
+ Added module RSpec::SleepingKingStudios::Concerns::SharedExampleGroup as a mixin for defining scoped shared example groups. Extend into a module to define shared example groups scoped to that module (and automatically included in example groups when the module is included), or extend into an example group to allow aliasing shared example groups with alternate or more expressive names.
14
14
 
15
15
  ### Custom Examples
16
16
 
data/DEVELOPMENT.md CHANGED
@@ -2,15 +2,11 @@
2
2
 
3
3
  ## Tasks
4
4
 
5
- ### High Priority
5
+ ### Release Candidate
6
6
 
7
- ### Medium Priority
8
-
9
- [RC1]
10
7
  - Thorough documentation pass.
11
- - Test against both RSpec 3.0 and 3.1 (multiple gemfiles? See ActiveModel::Collection for how it's done)
12
8
 
13
- ### Low Priority
9
+ ### Post 2.0.0
14
10
 
15
- [RC1]
16
11
  - Cucumber features for testing matchers, including returned text?
12
+ - add shared examples for #belongs_to, #has_one, #has_many, #embedded_in, #embeds_one, #embeds_many.
data/README.md CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  A collection of matchers and extensions to ease TDD/BDD using RSpec. Extends built-in matchers with new functionality, such as support for Ruby 2.0+ keyword arguments, and adds new matchers for testing boolean-ness, object reader/writer properties, object constructor arguments, ActiveModel validations, and more. Also defines shared example groups for more expressive testing.
4
4
 
5
- ## Supported Ruby Versions
5
+ ## Support
6
+
7
+ RSpec::SleepingKingStudios is tested against RSpec 3.0 and 3.1.
6
8
 
7
9
  Currently, the following versions of Ruby are officially supported:
8
10
 
@@ -11,7 +13,9 @@ Currently, the following versions of Ruby are officially supported:
11
13
 
12
14
  ## Contribute
13
15
 
14
- - https://github.com/sleepingkingstudios/rspec-sleeping_king_studios
16
+ ### GitHub
17
+
18
+ The canonical repository for this gem is located at https://github.com/sleepingkingstudios/rspec-sleeping_king_studios.
15
19
 
16
20
  ### A Note From The Developer
17
21
 
@@ -41,10 +45,10 @@ RSpec::SleepingKingStudios defines a few concerns that can be included in or ext
41
45
 
42
46
  ### Shared Example Groups
43
47
 
44
- require 'rspec/sleeping_king_studios/examples/shared_example_group'
48
+ require 'rspec/sleeping_king_studios/concerns/shared_example_group'
45
49
 
46
50
  module MyCustomExamples
47
- extend RSpec::SleepingKingStudios::Examples::SharedExampleGroup
51
+ extend RSpec::SleepingKingStudios::Concerns::SharedExampleGroup
48
52
 
49
53
  shared_examples 'has custom behavior' do
50
54
  # Define expectations here...
@@ -56,16 +60,15 @@ Utility functions for defining shared examples. If included in a module, any sha
56
60
 
57
61
  ### `::alias_shared_examples`
58
62
 
59
- Aliases a defined shared example group, allowing it to be accessed using a new name. The example group must be defined in the current context using `shared_examples`. The aliases must be defined before including the module into an example group, or they will not be available in the example group.
63
+ (also `::alias_shared_context`) Aliases a defined shared example group, allowing it to be accessed using a new name. The example group must be defined in the current context using `shared_examples`. The aliases must be defined before including the module into an example group, or they will not be available in the example group.
60
64
 
61
65
  ### `::shared_examples`
62
66
 
63
- Defines a shared example group within the context of the current module. Unlike a top-level example group defined using RSpec#shared_examples, these examples are not globally available, and must be mixed into an example group by including the module. The shared examples must be defined before including the module, or they will not be available in the example group.
67
+ (also `::shared_context`) Defines a shared example group within the context of the current module. Unlike a top-level example group defined using RSpec#shared_examples, these examples are not globally available, and must be mixed into an example group by including the module. The shared examples must be defined before including the module, or they will not be available in the example group.
64
68
 
65
69
  ## Custom Matchers
66
70
 
67
- To enable a custom matcher, simply require the associated file. Matchers can be
68
- required individually or by category:
71
+ To enable a custom matcher, simply require the associated file. Matchers can be required individually or by category:
69
72
 
70
73
  require 'rspec/sleeping_king_studios/all'
71
74
  #=> requires all features, including matchers
@@ -82,12 +85,11 @@ required individually or by category:
82
85
 
83
86
  These matchers validate ActiveModel functionality, such as validations.
84
87
 
85
- #### have\_errors Matcher
88
+ #### `#have_errors` Matcher
86
89
 
87
90
  require 'rspec/sleeping_king_studios/matchers/active_model/have_errors'
88
91
 
89
- Verifies that the actual object has validation errors. Optionally can specify
90
- individual fields to validate, or even specific messages for each attribute.
92
+ Verifies that the actual object has validation errors. Optionally can specify individual fields to validate, or even specific messages for each attribute.
91
93
 
92
94
  **How To Use:**
93
95
 
@@ -99,15 +101,10 @@ individual fields to validate, or even specific messages for each attribute.
99
101
 
100
102
  **Chaining:**
101
103
 
102
- * **on:** [String, Symbol] Adds a field to validate; the matcher only passes if
103
- all validated fields have errors.
104
- * **with:** [Array<String>] Adds one or more messages to the previously-defined
105
- field validation. Raises ArgumentError if no field was previously set.
106
- * **with\_message:** [String] Adds a message to the previously-defined field
107
- validation. Raises ArgumentError if no field was previously set.
108
- * **with\_messages:** [Array<String>] Adds one or more messages to the
109
- previously-defined field validation. Raises ArgumentError if no field was
110
- previously set.
104
+ * **`#on`:** [String, Symbol] Adds a field to validate; the matcher only passes if all validated fields have errors.
105
+ * **`#with`:** [Array<String>] Adds one or more messages to the previously-defined field validation. Raises ArgumentError if no field was previously set.
106
+ * **`#with_message`:** [String] Adds a message to the previously-defined field validation. Raises ArgumentError if no field was previously set.
107
+ * **`#with_messages`:** [Array<String>] Adds one or more messages to the previously-defined field validation. Raises ArgumentError if no field was previously set.
111
108
 
112
109
  ### BuiltIn
113
110
 
@@ -115,12 +112,11 @@ individual fields to validate, or even specific messages for each attribute.
115
112
 
116
113
  These extend the built-in RSpec matchers with additional functionality.
117
114
 
118
- #### be\_kind\_of Matcher
115
+ #### `#be_kind_of` Matcher
119
116
 
120
117
  require 'rspec/sleeping_king_studios/matchers/built_in/be_kind_of'
121
118
 
122
- Now accepts an Array of types. The matcher passes if the actual object is
123
- any of the parameter types.
119
+ Now accepts an Array of types. The matcher passes if the actual object is any of the parameter types.
124
120
 
125
121
  Also allows nil parameter as a shortcut for NilClass.
126
122
 
@@ -129,19 +125,17 @@ Also allows nil parameter as a shortcut for NilClass.
129
125
  expect(instance).to be_kind_of [String, Symbol, nil]
130
126
  #=> passes iff instance is a String, a Symbol, or is nil
131
127
 
132
- #### include Matcher
128
+ #### `#include` Matcher
133
129
 
134
130
  require 'rspec/sleeping_king_studios/matchers/built_in/include'
135
131
 
136
- Now accepts Proc parameters; items in the actual object are passed into
137
- proc#call, with a truthy response considered a match to the item. In addition,
138
- now accepts an optional block as a shortcut for adding a proc expectation.
132
+ Now accepts Proc parameters; items in the actual object are passed into proc#call, with a truthy response considered a match to the item. In addition, now accepts an optional block as a shortcut for adding a proc expectation.
139
133
 
140
134
  **How To Use:**
141
135
 
142
136
  expect(instance).to include { |item| item =~ /pattern/ }
143
137
 
144
- #### respond\_to Matcher
138
+ #### `#respond_to` Matcher
145
139
 
146
140
  require 'rspec/sleeping_king_studios/matchers/built_in/respond_to'
147
141
 
@@ -149,25 +143,27 @@ Now has additional chaining functionality to validate the number of arguments ac
149
143
 
150
144
  **How To Use:**
151
145
 
152
- # With a variable number of arguments.
153
- expect(instance).to respond_to(:foo).with(2..3).arguments.with_a_block
146
+ # With a block.
147
+ expect(instance).to respond_to(:foo).with_a_block.
148
+
149
+ # With a variable number of arguments and a block.
150
+ expect(instance).to respond_to(:foo).with(2..3).arguments.and_a_block
154
151
 
155
152
  # With keyword arguments.
156
153
  expect(instance).to respond_to(:foo).with(0, :bar, :baz)
157
154
 
158
155
  **Chaining:**
159
156
 
160
- * **with:** Expects at most one Integer or Range argument, and zero or more Symbol arguments corresponding to optional keywords. Verifies that the method accepts that keyword, or has a variadic keyword of the form `**params`. As of 2.1.0 and required keywords, verifies that all required keywords are provided.
161
- * **with\_a\_block:** No parameters. Verifies that the method requires a block argument of the form `&my_argument`. _Important note:_ A negative result _does not_ mean the method cannot accept a block, merely that it does not require one. Also, _does not_ check whether the block is called or yielded.
157
+ * **`#with`:** Expects at most one Integer or Range argument, and zero or more Symbol arguments corresponding to optional keywords. Verifies that the method accepts that keyword, or has a variadic keyword of the form `**params`. As of 2.1.0 and required keywords, verifies that all required keywords are provided.
158
+ * **`#with_a_block`:** (also `and_a_block`) No parameters. Verifies that the method requires a block argument of the form `&my_argument`. _Important note:_ A negative result _does not_ mean the method cannot accept a block, merely that it does not require one. Also, _does not_ check whether the block is called or yielded.
162
159
 
163
160
  ### Core
164
161
 
165
162
  require 'rspec/sleeping_king_studios/matchers/core/all'
166
163
 
167
- These matchers check core functionality, such as object boolean-ness, the
168
- existence of properties, and so on.
164
+ These matchers check core functionality, such as object boolean-ness, the existence of properties, and so on.
169
165
 
170
- #### be_boolean Matcher
166
+ #### `#be_boolean` Matcher
171
167
 
172
168
  require 'rspec/sleeping_king_studios/matchers/core/be_boolean'
173
169
 
@@ -179,46 +175,31 @@ Checks if the provided object is true or false.
179
175
 
180
176
  **Parameters:** None.
181
177
 
182
- #### construct Matcher
178
+ #### `#construct` Matcher
183
179
 
184
180
  require 'rspec/sleeping_king_studios/matchers/core/construct'
185
181
 
186
- Verifies that the actual object can be constructed using :new. Can take an
187
- optional number of arguments.
182
+ Verifies that the actual object can be constructed using `::new`. Can take an optional number of arguments.
188
183
 
189
184
  **How To Use:**
190
185
 
186
+ # With an expected number of arguments.
191
187
  expect(described_class).to construct.with(1).arguments
192
188
 
193
- **Parameters:** None.
194
-
195
- **Chaining:**
196
-
197
- * **with:** Expects one Integer or Range argument. If an Integer, verifies that
198
- the class's constructor accepts that number of arguments; if a Range,
199
- verifies that the constructor accepts both the minimum and maximum number of
200
- arguments.
201
-
202
- ##### Ruby 2.0+
189
+ # With an expected number of arguments and set of keywords.
190
+ expect(instance).to construct.with(0, :bar, :baz)
203
191
 
204
- Has additional functionality to support Ruby 2.0 keyword arguments.
205
-
206
- **How To Use:**
207
- expect(instance).to construct.with(0, :bar, :baz)
192
+ **Parameters:** None.
208
193
 
209
194
  **Chaining:**
210
195
 
211
- * **with:** Expects one Integer, Range, or nil argument, and zero or more
212
- Symbol arguments corresponding to optional keywords. Verifies that the
213
- class's constructor accepts that keyword, or has a variadic keyword of the
214
- form \*\*params. As of 2.1.0 and required keywords, verifies that all
215
- required keywords are provided.
196
+ * **`#with`:** Expects one Integer, Range, or nil argument, and zero or more Symbol arguments corresponding to optional keywords. Verifies that the class's constructor accepts that keyword, or has a variadic keyword of the form `**params`. As of Ruby 2.1 and required keywords, verifies that all required keywords are provided.
216
197
 
217
- #### have\_property Matcher
198
+ #### `#have_property` Matcher
218
199
 
219
200
  require 'rspec/sleeping_king_studios/matchers/core/have_property'
220
201
 
221
- Checks if the actual object responds to :property and :property=, and optionally if the curernt value of actual.property is equal to a specified value.
202
+ Checks if the actual object responds to `#property` and `#property=`, and optionally if the current value of `actual.property()` is equal to a specified value.
222
203
 
223
204
  **How To Use:**
224
205
 
@@ -228,18 +209,15 @@ Checks if the actual object responds to :property and :property=, and optionally
228
209
 
229
210
  **Chaining:**
230
211
 
231
- * **with:** Expects one object, which is checked against the current value of actual.property if actual responds to :property. Can also be used with an RSpec matcher:
212
+ * **`#with`:** (also `#with_value`) Expects one object, which is checked against the current value of `actual.property()` if actual responds to `#property`. Can also be used with an RSpec matcher:
232
213
 
233
214
  expect(instance).to have_property(:bar).with(an_instance_of(String))
234
215
 
235
- * **with_value:** Alias for `#with`, above.
236
-
237
- #### have\_reader Matcher
216
+ #### `#have_reader` Matcher
238
217
 
239
218
  require 'rspec/sleeping_king_studios/matchers/core/have_reader'
240
219
 
241
- Checks if the actual object responds to :property, and optionally if the
242
- current value of actual.property is equal to a specified value.
220
+ Checks if the actual object responds to `#property`, and optionally if the current value of `actual.property()` is equal to a specified value.
243
221
 
244
222
  **How To Use:**
245
223
 
@@ -249,38 +227,21 @@ current value of actual.property is equal to a specified value.
249
227
 
250
228
  **Chaining:**
251
229
 
252
- * **with:** Expects one object, which is checked against the current value of actual.property if actual responds to :property. Can also be used with an RSpec matcher:
230
+ * **`#with`:** (also `#with_value`) Expects one object, which is checked against the current value of `actual.property()` if actual responds to `#property`. Can also be used with an RSpec matcher:
253
231
 
254
232
  expect(instance).to have_reader(:bar).with(an_instance_of(String))
255
233
 
256
- * **with_value:** Alias for `#with`, above.
257
-
258
- #### have\_writer Matcher
234
+ #### `#have_writer` Matcher
259
235
 
260
236
  require 'rspec/sleeping_king_studios/matchers/core/have_writer'
261
237
 
262
- Checks if the actual object responds to :property=.
238
+ Checks if the actual object responds to `#property=`.
263
239
 
264
240
  **How To Use:**
265
241
 
266
242
  expect(instance).to have_writer(:foo=)
267
243
 
268
- **Parameters:** Property. Expects a string or symbol that is a valid
269
- identifier. An equals sign '=' is automatically added if the identifier does
270
- not already terminate in '='.
271
-
272
- #### include\_matching Matcher
273
-
274
- require 'rspec/sleeping_king_studios/matchers/core/include_matching'
275
-
276
- Loops through an enumerable actual object and checks if any of the items
277
- matches the given pattern.
278
-
279
- **How To Use:**
280
-
281
- expect(instance).to include_matching(/[01]+/)
282
-
283
- **Parameters:** Pattern. Expects a Regexp.
244
+ **Parameters:** Property. Expects a string or symbol that is a valid identifier. An equals sign '=' is automatically added if the identifier does not already terminate in '='.
284
245
 
285
246
  ## Shared Examples
286
247
 
@@ -306,7 +267,7 @@ These examples are shorthand for defining a reader and/or writer expectation.
306
267
 
307
268
  include_examples 'has property', :foo, 42
308
269
 
309
- Delegates to the `#has_reader` and `#has_writer` matchers (see Core/Has Reader and Core/Has Writer, above) and passes if the actual object responds to the specified property and property writer methods. If a value is specified, the object must respond to the property and return the specified value. Alternatively, you can set a proc as the expected value, which can contain a comparison, an RSpec expectation, or a more complex expression:
270
+ Delegates to the `#has_reader` and `#has_writer` matchers (see Core/#has\_reader and Core/#has\_writer, above) and passes if the actual object responds to the specified property and property writer methods. If a value is specified, the object must respond to the property and return the specified value. Alternatively, you can set a proc as the expected value, which can contain a comparison, an RSpec expectation, or a more complex expression:
310
271
 
311
272
  include_examples 'has property', :bar, ->() { an_instance_of(String) }
312
273
 
@@ -316,7 +277,7 @@ Delegates to the `#has_reader` and `#has_writer` matchers (see Core/Has Reader a
316
277
 
317
278
  include_examples 'has reader', :foo, 42
318
279
 
319
- Delegates to the `#has_reader` matcher (see Core/Has Reader, above) and passes if the actual object responds to the specified property. If a value is specified, the object must respond to the property and return the specified value. Alternatively, you can set a proc as the expected value, which can contain a comparison, an RSpec expectation, or a more complex expression:
280
+ Delegates to the `#has_reader` matcher (see Core/#has_reader, above) and passes if the actual object responds to the specified property. If a value is specified, the object must respond to the property and return the specified value. Alternatively, you can set a proc as the expected value, which can contain a comparison, an RSpec expectation, or a more complex expression:
320
281
 
321
282
  include_examples 'has reader', :bar, ->() { an_instance_of(String) }
322
283
 
@@ -326,7 +287,7 @@ Delegates to the `#has_reader` matcher (see Core/Has Reader, above) and passes i
326
287
 
327
288
  include_examples 'has writer', :foo=
328
289
 
329
- Delegates to the `#has_writer` matcher (see Core/Has Writer, above) and passes if the actual object responds to the specified property writer.
290
+ Delegates to the `#has_writer` matcher (see Core/#has_writer, above) and passes if the actual object responds to the specified property writer.
330
291
 
331
292
  ### RSpec Matcher Examples
332
293
 
@@ -1,4 +1,5 @@
1
1
  # lib/rspec/sleeping_king_studios/all.rb
2
2
 
3
+ require 'rspec/sleeping_king_studios/concerns/all'
3
4
  require 'rspec/sleeping_king_studios/examples/all'
4
5
  require 'rspec/sleeping_king_studios/matchers/all'
@@ -0,0 +1,5 @@
1
+ # lib/rspec/sleeping_king_studios/concerns/all.rb
2
+
3
+ Dir[File.join File.dirname(__FILE__), '*.rb'].each do |file|
4
+ require file
5
+ end # end each
@@ -1,8 +1,25 @@
1
- # lib/rspec/sleeping_king_studios/examples/shared_example_group.rb
1
+ # lib/rspec/sleeping_king_studios/concerns/shared_example_group.rb
2
2
 
3
- require 'rspec/sleeping_king_studios/examples'
3
+ require 'rspec/sleeping_king_studios/concerns'
4
4
 
5
- module RSpec::SleepingKingStudios::Examples
5
+ module RSpec::SleepingKingStudios::Concerns
6
+ # Methods for creating reusable shared example groups and shared contexts in
7
+ # a module that can be mixed into multiple RSpec example groups.
8
+ #
9
+ # @example
10
+ # module MySharedExamples
11
+ # extend Rspec::SleepingKingStudios::Concerns::SharedExampleGroup
12
+ #
13
+ # shared_examples 'my examples' do
14
+ # # Define shared examples here.
15
+ # end # shared_examples
16
+ # end # module
17
+ #
18
+ # RSpec.describe MyObject do
19
+ # include MySharedExamples
20
+ #
21
+ # include_examples 'my examples'
22
+ # end # describe
6
23
  module SharedExampleGroup
7
24
  # Aliases a defined shared example group, allowing it to be accessed using
8
25
  # a new name. The example group must be defined in the current context
@@ -14,13 +31,21 @@ module RSpec::SleepingKingStudios::Examples
14
31
  # as.
15
32
  # @param [String] old_name The name under which the shared example group is
16
33
  # currently defined.
34
+ #
35
+ # @raise ArgumentError If the referenced shared example group does not
36
+ # exist.
17
37
  def alias_shared_examples new_name, old_name
18
38
  proc = shared_example_groups[self][old_name]
19
39
 
40
+ raise ArgumentError.new(%{Could not find shared examples "#{old_name}"}) if proc.nil?
41
+
20
42
  self.shared_examples new_name, &proc
21
43
  end # method alias_shared_examples
44
+ alias_method :alias_shared_context, :alias_shared_examples
22
45
 
23
46
  # @api private
47
+ #
48
+ # Hook to merge defined example groups when included in another module.
24
49
  def included other
25
50
  merge_shared_example_groups other
26
51
  end # method included
@@ -44,6 +69,7 @@ module RSpec::SleepingKingStudios::Examples
44
69
  def shared_examples name, *metadata_args, &block
45
70
  RSpec.world.shared_example_group_registry.add(self, name, *metadata_args, &block)
46
71
  end # method shared_examples
72
+ alias_method :shared_context, :shared_examples
47
73
 
48
74
  private
49
75
 
@@ -0,0 +1,8 @@
1
+ # lib/rspec/sleeping_king_studios/concerns.rb
2
+
3
+ require 'rspec/sleeping_king_studios'
4
+
5
+ module RSpec::SleepingKingStudios
6
+ # RSpec-related concerns to mix into classes or objects.
7
+ module Concerns; end
8
+ end # module
@@ -3,14 +3,29 @@
3
3
  require 'rspec/sleeping_king_studios'
4
4
 
5
5
  module RSpec::SleepingKingStudios
6
+ # Configuration options for RSpec::SleepingKingStudios.
6
7
  class Configuration
8
+ # Configuration options for RSpec::SleepingKingStudios::Examples.
7
9
  class Examples
10
+ # Permitted options for :handle_missing_failure_message_with.
8
11
  MISSING_FAILURE_MESSAGE_HANDLERS = %w(ignore pending exception).map(&:intern)
9
12
 
13
+ # Gets the handler for missing failure messages when using the matcher
14
+ # examples, and sets to :pending if unset.
15
+ #
16
+ # @return [Symbol] The current missing message handler.
10
17
  def handle_missing_failure_message_with
11
18
  @handle_missing_failure_message_with ||= :pending
12
19
  end # method missing_failure_message
13
20
 
21
+ # Sets the handler for missing failure messages when using the matcher
22
+ # examples.
23
+ #
24
+ # @param [Symbol] value The desired handler. Must be :ignore, :pending,
25
+ # or :exception.
26
+ #
27
+ # @raise ArgumentError If the handler is not one of the recognized
28
+ # values.
14
29
  def handle_missing_failure_message_with= value
15
30
  unless MISSING_FAILURE_MESSAGE_HANDLERS.include?(value)
16
31
  message = "unrecognized handler value -- must be in #{MISSING_FAILURE_MESSAGE_HANDLERS.join ', '}"
@@ -20,7 +35,9 @@ module RSpec::SleepingKingStudios
20
35
  @handle_missing_failure_message_with = value
21
36
  end # message missing_failure_message=
22
37
  end # class
23
-
38
+
39
+ # Get or set the configuration options for
40
+ # RSpec::SleepingKingStudios::Examples.
24
41
  def examples &block
25
42
  (@examples ||= RSpec::SleepingKingStudios::Configuration::Examples.new).tap do |config|
26
43
  if block_given?
@@ -32,6 +49,7 @@ module RSpec::SleepingKingStudios
32
49
  end # module
33
50
 
34
51
  class RSpec::Core::Configuration
52
+ # Get or set the configuration options for RSpec::SleepingKingStudios.
35
53
  def sleeping_king_studios &block
36
54
  (@sleeping_king_studios ||= RSpec::SleepingKingStudios::Configuration.new).tap do |config|
37
55
  if block_given?
@@ -1,14 +1,20 @@
1
1
  # lib/rspec/sleeping_king_studios/examples/property_examples.rb
2
2
 
3
+ require 'rspec/sleeping_king_studios/concerns/shared_example_group'
3
4
  require 'rspec/sleeping_king_studios/examples'
4
- require 'rspec/sleeping_king_studios/examples/shared_example_group'
5
5
  require 'rspec/sleeping_king_studios/matchers/core/have_reader'
6
6
  require 'rspec/sleeping_king_studios/matchers/core/have_writer'
7
7
  require 'sleeping_king_studios/tools/object_tools'
8
8
 
9
+ # Pregenerated example groups for testing the presence and value of reader and
10
+ # writer methods.
9
11
  module RSpec::SleepingKingStudios::Examples::PropertyExamples
10
- extend RSpec::SleepingKingStudios::Examples::SharedExampleGroup
12
+ extend RSpec::SleepingKingStudios::Concerns::SharedExampleGroup
11
13
 
14
+ # @api private
15
+ #
16
+ # Internal object used to differentiate a nil expectation from a default
17
+ # value expectation.
12
18
  UNDEFINED_PROPERTY_EXPECTATION = Object.new.freeze
13
19
 
14
20
  shared_examples 'has reader' do |property, expected_value = UNDEFINED_PROPERTY_EXPECTATION|
@@ -1,11 +1,12 @@
1
1
  # lib/rspec/sleeping_king_studios/examples/rspec_matcher_examples.rb
2
2
 
3
+ require 'rspec/sleeping_king_studios/concerns/shared_example_group'
3
4
  require 'rspec/sleeping_king_studios/examples'
4
- require 'rspec/sleeping_king_studios/examples/shared_example_group'
5
5
  require 'rspec/sleeping_king_studios/matchers/base_matcher'
6
6
 
7
+ # Pregenerated example groups for testing RSpec matchers.
7
8
  module RSpec::SleepingKingStudios::Examples::RSpecMatcherExamples
8
- extend RSpec::SleepingKingStudios::Examples::SharedExampleGroup
9
+ extend RSpec::SleepingKingStudios::Concerns::SharedExampleGroup
9
10
 
10
11
  shared_examples 'passes with a positive expectation' do
11
12
  let(:matcher_being_examined) { defined?(instance) ? instance : subject }
@@ -2,41 +2,42 @@
2
2
 
3
3
  require 'rspec/sleeping_king_studios/matchers/active_model/have_errors/message_expectation'
4
4
 
5
+ # Helper objects for the ActiveModel::HaveErrorsMatcher.
5
6
  module RSpec::SleepingKingStudios::Matchers::ActiveModel::HaveErrors
6
7
  # Stores an expectation of receiving an error for a specified attribute, as
7
8
  # well as zero or more message expectations.
8
- #
9
+ #
9
10
  # @since 1.0.0
10
11
  #
11
12
  # @see MessageExpectation
12
13
  class ErrorExpectation < Struct.new :attribute, :expected, :received
13
14
  # Extra instance methods for the :messages array.
14
- #
15
- # @private
15
+ #
16
+ # @api private
16
17
  module MessagesMethods
17
- # @return [Array<MessageExpectation>] messages that are expected
18
+ # @return [Array<MessageExpectation>] Messages that are expected.
18
19
  def expected
19
20
  select { |message| message.expected }
20
21
  end # method expected
21
22
 
22
- # @return [Array<MessageExpectation>] messages that are expected but have
23
- # not been received
23
+ # @return [Array<MessageExpectation>] Messages that are expected but have
24
+ # not been received.
24
25
  def missing
25
26
  select { |message| message.expected && !message.received }
26
27
  end # method missing
27
28
 
28
- # @return [Array<MessageExpectation>] messages that have been received
29
+ # @return [Array<MessageExpectation>] Messages that have been received.
29
30
  def received
30
31
  select { |message| message.received }
31
32
  end # method received
32
33
  end # module
33
34
 
34
- # @param [String, Symbol] attribute the attribute for which an error is
35
- # expected to be or has been received
36
- # @param [Boolean] expected whether an error is expected for the specified
37
- # attribute
38
- # @param [Boolean] received whether an error has been received for the
39
- # specified attribute
35
+ # @param [String, Symbol] attribute The attribute for which an error is
36
+ # expected to be or has been received.
37
+ # @param [Boolean] expected Whether an error is expected for the specified
38
+ # attribute.
39
+ # @param [Boolean] received Whether an error has been received for the
40
+ # specified attribute.
40
41
  def initialize attribute, expected = true, received = false
41
42
  super attribute.intern, expected, received
42
43
 
@@ -48,9 +49,9 @@ module RSpec::SleepingKingStudios::Matchers::ActiveModel::HaveErrors
48
49
 
49
50
  # The message expectations for the specified attribute. The returned array
50
51
  # supports several additional methods: #expected, #missing, and #received.
51
- #
52
+ #
52
53
  # @return [Array<MessageExpectation>]
53
- #
54
+ #
54
55
  # @see MessagesMethods#expected
55
56
  # @see MessagesMethods#missing
56
57
  # @see MessagesMethods#received
@@ -5,10 +5,10 @@ require 'rspec/sleeping_king_studios/matchers/active_model'
5
5
  module RSpec::SleepingKingStudios::Matchers::ActiveModel::HaveErrors
6
6
  # Stores an expectation of receiving a specified error message.
7
7
  class MessageExpectation < Struct.new :message, :expected, :received
8
- # @param [String] message the message which is expected to be or has been
9
- # received
10
- # @param [Boolean] expected whether the message is expected
11
- # @param [Boolean] received whether the message has been received
8
+ # @param [String] message The message which is expected to be or has been
9
+ # received.
10
+ # @param [Boolean] expected Whether the message is expected.
11
+ # @param [Boolean] received Whether the message has been received.
12
12
  def initialize message, expected = true, received = false
13
13
  super message, expected, received
14
14
  end # constructor
@@ -18,14 +18,12 @@ module RSpec::SleepingKingStudios::Matchers::ActiveModel
18
18
  def initialize
19
19
  super
20
20
 
21
- # The error and message expectations set up through #on and
21
+ # The error and message expectations are set up through #on and
22
22
  # #with_message.
23
23
  @error_expectations = []
24
24
  end # constructor
25
25
 
26
- # Generates a description of the matcher expectation.
27
- #
28
- # @return [String] The matcher description.
26
+ # (see BaseMatcher#description)
29
27
  def description
30
28
  message = 'have errors'
31
29
 
@@ -51,11 +49,11 @@ module RSpec::SleepingKingStudios::Matchers::ActiveModel
51
49
  # checks the errors on the object against the expected errors and messages
52
50
  # from #on and #with_message, if any.
53
51
  #
54
- # @param [Object] actual the object to test against the matcher
52
+ # @param [Object] actual The object to test against the matcher.
55
53
  #
56
- # @return [Boolean] true if the object responds to :valid? and is valid
54
+ # @return [Boolean] True if the object responds to :valid? and is valid
57
55
  # or object.errors does not match the specified errors and messages (if
58
- # any); otherwise false
56
+ # any); otherwise false.
59
57
  #
60
58
  # @see #matches?
61
59
  def does_not_match? actual
@@ -70,11 +68,12 @@ module RSpec::SleepingKingStudios::Matchers::ActiveModel
70
68
  # checks the errors on the object against the expected errors and messages
71
69
  # from #on and #with_message, if any.
72
70
  #
73
- # @param [Object] actual the object to test against the matcher
71
+ # @param [Object] actual The object to test against the matcher.
74
72
  #
75
- # @return [Boolean] true if the object responds to :valid?, is not valid,
73
+ # @return [Boolean] True if the object responds to :valid?, is not valid,
76
74
  # and object.errors matches the specified errors and messages (if any);
77
- # otherwise false
75
+ # otherwise false.
76
+ #
78
77
  # @see RSpec::SleepingKingStudios::Matchers::BaseMatcher#matches?
79
78
  def matches? actual
80
79
  super
@@ -103,11 +102,11 @@ module RSpec::SleepingKingStudios::Matchers::ActiveModel
103
102
  # If the actual object does not have an error on the that attribute with
104
103
  # the specified message, #matches? will return false.
105
104
  #
106
- # @param [String, Regexp] message the expected error message. If a string,
105
+ # @param [String, Regexp] message The expected error message. If a string,
107
106
  # matcher will check for an exact match; if a regular expression, matcher
108
- # will check if the message matches the regexp
107
+ # will check if the message matches the regexp.
109
108
  #
110
- # @raise [ArgumentError] if no error attribute has been added
109
+ # @raise [ArgumentError] If no error attribute has been added.
111
110
  #
112
111
  # @return [HaveErrorsMatcher] self
113
112
  #
@@ -137,7 +136,7 @@ module RSpec::SleepingKingStudios::Matchers::ActiveModel
137
136
  end # method with_message
138
137
  alias_method :with, :with_messages
139
138
 
140
- # @see BaseMatcher#failure_message
139
+ # (see BaseMatcher#failure_message)
141
140
  def failure_message
142
141
  # Failure cases:
143
142
  # * object is not a model ("to respond to valid")
@@ -154,7 +153,7 @@ module RSpec::SleepingKingStudios::Matchers::ActiveModel
154
153
  end # if-elsif-else
155
154
  end # method failure_message
156
155
 
157
- # @see BaseMatcher#failure_message_when_negated
156
+ # (see BaseMatcher#failure_message_when_negated)
158
157
  def failure_message_when_negated
159
158
  # Failure cases:
160
159
  # * object is not a model ("to respond to valid")
@@ -4,16 +4,15 @@ require 'rspec/sleeping_king_studios/matchers'
4
4
 
5
5
  module RSpec::SleepingKingStudios::Matchers
6
6
  # Minimal implementation of the RSpec matcher interface.
7
- #
7
+ #
8
8
  # @since 1.0.0
9
9
  class BaseMatcher
10
10
  include RSpec::Matchers::Pretty
11
11
 
12
12
  attr_reader :actual
13
13
 
14
- # A short string that describes the purpose of the matcher. Borrowed from
15
- # RSpec::Matchers::BuiltIn::BaseMatcher.
16
- #
14
+ # A short string that describes the purpose of the matcher.
15
+ #
17
16
  # @return [String] the matcher description
18
17
  def description
19
18
  return name_to_sentence unless defined?(@expected)
@@ -23,9 +22,9 @@ module RSpec::SleepingKingStudios::Matchers
23
22
  # Inverse of #matches? method.
24
23
  #
25
24
  # @param [Object] actual the object to test against the matcher
26
- #
25
+ #
27
26
  # @return [Boolean] false if the object matches, otherwise true
28
- #
27
+ #
29
28
  # @see #matches?
30
29
  def does_not_match? actual
31
30
  !matches?(actual)
@@ -35,7 +34,7 @@ module RSpec::SleepingKingStudios::Matchers
35
34
  # Invoked by RSpec expectations.
36
35
  #
37
36
  # @param [Object] actual the object to test against the matcher
38
- #
37
+ #
39
38
  # @return [Boolean] true if the object matches, otherwise false
40
39
  def matches? actual
41
40
  @actual = actual
@@ -4,12 +4,11 @@ require 'rspec/sleeping_king_studios/matchers/built_in'
4
4
  require 'sleeping_king_studios/tools/enumerable_tools'
5
5
 
6
6
  module RSpec::SleepingKingStudios::Matchers::BuiltIn
7
+ # Extensions to the built-in RSpec #be_kind_of matcher.
7
8
  class BeAKindOfMatcher < RSpec::Matchers::BuiltIn::BeAKindOf
8
9
  include SleepingKingStudios::Tools::EnumerableTools
9
10
 
10
- # Generates a description of the matcher expectation.
11
- #
12
- # @return [String] The matcher description.
11
+ # (see BaseMatcher#description)
13
12
  def description
14
13
  message = "be #{type_string}"
15
14
  end # method description
@@ -18,22 +17,22 @@ module RSpec::SleepingKingStudios::Matchers::BuiltIn
18
17
  # expected value of nil as a shortcut for expecting an instance of
19
18
  # NilClass.
20
19
  #
21
- # @param [Module, nil, Array<Module, nil>] expected the type or types to
22
- # check the object against
23
- # @param [Object] actual the object to check
20
+ # @param [Module, nil, Array<Module, nil>] expected The type or types to
21
+ # check the object against.
22
+ # @param [Object] actual The object to check.
24
23
  #
25
- # @return [Boolean] true if the object matches one of the specified types,
26
- # otherwise false
24
+ # @return [Boolean] True if the object matches one of the specified types,
25
+ # otherwise false.
27
26
  def match expected, actual
28
27
  match_type? expected
29
28
  end # method match
30
29
 
31
- # @see BaseMatcher#failure_message
30
+ # (see BaseMatcher#failure_message)
32
31
  def failure_message
33
32
  "expected #{@actual.inspect} to be #{type_string}"
34
33
  end # method failure_message
35
34
 
36
- # @see BaseMatcher#failure_message_when_negated
35
+ # (see BaseMatcher#failure_message_when_negated)
37
36
  def failure_message_when_negated
38
37
  "expected #{@actual.inspect} not to be #{type_string}"
39
38
  end # method failure_message_when_negated
@@ -3,22 +3,25 @@
3
3
  require 'rspec/sleeping_king_studios/matchers/built_in'
4
4
 
5
5
  module RSpec::SleepingKingStudios::Matchers::BuiltIn
6
+ # Extensions to the built-in RSpec #include matcher.
6
7
  class IncludeMatcher < RSpec::Matchers::BuiltIn::Include
7
8
  # @param [Array<Hash, Proc, Object>] expected the items expected to be
8
9
  # matched by the actual object
9
10
  #
10
- # @yield if a block is provided, the block is converted to a proc and
11
- # appended to the item expectations
12
- # @yieldparam [Object] item an item from the actual object; yield(item)
11
+ # @yield If a block is provided, the block is converted to a proc and
12
+ # appended to the item expectations.
13
+ # @yieldparam [Object] item An item from the actual object; yield(item)
13
14
  # should return true if and only if the item matches the desired
14
- # predicate
15
+ # predicate.
15
16
  def initialize *expected, &block
16
17
  expected << block if block_given?
17
18
 
18
19
  super *expected
19
20
  end # constructor
20
21
 
21
- # @private
22
+ # @api private
23
+ #
24
+ # Converts the expected item to a human-readable string.
22
25
  def to_word expected_item
23
26
  case
24
27
  when is_matcher_with_description?(expected_item)
@@ -30,7 +33,7 @@ module RSpec::SleepingKingStudios::Matchers::BuiltIn
30
33
  end # case
31
34
  end # method to_word
32
35
 
33
- # @see BaseMatcher#failure_message
36
+ # (see BaseMatcher#failure_message)
34
37
  def failure_message
35
38
  message = super
36
39
 
@@ -39,7 +42,7 @@ module RSpec::SleepingKingStudios::Matchers::BuiltIn
39
42
  message
40
43
  end # method failure_message_for_should
41
44
 
42
- # @see BaseMatcher#failure_message_when_negated
45
+ # (see BaseMatcher#failure_message_when_negated)
43
46
  def failure_message_when_negated
44
47
  message = super
45
48
 
@@ -7,6 +7,7 @@ require 'sleeping_king_studios/tools/enumerable_tools'
7
7
  require 'sleeping_king_studios/tools/string_tools'
8
8
 
9
9
  module RSpec::SleepingKingStudios::Matchers::BuiltIn
10
+ # Extensions to the built-in RSpec #respond_to matcher.
10
11
  class RespondToMatcher < RSpec::Matchers::BuiltIn::RespondTo
11
12
  include RSpec::SleepingKingStudios::Matchers::Shared::MatchParameters
12
13
  include SleepingKingStudios::Tools::EnumerableTools
@@ -18,14 +19,15 @@ module RSpec::SleepingKingStudios::Matchers::BuiltIn
18
19
  super(*expected)
19
20
  end # constructor
20
21
 
21
- # Generates a description of the matcher expectation.
22
- #
23
- # @return [String] The matcher description.
22
+ # (see BaseMatcher#description)
24
23
  def description
25
24
  expected_message = format_expected_arguments
26
25
  "respond to #{pp_names}#{expected_message.empty? ? '' : " with #{expected_message}"}"
27
26
  end # method description
28
27
 
28
+ # Adds a parameter count expectation and/or one or more keyword
29
+ # expectations.
30
+ #
29
31
  # @overload with count
30
32
  # Adds a parameter count expectation.
31
33
  #
@@ -34,7 +36,7 @@ module RSpec::SleepingKingStudios::Matchers::BuiltIn
34
36
  #
35
37
  # @return [RespondToMatcher] self
36
38
  # @overload with *keywords
37
- # Adds one or more keyword expectations (Ruby 2.0 only).
39
+ # Adds one or more keyword expectations.
38
40
  #
39
41
  # @param [Array<String, Symbol>] keywords List of keyword arguments
40
42
  # accepted by the method.
@@ -42,7 +44,7 @@ module RSpec::SleepingKingStudios::Matchers::BuiltIn
42
44
  # @return [RespondToMatcher] self
43
45
  # @overload with count, *keywords
44
46
  # Adds a parameter count expectation and one or more keyword
45
- # expectations (Ruby 2.0 only).
47
+ # expectations.
46
48
  #
47
49
  # @param [Integer, Range, nil] count (optional) The number of expected
48
50
  # parameters.
@@ -65,8 +67,9 @@ module RSpec::SleepingKingStudios::Matchers::BuiltIn
65
67
  @expected_block = true
66
68
  self
67
69
  end # method with_a_block
70
+ alias_method :and_a_block, :with_a_block
68
71
 
69
- # @see BaseMatcher#failure_message
72
+ # (see BaseMatcher#failure_message)
70
73
  def failure_message
71
74
  @failing_method_names ||= []
72
75
  methods, messages = @failing_method_names, []
@@ -82,7 +85,7 @@ module RSpec::SleepingKingStudios::Matchers::BuiltIn
82
85
  messages.join "\n"
83
86
  end # method failure_message
84
87
 
85
- # @see BaseMatcher#failure_message_when_negated
88
+ # (see BaseMatcher#failure_message_when_negated)
86
89
  def failure_message_when_negated
87
90
  @failing_method_names ||= []
88
91
  methods, messages = @failing_method_names, []
@@ -3,5 +3,6 @@
3
3
  require 'rspec/sleeping_king_studios/matchers'
4
4
 
5
5
  module RSpec::SleepingKingStudios::Matchers
6
+ # Extensions to the built-in RSpec matchers.
6
7
  module BuiltIn; end
7
8
  end # module
@@ -8,30 +8,28 @@ module RSpec::SleepingKingStudios::Matchers::Core
8
8
  #
9
9
  # @since 1.0.0
10
10
  class BeBooleanMatcher < RSpec::SleepingKingStudios::Matchers::BaseMatcher
11
- # Generates a description of the matcher expectation.
12
- #
13
- # @return [String] The matcher description.
11
+ # (see BaseMatcher#description)
14
12
  def description
15
13
  'be true or false'
16
14
  end # method description
17
15
 
18
16
  # Checks if the object is true or false.
19
17
  #
20
- # @param [Object] actual the object to check
18
+ # @param [Object] actual The object to check.
21
19
  #
22
- # @return [Boolean] true if the object is true or false, otherwise false
20
+ # @return [Boolean] True if the object is true or false, otherwise false.
23
21
  def matches? actual
24
22
  super
25
23
 
26
24
  true === actual || false === actual
27
25
  end # method matches?
28
26
 
29
- # @see BaseMatcher#failure_message
27
+ # (see BaseMatcher#failure_message)
30
28
  def failure_message
31
29
  "expected #{@actual.inspect} to be true or false"
32
30
  end # method failure_message
33
31
 
34
- # @see BaseMatcher#failure_message_when_negated
32
+ # (see BaseMatcher#failure_message_when_negated)
35
33
  def failure_message_when_negated
36
34
  "expected #{@actual.inspect} not to be true or false"
37
35
  end # method failure_message_when_negated
@@ -16,9 +16,7 @@ module RSpec::SleepingKingStudios::Matchers::Core
16
16
  include SleepingKingStudios::Tools::EnumerableTools
17
17
  include SleepingKingStudios::Tools::StringTools
18
18
 
19
- # Generates a description of the matcher expectation.
20
- #
21
- # @return [String] The matcher description.
19
+ # (see BaseMatcher#description)
22
20
  def description
23
21
  expected_message = format_expected_arguments
24
22
  "construct#{expected_message.empty? ? '' : " with #{expected_message}"}"
@@ -28,10 +26,10 @@ module RSpec::SleepingKingStudios::Matchers::Core
28
26
  # checks the parameters expected by #initialize against the expected
29
27
  # parameters, if any.
30
28
  #
31
- # @param [Object] actual the object to check
29
+ # @param [Object] actual The object to check.
32
30
  #
33
- # @return [Boolean] true if the object responds to :new and accepts the
34
- # specified parameters for #initialize; otherwise false
31
+ # @return [Boolean] True if the object responds to :new and accepts the
32
+ # specified parameters for #initialize; otherwise false.
35
33
  def matches? actual
36
34
  @actual = actual
37
35
  @failing_method_reasons = {}
@@ -40,30 +38,33 @@ module RSpec::SleepingKingStudios::Matchers::Core
40
38
  matches_keywords?(actual)
41
39
  end # method matches?
42
40
 
41
+ # Adds a parameter count expectation and/or one or more keyword
42
+ # expectations.
43
+ #
43
44
  # @overload with(count)
44
- # Adds a parameter count expectation and removes any keyword expectations
45
- # (Ruby 2.0+ only).
45
+ # Adds a parameter count expectation and removes any keyword
46
+ # expectations.
46
47
  #
47
- # @param [Integer, Range] count the number of expected parameters
48
+ # @param [Integer, Range] count The number of expected parameters.
48
49
  #
49
50
  # @return [ConstructMatcher] self
50
51
  #
51
52
  # @overload with(count, *keywords)
52
- # Adds a parameter count expectation and one or more keyword expectations
53
- # (Ruby 2.0 only).
53
+ # Adds a parameter count expectation and one or more keyword
54
+ # expectations.
54
55
  #
55
- # @param [Integer, Range] count the number of expected parameters
56
- # @param [Array<String, Symbol>] keywords list of keyword arguments
57
- # accepted by the method
56
+ # @param [Integer, Range] count The number of expected parameters.
57
+ # @param [Array<String, Symbol>] keywords List of keyword arguments
58
+ # accepted by the method.
58
59
  #
59
60
  # @return [ConstructMatcher] self
60
61
  #
61
62
  # @overload with(*keywords)
62
63
  # Removes a parameter count expectation (if any) and adds one or more
63
- # keyword expectations (Ruby 2.0 only).
64
+ # keyword expectations.
64
65
  #
65
- # @param [Array<String, Symbol>] keywords list of keyword arguments
66
- # accepted by the method
66
+ # @param [Array<String, Symbol>] keywords List of keyword arguments
67
+ # accepted by the method.
67
68
  #
68
69
  # @return [ConstructMatcher] self
69
70
  def with *keywords
@@ -82,14 +83,14 @@ module RSpec::SleepingKingStudios::Matchers::Core
82
83
  end # method argument
83
84
  alias_method :arguments, :argument
84
85
 
85
- # @see BaseMatcher#failure_message
86
+ # (see BaseMatcher#failure_message)
86
87
  def failure_message
87
88
  message = "expected #{@actual.inspect} to construct"
88
89
  message << " with arguments:\n#{format_errors}" if @actual.respond_to?(:new)
89
90
  message
90
91
  end # method failure_message
91
92
 
92
- # @see BaseMatcher#failure_message_when_negated
93
+ # (see BaseMatcher#failure_message_when_negated)
93
94
  def failure_message_when_negated
94
95
  message = "expected #{@actual.inspect} not to construct"
95
96
  unless (formatted = format_expected_arguments).empty?
@@ -6,41 +6,40 @@ require 'rspec/sleeping_king_studios/matchers/shared/match_property'
6
6
 
7
7
  module RSpec::SleepingKingStudios::Matchers::Core
8
8
  # Matcher for testing whether an object has a specific property, e.g.
9
- # responds to :property and :property= and :property= updates the value of
10
- # :property.
9
+ # responds to #property and #property= and has the specified value for
10
+ # #property.
11
11
  #
12
12
  # @since 1.0.0
13
13
  class HavePropertyMatcher < RSpec::SleepingKingStudios::Matchers::BaseMatcher
14
14
  include RSpec::SleepingKingStudios::Matchers::Shared::MatchProperty
15
15
 
16
- # Generates a description of the matcher expectation.
17
- #
18
- # @return [String] The matcher description.
16
+ # (see BaseMatcher#description)
19
17
  def description
20
18
  value_message = value_to_string
21
19
  "have property :#{@expected}#{@value_set ? " with value #{value_message}" : ''}"
22
20
  end # method description
23
21
 
24
- # @param [String, Symbol] expected the property to check for on the actual
25
- # object
22
+ # @param [String, Symbol] expected The property to check for on the actual
23
+ # object.
26
24
  def initialize expected
27
25
  @expected = expected.intern
28
26
  end # method initialize
29
27
 
28
+ # (see BaseMatcher#does_not_match?)
30
29
  def does_not_match? actual
31
30
  super
32
31
 
33
32
  matches_property?(:none?)
34
33
  end # method does_not_match?
35
34
 
36
- # Checks if the object responds to :expected and :expected=. Additionally,
35
+ # Checks if the object responds to #expected and #expected=. Additionally,
37
36
  # if a value expectation is set, compares the result of calling :expected
38
37
  # to the value.
39
38
  #
40
- # @param [Object] actual the object to check
39
+ # @param [Object] actual The object to check.
41
40
  #
42
- # @return [Boolean] true if the object responds to :expected and
43
- # :expected= and matches the value expectation (if any); otherwise false
41
+ # @return [Boolean] true If the object responds to #expected and
42
+ # #expected= and matches the value expectation (if any); otherwise false.
44
43
  def matches? actual
45
44
  super
46
45
 
@@ -48,9 +47,9 @@ module RSpec::SleepingKingStudios::Matchers::Core
48
47
  end # method matches?
49
48
 
50
49
  # Sets a value expectation. The matcher will compare the value to the
51
- # result of calling :property.
50
+ # result of calling #property.
52
51
  #
53
- # @param [Object] value the value to set and then compare
52
+ # @param [Object] value The value to set and then compare.
54
53
  #
55
54
  # @return [HavePropertyMatcher] self
56
55
  def with value
@@ -60,7 +59,7 @@ module RSpec::SleepingKingStudios::Matchers::Core
60
59
  end # method with
61
60
  alias_method :with_value, :with
62
61
 
63
- # @see BaseMatcher#failure_message
62
+ # (see BaseMatcher#failure_message)
64
63
  def failure_message
65
64
  methods = []
66
65
  methods << ":#{@expected}" unless @matches_reader
@@ -77,7 +76,7 @@ module RSpec::SleepingKingStudios::Matchers::Core
77
76
  message
78
77
  end # failure_message
79
78
 
80
- # @see BaseMatcher#failure_message_when_negated
79
+ # (see BaseMatcher#failure_message_when_negated)
81
80
  def failure_message_when_negated
82
81
  methods = []
83
82
  methods << ":#{@expected}" if @matches_reader
@@ -12,28 +12,26 @@ module RSpec::SleepingKingStudios::Matchers::Core
12
12
  class HaveReaderMatcher < RSpec::SleepingKingStudios::Matchers::BaseMatcher
13
13
  include RSpec::SleepingKingStudios::Matchers::Shared::MatchProperty
14
14
 
15
- # Generates a description of the matcher expectation.
16
- #
17
- # @return [String] The matcher description.
15
+ # (see BaseMatcher#description)
18
16
  def description
19
17
  value_message = value_to_string
20
18
  "have reader :#{@expected}#{@value_set ? " with value #{value_message}" : ''}"
21
19
  end # method description
22
20
 
23
- # @param [String, Symbol] expected the property to check for on the actual
24
- # object
21
+ # @param [String, Symbol] expected The property to check for on the actual
22
+ # object.
25
23
  def initialize expected
26
24
  @expected = expected.intern
27
25
  end # method initialize
28
26
 
29
- # Checks if the object responds to :expected. Additionally, if a value
30
- # expectation is set, compares the value of :expected to the specified
27
+ # Checks if the object responds to #expected. Additionally, if a value
28
+ # expectation is set, compares the value of #expected to the specified
31
29
  # value.
32
30
  #
33
- # @param [Object] actual the object to check
31
+ # @param [Object] actual The object to check.
34
32
  #
35
- # @return [Boolean] true if the object responds to :expected and matches
36
- # the value expectation (if any); otherwise false
33
+ # @return [Boolean] true If the object responds to #expected and matches
34
+ # the value expectation (if any); otherwise false.
37
35
  def matches? actual
38
36
  super
39
37
 
@@ -41,9 +39,9 @@ module RSpec::SleepingKingStudios::Matchers::Core
41
39
  end # method matches?
42
40
 
43
41
  # Sets a value expectation. The matcher will compare the value from
44
- # :property with the specified value.
42
+ # #property with the specified value.
45
43
  #
46
- # @param [Object] value the value to compare
44
+ # @param [Object] value The value to compare.
47
45
  #
48
46
  # @return [HaveReaderMatcher] self
49
47
  def with value
@@ -53,7 +51,7 @@ module RSpec::SleepingKingStudios::Matchers::Core
53
51
  end # method with
54
52
  alias_method :with_value, :with
55
53
 
56
- # @see BaseMatcher#failure_message
54
+ # (see BaseMatcher#failure_message)
57
55
  def failure_message
58
56
  message = "expected #{@actual} to respond to :#{@expected}"
59
57
  message << " and return #{value_to_string}" if @value_set
@@ -67,7 +65,7 @@ module RSpec::SleepingKingStudios::Matchers::Core
67
65
  message
68
66
  end # method failure_message
69
67
 
70
- # @see BaseMatcher#failure_message_when_negated
68
+ # (see BaseMatcher#failure_message_when_negated)
71
69
  def failure_message_when_negated
72
70
  message = "expected #{@actual} not to respond to :#{@expected}"
73
71
  message << " and return #{value_to_string}" if @value_set
@@ -3,5 +3,6 @@
3
3
  require 'rspec/sleeping_king_studios/matchers'
4
4
 
5
5
  module RSpec::SleepingKingStudios::Matchers
6
+ # All-purpose matchers for use with objects and built-in types.
6
7
  module Core; end
7
8
  end # module
@@ -3,13 +3,23 @@
3
3
  module RSpec
4
4
  module SleepingKingStudios
5
5
  # @api private
6
+ #
7
+ # The current version of the gem.
8
+ #
9
+ # @see http://semver.org/
6
10
  module Version
11
+ # Major version.
7
12
  MAJOR = 2
13
+ # Minor version.
8
14
  MINOR = 0
15
+ # Patch version.
9
16
  PATCH = 0
10
- PRERELEASE = 'beta'
11
- BUILD = 2
17
+ # Prerelease version.
18
+ PRERELEASE = 'rc'
19
+ # Build metatada.
20
+ BUILD = 0
12
21
 
22
+ # Generates the gem version string from the Version constants.
13
23
  def self.to_gem_version
14
24
  str = "#{MAJOR}.#{MINOR}.#{PATCH}"
15
25
 
@@ -3,6 +3,7 @@
3
3
  require 'rspec/core'
4
4
 
5
5
  module RSpec
6
+ # Hic Iacet Arthurus, Rex Quondam, Rexque Futurus.
6
7
  module SleepingKingStudios; end
7
8
  end # module
8
9
 
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: 2.0.0.beta.2
4
+ version: 2.0.0.rc.0
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: 2014-11-03 00:00:00.000000000 Z
11
+ date: 2014-11-15 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: '3.1'
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: '3.1'
26
+ version: '3.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: sleeping_king_studios-tools
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -122,12 +122,14 @@ files:
122
122
  - README.md
123
123
  - lib/rspec/sleeping_king_studios.rb
124
124
  - lib/rspec/sleeping_king_studios/all.rb
125
+ - lib/rspec/sleeping_king_studios/concerns.rb
126
+ - lib/rspec/sleeping_king_studios/concerns/all.rb
127
+ - lib/rspec/sleeping_king_studios/concerns/shared_example_group.rb
125
128
  - lib/rspec/sleeping_king_studios/configuration.rb
126
129
  - lib/rspec/sleeping_king_studios/examples.rb
127
130
  - lib/rspec/sleeping_king_studios/examples/all.rb
128
131
  - lib/rspec/sleeping_king_studios/examples/property_examples.rb
129
132
  - lib/rspec/sleeping_king_studios/examples/rspec_matcher_examples.rb
130
- - lib/rspec/sleeping_king_studios/examples/shared_example_group.rb
131
133
  - lib/rspec/sleeping_king_studios/matchers.rb
132
134
  - lib/rspec/sleeping_king_studios/matchers/active_model.rb
133
135
  - lib/rspec/sleeping_king_studios/matchers/active_model/all.rb
@@ -171,8 +173,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
173
  version: 1.3.1
172
174
  requirements: []
173
175
  rubyforge_project:
174
- rubygems_version: 2.4.2
176
+ rubygems_version: 2.4.3
175
177
  signing_key:
176
178
  specification_version: 4
177
179
  summary: A collection of RSpec patches and custom matchers.
178
180
  test_files: []
181
+ has_rdoc: