rspec-sleeping_king_studios 2.5.1 → 2.6.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: '096c6d91e990581772d795cedab4356ac8b07f84712d2a52e61fd715d47bfbc2'
4
- data.tar.gz: b2f7d0d162e1678be6a8ed0886ec1a9670321bbe64abc6a4f58a30b58e479725
3
+ metadata.gz: 8dd0e24014dae4f35a224e0c8d244b7e20d827d22c88ddf966f7ae201b1e148e
4
+ data.tar.gz: c3658bf3b7261942c9e166df38b7fdf5639688a074ca3a4cfb70992ae2698c8e
5
5
  SHA512:
6
- metadata.gz: c6bd478d39bd8ec15b23b12440ca82b839e652376cfb761b2fa56c1e6228c6ebfd0658156bc886c5ab58a31547801dc581e732be98392280f913beb240ee4b49
7
- data.tar.gz: ccc88ee28086629ab456961cdc746a8647c0c285d1d0e1734000abae8ece56532324f36e9568a64e00156186e4c5c0eeab1912f5029b7315ad717e855170447b
6
+ metadata.gz: 8fb97318df347582c4204f6a7f61e359d87069952f24ef72e928514e97d84fd82372d77300c7e1f01669fea239526ea6021d28be151f49177939ad0760755667
7
+ data.tar.gz: 2e1da21ffdd79e55c5891dd3a7f10247bb5aed761454ee1f7898275788cc77022ac3d0deefe3ac4a7470b0696d0ee6accb94809794b72f19a410bcd16dc4f787
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.6.0
4
+
5
+ Deprecated the DelegateMethod matcher. Use `rspec-mocks` expectations instead.
6
+
7
+ Deprecated the Include matcher with a block. Use the `satisfy` matcher instead.
8
+
9
+ ### Matchers
10
+
11
+ Updated RespondToMatcher to check the arity of `#initialize` when matching against a class and the method name is `:new`.
12
+
3
13
  ## 2.5.1
4
14
 
5
15
  Fixed a compatibility issue with Rails 6 configuration objects.
data/DEVELOPMENT.md CHANGED
@@ -2,25 +2,12 @@
2
2
 
3
3
  ## Version 2.6
4
4
 
5
- ### Features - Matchers
6
-
7
- - RespondToMatcher: |
8
- update to match core respond_to matcher
9
- - uses the signature from initialize to validate checks for new
10
- - see https://github.com/rspec/rspec-expectations/blob/master/Changelog.md
11
- subclass BeConstructibleMatcher from RespondTo ?
12
-
13
- ## Version 2.6+
14
-
15
- - DeepMatcher: |
16
- - indifferent - symbol/string keys
17
- - ordered - pre-sort arrays?
18
- - only homogenous arrays?
19
- - odd results unless equality comparison
5
+ - Deprecate `delegate_method` matcher, `include` matcher with block.
20
6
 
21
7
  ## Version 3.0
22
8
 
23
9
  - Extract out Rails-specific matchers to RSpec::SleepingKingStudios::Rails.
10
+ - Drop Rails 3 support.
24
11
  - Refactor property, constant matchers to Define$1Matcher.
25
12
  - HaveConstantMatcher, HaveReaderMatcher, HavePredicateMatcher, HavePropertyMatcher, HaveWriterMatcher.
26
13
  - Designate define_* macros as primary, have_* as aliases.
@@ -31,6 +18,12 @@
31
18
 
32
19
  ## Future Tasks
33
20
 
21
+ - DeepMatcher: |
22
+ - indifferent - symbol/string keys
23
+ - ordered - pre-sort arrays?
24
+ - only homogenous arrays?
25
+ - odd results unless equality comparison
26
+
34
27
  ### Bug Fixes
35
28
 
36
29
  - false negative on #alias_method?
data/README.md CHANGED
@@ -322,7 +322,166 @@ A simplified syntax for re-using shared context or examples without having to ex
322
322
 
323
323
  (also `::xwrap_context`) A shortcut for wrapping the context or examples in an automatically-skipped `describe` block, similar to the built-in `xit` and `xdescribe` methods.
324
324
 
325
- ## Custom Matchers
325
+ ## Contracts
326
+
327
+ ```ruby
328
+ require 'rspec/sleepingkingstudios/contract'
329
+ ```
330
+
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
336
+
337
+ describe '#greet' do
338
+ it { expect(subject).to respond_to(:greet).with(1).argument }
339
+
340
+ it { expect(subject.greet 'programs').to be == 'Greetings, programs!' }
341
+ end
342
+ end
343
+
344
+ RSpec.describe Greeter do
345
+ include GreetContract
346
+ end
347
+ ```
348
+
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
362
+
363
+ context 'when the moon is full' do
364
+ let(:moon_phase) { :full }
365
+
366
+ it { expect(werewolf).to be_transformed }
367
+ end
368
+ end
369
+ ```
370
+
371
+ #### `::describe`
372
+
373
+ Defines an example group inside the contract. This example group will be defined on all specs that include the contract.
374
+
375
+ ```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'
382
+ end
383
+
384
+ it 'should kill the werewolf' do
385
+ expect(attack(werewolf, weapon)).to change(werewolf, :alive?).to be false
386
+ end
387
+ end
388
+ end
389
+ ```
390
+
391
+ #### `::it`
392
+
393
+ Defines an example inside the contract.
394
+
395
+ ```ruby
396
+ module HowlingContract
397
+ extend RSpec::SleepingKingStudios::Contract
398
+
399
+ it { expect(werewolf).to respond_to(:howl) }
400
+ end
401
+ ```
402
+
403
+ #### `::shared_context`
404
+
405
+ Defines a shared example group.
406
+
407
+ ```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
414
+ end
415
+ ```
416
+
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.
418
+
419
+ #### `::shared_examples`
420
+
421
+ Defines a shared example group.
422
+
423
+ ```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 }
430
+ end
431
+ end
432
+ end
433
+ ```
434
+
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.
463
+
464
+ #### `::fit`
465
+
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.
483
+
484
+ ## Matchers
326
485
 
327
486
  To enable a custom matcher, simply require the associated file. Matchers can be required individually or by category:
328
487
 
@@ -17,7 +17,12 @@ module RSpec::SleepingKingStudios::Matchers::BuiltIn
17
17
  # should return true if and only if the item matches the desired
18
18
  # predicate.
19
19
  def initialize *expected, &block
20
- expected << block if block_given?
20
+ if block_given?
21
+ SleepingKingStudios::Tools::CoreTools
22
+ .deprecate('IncludeMatcher with a block')
23
+
24
+ expected << block
25
+ end
21
26
 
22
27
  if expected.empty? && !allow_empty_matcher?
23
28
  raise ArgumentError,
@@ -87,18 +87,18 @@ module RSpec::SleepingKingStudios::Matchers::BuiltIn
87
87
 
88
88
  method =
89
89
  begin
90
- actual.method(method_name)
90
+ if actual.is_a?(Class) && method_name.intern == :new
91
+ actual.instance_method(:initialize)
92
+ else
93
+ actual.method(method_name)
94
+ end
91
95
  rescue NameError
92
- nil
93
- end # unless
96
+ @failing_method_reasons[method_name] = {
97
+ :is_not_a_method => true
98
+ } # end hash
94
99
 
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
100
+ next false
101
+ end
102
102
 
103
103
  next true unless method_signature_expectation?
104
104
 
@@ -125,6 +125,8 @@ module RSpec::SleepingKingStudios::Matchers::Core
125
125
 
126
126
  # (see BaseMatcher#matches?)
127
127
  def matches? actual
128
+ SleepingKingStudios::Tools::CoreTools.deprecate('DelegateMethodMatcher')
129
+
128
130
  super
129
131
 
130
132
  raise ArgumentError.new('must specify a target') if @target.nil?
@@ -187,14 +189,22 @@ module RSpec::SleepingKingStudios::Matchers::Core
187
189
 
188
190
  private
189
191
 
190
- def call_method arguments, expected_return = DEFAULT_EXPECTED_RETURN
192
+ def call_method(arguments:, keywords:, expected_return: DEFAULT_EXPECTED_RETURN)
191
193
  if @expected_block
192
194
  @received_block = false
193
195
  block = ->(*args, **kwargs, &block) {}
194
196
 
195
- return_value = @actual.send(@expected, *arguments, &block)
197
+ if keywords.empty?
198
+ return_value = @actual.send(@expected, *arguments, &block)
199
+ else
200
+ return_value = @actual.send(@expected, *arguments, **keywords, &block)
201
+ end
196
202
  else
197
- return_value = @actual.send(@expected, *arguments)
203
+ if keywords.empty?
204
+ return_value = @actual.send(@expected, *arguments)
205
+ else
206
+ return_value = @actual.send(@expected, *arguments, **keywords)
207
+ end
198
208
  end
199
209
 
200
210
  @received_return_values << return_value
@@ -215,19 +225,22 @@ module RSpec::SleepingKingStudios::Matchers::Core
215
225
  def delegates_method?
216
226
  stub_target!
217
227
 
218
- args = @expected_arguments.dup
219
- args << @expected_keywords unless @expected_keywords.empty?
220
-
221
228
  if @expected_return_values.empty?
222
- call_method(args)
229
+ call_method(arguments: @expected_arguments, keywords: @expected_keywords)
223
230
  else
224
231
  @expected_return_values.each do |return_value|
225
- call_method(args, return_value)
232
+ call_method(arguments: @expected_arguments, keywords: @expected_keywords, expected_return: return_value)
226
233
  end # each
227
234
  end # if-else
228
235
 
229
236
  matcher = RSpec::Mocks::Matchers::HaveReceived.new(@expected)
230
- matcher = matcher.with(*args) unless args.empty?
237
+ if !@expected_arguments.empty? && !@expected_keywords.empty?
238
+ matcher = matcher.with(*@expected_arguments, **@expected_keywords)
239
+ elsif !@expected_arguments.empty?
240
+ matcher = matcher.with(*@expected_arguments)
241
+ elsif !@expected_keywords.empty?
242
+ matcher = matcher.with(**@expected_keywords)
243
+ end
231
244
 
232
245
  unless @expected_return_values.empty?
233
246
  matcher = matcher.exactly(@expected_return_values.count).times
@@ -11,13 +11,13 @@ module RSpec
11
11
  # Major version.
12
12
  MAJOR = 2
13
13
  # Minor version.
14
- MINOR = 5
14
+ MINOR = 6
15
15
  # Patch version.
16
- PATCH = 1
16
+ PATCH = 0
17
17
  # Prerelease version.
18
- PRERELEASE = nil
18
+ PRERELEASE = :rc
19
19
  # Build metadata.
20
- BUILD = nil
20
+ BUILD = 0
21
21
 
22
22
  # Generates the gem version string from the Version constants.
23
23
  #
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.5.1
4
+ version: 2.6.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: 2019-05-16 00:00:00.000000000 Z
11
+ date: 2021-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashdiff
@@ -42,16 +42,22 @@ dependencies:
42
42
  name: sleeping_king_studios-tools
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 0.8.0
48
+ - - "<"
46
49
  - !ruby/object:Gem::Version
47
- version: '0.7'
50
+ version: '2'
48
51
  type: :runtime
49
52
  prerelease: false
50
53
  version_requirements: !ruby/object:Gem::Requirement
51
54
  requirements:
52
- - - "~>"
55
+ - - ">="
53
56
  - !ruby/object:Gem::Version
54
- version: '0.7'
57
+ version: 0.8.0
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: '2'
55
61
  - !ruby/object:Gem::Dependency
56
62
  name: appraisal
57
63
  requirement: !ruby/object:Gem::Requirement
@@ -98,36 +104,42 @@ dependencies:
98
104
  name: thor
99
105
  requirement: !ruby/object:Gem::Requirement
100
106
  requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: 0.19.4
104
107
  - - "~>"
105
108
  - !ruby/object:Gem::Version
106
109
  version: '0.20'
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: 0.19.4
107
113
  type: :development
108
114
  prerelease: false
109
115
  version_requirements: !ruby/object:Gem::Requirement
110
116
  requirements:
111
- - - ">="
112
- - !ruby/object:Gem::Version
113
- version: 0.19.4
114
117
  - - "~>"
115
118
  - !ruby/object:Gem::Version
116
119
  version: '0.20'
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: 0.19.4
117
123
  - !ruby/object:Gem::Dependency
118
124
  name: sleeping_king_studios-tasks
119
125
  requirement: !ruby/object:Gem::Requirement
120
126
  requirements:
121
127
  - - "~>"
122
128
  - !ruby/object:Gem::Version
123
- version: '0.1'
129
+ version: '0.4'
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: 0.4.1
124
133
  type: :development
125
134
  prerelease: false
126
135
  version_requirements: !ruby/object:Gem::Requirement
127
136
  requirements:
128
137
  - - "~>"
129
138
  - !ruby/object:Gem::Version
130
- version: '0.1'
139
+ version: '0.4'
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: 0.4.1
131
143
  - !ruby/object:Gem::Dependency
132
144
  name: aruba
133
145
  requirement: !ruby/object:Gem::Requirement
@@ -165,7 +177,7 @@ dependencies:
165
177
  version: '3.0'
166
178
  - - "<"
167
179
  - !ruby/object:Gem::Version
168
- version: '6.0'
180
+ version: '7.0'
169
181
  type: :development
170
182
  prerelease: false
171
183
  version_requirements: !ruby/object:Gem::Requirement
@@ -175,7 +187,7 @@ dependencies:
175
187
  version: '3.0'
176
188
  - - "<"
177
189
  - !ruby/object:Gem::Version
178
- version: '6.0'
190
+ version: '7.0'
179
191
  description: |2
180
192
  A collection of RSpec patches and custom matchers. The features can be
181
193
  included individually or by category. For more information, check out the
@@ -265,7 +277,9 @@ files:
265
277
  homepage: http://sleepingkingstudios.com
266
278
  licenses:
267
279
  - MIT
268
- metadata: {}
280
+ metadata:
281
+ bug_tracker_uri: https://github.com/sleepingkingstudios/rspec-sleeping_king_studios/issues
282
+ source_code_uri: https://github.com/sleepingkingstudios/rspec-sleeping_king_studios
269
283
  post_install_message:
270
284
  rdoc_options: []
271
285
  require_paths:
@@ -277,11 +291,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
277
291
  version: '0'
278
292
  required_rubygems_version: !ruby/object:Gem::Requirement
279
293
  requirements:
280
- - - ">="
294
+ - - ">"
281
295
  - !ruby/object:Gem::Version
282
- version: '0'
296
+ version: 1.3.1
283
297
  requirements: []
284
- rubygems_version: 3.0.3
298
+ rubygems_version: 3.1.2
285
299
  signing_key:
286
300
  specification_version: 4
287
301
  summary: A collection of RSpec patches and custom matchers.