rspec-sleeping_king_studios 2.6.0 → 2.7.0.rc.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c218158ac4229d6cd818cec2837832e27086b1407bc54a90b43921be5ad6ef2d
4
- data.tar.gz: 1afecef7b021d634b9203b8bab2c72d2faed3498a92eac0081ffab0f2ee4a674
3
+ metadata.gz: 6c41b78a115cc4c2c5d876a2841738696c233e394ff10a965200636bb9146cb4
4
+ data.tar.gz: 51b7c5c228673431eb1c550cdf51291966527ff99664feff835f5b9455534aa0
5
5
  SHA512:
6
- metadata.gz: b59b280dd97fd18691887d504407c0a70e849a0e9cca3cff65f71078b155050eb0c2590cea2fb5cb192af8c3951f50798b8bc22a3832d58d679a761ab32f4b8a
7
- data.tar.gz: b71d3fb856bf0eecb962219edc68103b49b3d71e42699d677db42432f52ef67d1ac97e9232f51c01d807654f1e58d30ded38b9c66fb7ba27b55783d375c1271e
6
+ metadata.gz: e4680d113beb15829ad1af0cf6879d1d7ebc5a9764accab33fe847233328b8d70b5456cb64307bef4999b5c7cb95da48b867a008664e67b101a63cca2dff31cd
7
+ data.tar.gz: 3025e278333fb4aa95efb9473a11cb410b76a0f2e0adce1cb2b3709f20d6cb3b2f25e23fcd9c11468177f611aed7a3faaca89c96696a45c4c7379f04218a7603
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.7.0
4
+
5
+ ### Concerns
6
+
7
+ Implemented RSpec::SleepingKingStudios::Contract and the IncludeContract concern. These provide a mechanism for documenting and sharing specifications between projects.
8
+
9
+ ### Matchers
10
+
11
+ Renamed the `#alias_method` matcher to `#have_aliased_method`, and renamed the AliasMethodMatcher to HaveAliasedMethodMatcher. Using the older matcher will trigger a deprecation warning.
12
+
3
13
  ## 2.6.0
4
14
 
5
15
  Deprecated the DelegateMethod matcher. Use `rspec-mocks` expectations instead.
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, religion, or sexual identity
10
+ and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the
26
+ overall community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or
31
+ advances of any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email
35
+ address, without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official e-mail address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ merlin@sleepingkingstudios.com.
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series
86
+ of actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or
93
+ permanent ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within
113
+ the community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.0, available at
119
+ [https://www.contributor-covenant.org/version/2/0/code_of_conduct.html][v2.0].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available
126
+ at [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.0]: https://www.contributor-covenant.org/version/2/0/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/DEVELOPMENT.md CHANGED
@@ -1,9 +1,5 @@
1
1
  # Development Notes
2
2
 
3
- ## Version 2.6
4
-
5
- - Deprecate `delegate_method` matcher, `include` matcher with block.
6
-
7
3
  ## Version 3.0
8
4
 
9
5
  - Extract out Rails-specific matchers to RSpec::SleepingKingStudios::Rails.
data/README.md CHANGED
@@ -2,31 +2,38 @@
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
- ## Support
5
+ ## About
6
6
 
7
- RSpec::SleepingKingStudios is tested against RSpec 3.3 through 3.7.
7
+ ### Compatibility
8
8
 
9
- Currently, the following versions of Ruby are officially supported:
9
+ RSpec::SleepingKingStudios is tested against the following dependencies:
10
10
 
11
- * 2.4
12
- * 2.5
13
- * 2.6
11
+ - Ruby (MRI) 2.6 through 3.0
12
+ - RSpec versions 3.4 through 3.10
13
+ - ActiveModel versions 3.0 through 6.1
14
14
 
15
- For Ruby 2.0 support, use version 2.1 or earlier: `gem "rspec-sleeping_king_studios", "~> 2.1.1"`.
15
+ ### Documentation
16
16
 
17
- For RSpec 3.0 to 3.2 support, use version 2.2 or earlier: `gem "rspec-sleeping_king_studios", "~> 2.2.2"`.
17
+ Documentation is generated using [YARD](https://yardoc.org/), and can be generated locally using the `yard` gem.
18
18
 
19
- If you require a previous version of Ruby or RSpec, the 1.0 branch supports Ruby 1.9.3 and RSpec 2: `gem "rspec-sleeping_king_studios", "~> 1.0.1"`. However, changes from 2.0 and higher will not be backported.
19
+ ### License
20
20
 
21
- ## Contribute
21
+ Copyright (c) 2013-2021 Rob Smith
22
22
 
23
- ### GitHub
23
+ RSpec::SleepingKingStudios is released under the [MIT License](https://opensource.org/licenses/MIT).
24
+
25
+ ### Contribute
24
26
 
25
27
  The canonical repository for this gem is located at https://github.com/sleepingkingstudios/rspec-sleeping_king_studios.
26
28
 
27
- ### A Note From The Developer
29
+ To report a bug or submit a feature request, please use the [Issue Tracker](https://github.com/sleepingkingstudios/rspec-sleeping_king_studios/issues).
30
+
31
+ To contribute code, please fork the repository, make the desired updates, and then provide a [Pull Request](https://github.com/sleepingkingstudios/rspec-sleeping_king_studios/pulls). Pull requests must include appropriate tests for consideration, and all code must be properly formatted.
32
+
33
+ ### Code of Conduct
34
+
35
+ Please note that the `RSpec::SleepingKingStudios` project is released with a [Contributor Code of Conduct](https://github.com/sleepingkingstudios/rspec-sleeping_king_studios/blob/master/CODE_OF_CONDUCT.md). By contributing to this project, you agree to abide by its terms.
28
36
 
29
- Hi, I'm Rob Smith, a Ruby Engineer and the developer of this library. I use these tools every day, but they're not just written for me. If you find this project helpful in your own work, or if you have any questions, suggestions or critiques, please feel free to get in touch! I can be reached on GitHub (see above, and feel encouraged to submit bug reports or merge requests there) or via email at `merlin@sleepingkingstudios.com`. I look forward to hearing from you!
30
37
 
31
38
  ## Configuration
32
39
 
@@ -149,6 +156,113 @@ Sets the value of the named constant to the specified value within the context o
149
156
 
150
157
  Creates a new class with the specified base class and sets the value of the named constant to the created class within the context of the current example.
151
158
 
159
+ <a id="include-contract"></a>
160
+
161
+ ### Include Contract
162
+
163
+ ```ruby
164
+ require 'rspec/sleepingkingstudios/concerns/include_contract'
165
+ ```
166
+
167
+ Defines helpers for including reusable contracts in RSpec example groups.
168
+
169
+ Contracts are a mechanism for sharing tests between projects. For example, one library may define an interface or specification for a type of object, while a second library implements that object. By defining a contract and sharing that contract as part of the library, the developer ensures that any object that matches the contract has correctly implemented and conforms to the interface. This reduces duplication of tests and provides resiliency as an interface is developed over time and across versions of the library.
170
+
171
+ Mechanically speaking, each contract encapsulates a section of RSpec code. When the contract is included in a spec, that code is then injected into the spec. Writing a contract, therefore, is no different than writing any other RSpec specification - it is only the delivery mechanism that differs. A contract can be any object that responds to #to_proc; the simplest contract is therefore a Proc or lambda that contains some RSpec code.
172
+
173
+ Although the examples use bare `lambda`s, any object that responds to `#to_proc` can be used as a contract. See also [Contracts](#contracts), which provide an approach to defining contracts that makes documenting contracts much cleaner.
174
+
175
+ ```ruby
176
+ module ExampleContracts
177
+ # This contract asserts that the object has the Enumerable module as an
178
+ # ancestor, and that it responds to the #each method.
179
+ SHOULD_BE_ENUMERABLE_CONTRACT = lambda do
180
+ it 'should be Enumerable' do
181
+ expect(subject).to be_a Enumerable
182
+ end
183
+
184
+ it 'should respond to #each' do
185
+ expect(subject).to respond_to(:each).with(0).arguments
186
+ end
187
+ end
188
+ end
189
+
190
+ RSpec.describe Array do
191
+ extend RSpec::SleepingKingStudios::Concerns::IncludeContract
192
+
193
+ include_contract ExampleContracts::SHOULD_BE_ENUMERABLE_CONTRACT
194
+ end
195
+
196
+ RSpec.describe Hash do
197
+ extend RSpec::SleepingKingStudios::Concerns::IncludeContract
198
+ include ExampleContracts
199
+
200
+ include_contract 'should be enumerable'
201
+ end
202
+ ```
203
+
204
+ We can also write contracts that take parameters, allowing us to customize the expected behavior of the object.
205
+
206
+ ```ruby
207
+ module SerializerContracts
208
+ # This contract asserts that the serialized result has the expected values.
209
+ SHOULD_SERIALIZE_ATTRIBUTES_CONTRACT = lambda \
210
+ do |*attributes, **values, &block|
211
+ describe '#serialize' do
212
+ let(:serialized) { subject.serialize }
213
+
214
+ it { expect(subject).to respond_to(:serialize).with(0).arguments }
215
+
216
+ attributes.each do |attribute|
217
+ it "should serialize #{attribute}" do
218
+ expect(serialized[attribute]).to be == subject[attribute]
219
+ end
220
+ end
221
+
222
+ values.each do |attribute, value|
223
+ it "should serialize #{attribute}" do
224
+ expect(serialized[attribute]).to be == value
225
+ end
226
+ end
227
+
228
+ instance_exec(&block) if block
229
+ end
230
+ end
231
+ end
232
+
233
+ RSpec.describe CaptainPicard do
234
+ extend RSpec::SleepingKingStudios::Concerns::IncludeContract
235
+ include SerializerContracts
236
+
237
+ include_contract 'should serialize attributes',
238
+ :name,
239
+ :rank,
240
+ lights: 4 do
241
+ it 'should serialize the catchphrase' do
242
+ expect(serialized[:catchphrase]).to be == 'Make it so.'
243
+ end
244
+ end
245
+ end
246
+ ```
247
+
248
+ First, we pass the contract a series of attribute names. These are used to assert that the serialized attributes match the values on the original object.
249
+
250
+ Second, we pass the contract a set of attribute names and values. These are used to assert that the serialized attributes have the specified values.
251
+
252
+ Finally, we can pass the contract a block, which the contract then executes. Note that the block is executed in the context of our describe block, and thus can take advantage of our memoized #serialized helper method.
253
+
254
+ #### `.include_contract`
255
+
256
+ The `.include_contract` class method applies the contract to the current example group. It passes any additional arguments, keywords, or block to the contract implementation.
257
+
258
+ #### `.finclude_contract`
259
+
260
+ The `.finclude_contract` class method creates a new focused context inside the current example group and applies the contract to that context. If RSpec is configured to run only focused specs, then only the contract specs will be run. This is useful to quickly focus and run the specs from a particular contract.
261
+
262
+ #### `.xinclude_contract`
263
+
264
+ The `.xinclude_contract` class method creates a new skipped context inside the current example group and applies the contract to that context. The contract specs will not be run, but will instead be marked as pending. This is useful to temporarily disable the specs from a particular contract.
265
+
152
266
  ### Focus Examples
153
267
 
154
268
  require 'rspec/sleeping_king_studios/concerns/focus_examples'
@@ -328,158 +442,146 @@ A simplified syntax for re-using shared context or examples without having to ex
328
442
  require 'rspec/sleepingkingstudios/contract'
329
443
  ```
330
444
 
331
- A Contract encapsulates a set of RSpec expectations, which can then be used when defining a spec.
332
-
333
- ```ruby
334
- module GreetContract
335
- extend RSpec::SleepingKingStudios::Contract
445
+ An `RSpec::SleepingKingStudios::Contract` object encapsulates a partial RSpec specification. Unlike a traditional shared example group, a contract can be reused across projects, allowing a library to define an interface, provide a reference implementation, and publish tests that validate other implementations.
336
446
 
337
- describe '#greet' do
338
- it { expect(subject).to respond_to(:greet).with(1).argument }
447
+ Contracts can be added to an example group either through the `.apply` method or using the [Include Contract concern](#include-contract).
339
448
 
340
- it { expect(subject.greet 'programs').to be == 'Greetings, programs!' }
449
+ ```ruby
450
+ module ExampleContracts
451
+ # This contract asserts that the object has the Enumerable module as an
452
+ # ancestor, and that it responds to the #each method.
453
+ class ShouldBeEnumerableContract < RSpec::SleepingKingStudios::Contract
454
+ # @!method apply(example_group)
455
+ # Adds the contract to the example group.
456
+
457
+ contract do
458
+ it 'should be Enumerable' do
459
+ expect(subject).to be_a Enumerable
460
+ end
461
+
462
+ it 'should respond to #each' do
463
+ expect(subject).to respond_to(:each).with(0).arguments
464
+ end
465
+ end
341
466
  end
342
467
  end
343
468
 
344
- RSpec.describe Greeter do
345
- include GreetContract
469
+ RSpec.describe Array do
470
+ ExampleContracts::SHOULD_BE_ENUMERABLE_CONTRACT.apply(self)
346
471
  end
347
- ```
348
472
 
349
- Using a contract allows for examples to be shared between different specs, or even between projects.
350
-
351
- ### Contract Methods
352
-
353
- Not all RSpec methods are defined in a Contract. Only methods that define an example (`it`) or an example group (`context` or `describe`) can be used at the top level of a Contract. However, all RSpec methods (including methods that modify the current scope, such as `let` and the `before`/`around`/`after` filters) can be used inside an example group as normal.
354
-
355
- #### `::context`
356
-
357
- Defines an example group inside the contract. This example group will be defined on all specs that include the contract.
358
-
359
- ```ruby
360
- module TransformationContract
361
- extend RSpec::SleepingKingStudios::Contract
473
+ RSpec.describe Hash do
474
+ extend RSpec::SleepingKingStudios::Concerns::IncludeContract
475
+ include ExampleContracts
362
476
 
363
- context 'when the moon is full' do
364
- let(:moon_phase) { :full }
365
-
366
- it { expect(werewolf).to be_transformed }
367
- end
477
+ include_contract 'should be enumerable'
368
478
  end
369
479
  ```
370
480
 
371
- #### `::describe`
481
+ The major advantage a Contract object provides over using a Proc is documentation - tools such as YARD do not gracefully handle bare lambdas, while the functionality and requirements of a Contract can be specified using standard patterns, such as documenting the parameters passed to a contract using the #apply method.
372
482
 
373
- Defines an example group inside the contract. This example group will be defined on all specs that include the contract.
483
+ Contracts can be defined with parameters, which allows us to customize the expected behavior of the object.
374
484
 
375
485
  ```ruby
376
- module SilverContract
377
- extend RSpec::SleepingKingStudios::Contract
378
-
379
- describe 'with a silver weapon' do
380
- before(:example) do
381
- weapon.material = 'silver'
486
+ module SerializerContracts
487
+ # This contract asserts that the serialized result has the expected
488
+ # values.
489
+ #
490
+ # First, we pass the contract a series of attribute names. These are
491
+ # used to assert that the serialized attributes match the values on the
492
+ # original object.
493
+ #
494
+ # Second, we pass the contract a set of attribute names and values.
495
+ # These are used to assert that the serialized attributes have the
496
+ # specified values.
497
+ #
498
+ # Finally, we can pass the contract a block, which the contract then
499
+ # executes. Note that the block is executed in the context of our
500
+ # describe block, and thus can take advantage of our memoized
501
+ # #serialized helper method.
502
+ class ShouldSerializeAttributesContract
503
+ extend RSpec::SleepingKingStudios::Contract
504
+
505
+ contract do |*attributes, **values, &block|
506
+ describe '#serialize' do
507
+ let(:serialized) { subject.serialize }
508
+
509
+ it { expect(subject).to respond_to(:serialize).with(0).arguments }
510
+
511
+ attributes.each do |attribute|
512
+ it "should serialize #{attribute}" do
513
+ expect(serialized[attribute]).to be == subject[attribute]
514
+ end
515
+ end
516
+
517
+ values.each do |attribute, value|
518
+ it "should serialize #{attribute}" do
519
+ expect(serialized[attribute]).to be == value
520
+ end
521
+ end
522
+
523
+ instance_exec(&block) if block
524
+ end
382
525
  end
526
+ end
383
527
 
384
- it 'should kill the werewolf' do
385
- expect(attack(werewolf, weapon)).to change(werewolf, :alive?).to be false
528
+ RSpec.describe CaptainPicard do
529
+ SerializerContracts::ShouldSerializeAttributesContract.apply(
530
+ self,
531
+ :name,
532
+ :rank,
533
+ lights: 4) \
534
+ do
535
+ it 'should serialize the catchphrase' do
536
+ expect(serialized[:catchphrase]).to be == 'Make it so.'
386
537
  end
387
538
  end
388
539
  end
389
540
  ```
390
541
 
391
- #### `::it`
542
+ ### Contract Methods
392
543
 
393
- Defines an example inside the contract.
544
+ Each `RSpec::SleepingKingStudios::Contract` defines the following methods.
394
545
 
395
- ```ruby
396
- module HowlingContract
397
- extend RSpec::SleepingKingStudios::Contract
546
+ #### `.apply`
398
547
 
399
- it { expect(werewolf).to respond_to(:howl) }
400
- end
401
- ```
402
-
403
- #### `::shared_context`
404
-
405
- Defines a shared example group.
548
+ The `.apply` method adds the contract to the given example group, using the same internals used in the [Include Contract concern](#include-contract).
406
549
 
407
550
  ```ruby
408
- module MoonContract
409
- extend RSpec::SleepingKingStudios::Contract
410
-
411
- shared_context 'when the moon is full' do
412
- before(:example) { moon.phase = :full }
413
- end
551
+ RSpec.describe Book do
552
+ subject(:book) { Book.first }
553
+
554
+ SerializerContracts::ShouldSerializeAttributesContract.apply(
555
+ self,
556
+ :title,
557
+ author: book.author.as_json
558
+ )
414
559
  end
415
560
  ```
416
561
 
417
- **Note:** When the `Contract` is included in an RSpec example group, any shared example groups defined at the top level of a contract are also included in that example group, even outside of the contract itself. This may cause namespace collisions with shared example groups defined elsewhere in the example group or by other included contracts.
562
+ #### `.contract`
418
563
 
419
- #### `::shared_examples`
420
-
421
- Defines a shared example group.
564
+ The `.contract` method is used to define the contract implementation.
422
565
 
423
566
  ```ruby
424
- module HairContract
425
- extend RSpec::SleepingKingStudios::Contract
426
-
427
- shared_examples 'should be hairy' do
428
- describe '#hairy?' do
429
- it { expect(werewolf.hairy?).to be true }
567
+ module ModelContracts
568
+ class ShouldHavePrimaryKey
569
+ extend RSpec::SleepingKingStudios::Contract
570
+
571
+ contract do |primary_key_name: :id|
572
+ describe "##{primary_key_name}" do
573
+ it { expect(subject).to respond_to(primary_key_name).with(0).arguments }
574
+ end
430
575
  end
431
576
  end
432
577
  end
433
578
  ```
434
579
 
435
- **Note:** When the `Contract` is included in an RSpec example group, any shared example groups defined at the top level of a contract are also included in that example group, even outside of the contract itself. This may cause namespace collisions with shared example groups defined elsewhere in the example group or by other included contracts.
436
-
437
- ### Developing Contracts
438
-
439
- ```ruby
440
- module VampireContract
441
- extend RSpec::SleepingKingStudios::Contract
442
- extend RSpec::SleepingKingStudios::Contracts::Development
443
-
444
- fdescribe '#drink' do
445
- it { expect(drink 'blood').to be true }
446
-
447
- xit { expect(drink 'holy water').to be false }
448
- end
449
-
450
- pending
451
- end
452
- ```
453
-
454
- The `RSpec::SleepingKingStudios::Contracts::Development` module provides methods for defining focused or pending examples and example groups. These are intended for use when developing a contract, and should not be included in the final version. Having skipped or focused example groups in a shared contract can have unexpected effects when the contract is included by the end user.
455
-
456
- #### `::fcontext`
457
-
458
- Defines a focused example group inside the contract.
459
-
460
- #### `::fdescribe`
461
-
462
- Defines a focused example group inside the contract.
580
+ If a block is not given, it returns the current implementation as a `Proc` (or `nil`, if a contract implementation has not yet been set).
463
581
 
464
- #### `::fit`
582
+ #### `.to_proc`
465
583
 
466
- Defines a focused example inside the contract.
467
-
468
- #### `::pending`
469
-
470
- Marks the contract as pending.
471
-
472
- #### `::xcontext`
473
-
474
- Defines a skipped example group inside the contract.
475
-
476
- #### `::xdescribe`
477
-
478
- Defines a skipped example group inside the contract.
479
-
480
- #### `::xit`
481
-
482
- Defines a skipped example inside the contract.
584
+ The `.to_proc` method returns the current implementation as a `Proc` (or `nil`, if a contract implementation has not yet been set).
483
585
 
484
586
  ## Matchers
485
587
 
@@ -590,22 +692,6 @@ Now has additional chaining functionality to validate the number of arguments ac
590
692
 
591
693
  These matchers check core functionality, such as object boolean-ness, the existence of properties, and so on.
592
694
 
593
- #### `#alias_method` Matcher
594
-
595
- require 'rspec/sleeping_king_studios/matchers/core/alias_method'
596
-
597
- Checks if the object aliases the specified method with the specified other name. Matches if and only if the object responds to both the old and new method names, and if the old method and the new method are the same method.
598
-
599
- **How To Use**:
600
-
601
- expect(object).to alias_method(:old_method).as(:new_method)
602
-
603
- **Parameters:** Old method name. Expects the name of the method which has been aliased as a String or Symbol.
604
-
605
- **Chaining:**
606
-
607
- * **`#as`:** Required. Expects one String or Symbol, which is the name of the generated method.
608
-
609
695
  #### `#be_a_uuid` Matcher
610
696
 
611
697
  require 'rspec/sleeping_king_studios/matchers/core/be_a_uuid'
@@ -709,34 +795,21 @@ When the value does not match the expectation, the failure message will provide
709
795
  # + :errors => got ["Insufficient funds"]
710
796
  # ~ :status => expected 200, got 400
711
797
 
712
- #### `#delegate_method` Matcher
798
+ #### `#have_aliased_method` Matcher
713
799
 
714
- require 'rspec/sleeping_king_studios/matchers/core/delegate_method'
800
+ require 'rspec/sleeping_king_studios/matchers/core/have_aliased_method'
715
801
 
716
- Checks if the actual object forwards the specified method to the specified target. Can also specify that arguments, keywords, and/or a block are passed to the target, and that the object returns the specified values.
717
-
718
- **How To Use:**
719
-
720
- expect(object).to delegate_method(:my_method).to(target)
802
+ Checks if the object aliases the specified method with the specified other name. Matches if and only if the object responds to both the old and new method names, and if the old method and the new method are the same method.
721
803
 
722
- # Specify that arguments must be passed to the target.
723
- expect(object).to delegate_method(:my_method).to(target).with_arguments(:ichi, :ni, :san)
724
- expect(object).to delegate_method(:my_method).to(target).with_keywords(:foo => 'foo', :bar => 'bar')
725
- expect(object).to delegate_method(:my_method).to(target).with_a_block
804
+ **How To Use**:
726
805
 
727
- # Specify that the method must return the specified value.
728
- expect(object).to delegate_method(:my_method).to(target).and_return(true) # Called 1 time.
729
- expect(object).to delegate_method(:my_method).to(target).and_return(0, 1, 2) # Called 3 times.
806
+ expect(object).to have_aliased_method(:old_method).as(:new_method)
730
807
 
731
- **Parameters:** Method name. Expects a string or symbol that is a valid identifier.
808
+ **Parameters:** Old method name. Expects the name of the method which has been aliased as a String or Symbol.
732
809
 
733
810
  **Chaining:**
734
811
 
735
- * **`#to`:** Required. Expects an object, which is the target the method should be forwarded to.
736
- * **`#with_arguments`:** (also `and_arguments`) Expects one or more arguments. Specifies that when the method is called on the actual object with the given arguments, those arguments are then passed on to the target object when the method is called on the target.
737
- * **`#with_keywords:`** (also `and_keywords`) Expects a hash of keywords and values. Specifies that when the method is called on the actual object with the given keywords, those keywords are then passed on to the target object when the method is called on the target.
738
- * **`#with_a_block:`** (also `and_a_block`) Specifies that when the method is called on the actual object a block argument, thhe block is then passed on to the target object when the method is called on the target.
739
- * **`#and_return`:** Expects one or more arguments. The method is called on the actual object one time for each value passed into `#and_return`. Specifies that the return value of calling the method on the actual object is the corresponding value passed into `#and_return`.
812
+ * **`#as`:** Required. Expects one String or Symbol, which is the name of the generated method.
740
813
 
741
814
  #### `#have_changed` Matcher
742
815
 
@@ -1,5 +1,6 @@
1
1
  # lib/rspec/sleeping_king_studios/all.rb
2
2
 
3
3
  require 'rspec/sleeping_king_studios/concerns/all'
4
+ require 'rspec/sleeping_king_studios/contract'
4
5
  require 'rspec/sleeping_king_studios/examples/all'
5
6
  require 'rspec/sleeping_king_studios/matchers/all'