delegate_matcher 0.0.3 → 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.bundle/config +3 -0
  3. data/.gitignore +3 -1
  4. data/.rubocop.yml +8 -0
  5. data/.travis.yml +7 -2
  6. data/Gemfile.lock +90 -37
  7. data/Guardfile +4 -0
  8. data/README.md +106 -98
  9. data/Rakefile +3 -1
  10. data/delegate_matcher.gemspec +17 -8
  11. data/lib/delegate_matcher/delegate.rb +79 -0
  12. data/lib/delegate_matcher/delegate_matcher.rb +41 -266
  13. data/lib/delegate_matcher/delegation.rb +115 -0
  14. data/lib/delegate_matcher/dispatcher.rb +26 -0
  15. data/lib/delegate_matcher/expected.rb +108 -0
  16. data/lib/delegate_matcher/nil_delegate.rb +41 -0
  17. data/lib/delegate_matcher/stub_delegate.rb +26 -0
  18. data/lib/delegate_matcher/version.rb +1 -1
  19. data/lib/delegate_matcher.rb +9 -0
  20. data/spec/lib/active_support_delegation_spec.rb +24 -29
  21. data/spec/lib/aggregate_delegate_matcher_spec.rb +62 -0
  22. data/spec/lib/delegate_spec.rb +15 -0
  23. data/spec/lib/delegate_to_class_variable_spec.rb +85 -0
  24. data/spec/lib/delegate_to_constant_spec.rb +86 -0
  25. data/spec/lib/delegate_to_instance_variable_spec.rb +86 -0
  26. data/spec/lib/delegate_to_method_spec.rb +84 -0
  27. data/spec/lib/delegate_to_object_spec.rb +103 -0
  28. data/spec/lib/forwardable_delegation_spec.rb +14 -13
  29. data/spec/lib/shared/a_simple_delegator.rb +17 -0
  30. data/spec/lib/shared/args.rb +24 -0
  31. data/spec/lib/shared/args_and_a_block.rb +6 -0
  32. data/spec/lib/shared/author.rb +10 -0
  33. data/spec/lib/shared/block.rb +45 -0
  34. data/spec/lib/shared/different_method_name.rb +12 -0
  35. data/spec/lib/shared/different_return_value.rb +19 -0
  36. data/spec/lib/shared/nil_check.rb +52 -0
  37. data/spec/lib/shared/prefix.rb +16 -0
  38. data/spec/spec_helper.rb +6 -2
  39. metadata +85 -7
  40. data/spec/lib/delegate_matcher_spec.rb +0 -467
  41. data/spec/lib/version_spec.rb +0 -7
@@ -0,0 +1,17 @@
1
+ shared_examples 'a simple delegator' do
2
+ it { should delegate(:name).to(receiver) }
3
+ it { should delegate(:name.to_s).to(receiver) }
4
+
5
+ it { should_not delegate(:to_s).to(receiver) }
6
+
7
+ include_examples 'a delegator without a block'
8
+
9
+ describe 'description' do
10
+ let(:matcher) { delegate(:name).to(receiver) }
11
+ before { matcher.matches? subject }
12
+
13
+ it { expect(matcher.description).to eq "delegate name to #{receiver}" }
14
+ it { expect(matcher.failure_message).to match(/expected .* to delegate name to #{receiver}/) }
15
+ it { expect(matcher.failure_message_when_negated).to match(/expected .* not to delegate name to #{receiver}/) }
16
+ end
17
+ end
@@ -0,0 +1,24 @@
1
+ shared_examples 'a delegator with args' do |*args|
2
+ it { should delegate(:name).with(*args).to(receiver) }
3
+
4
+ describe 'description and failure messages' do
5
+ before { matcher.matches? subject }
6
+
7
+ context 'with no args' do
8
+ let(:matcher) { delegate(:name).with.to(receiver) }
9
+ it { expect(matcher.description).to eq %(delegate name() to #{receiver}) }
10
+ end
11
+
12
+ context 'with args passed through' do
13
+ let(:matcher) { delegate(:name).with('Ms.').to(receiver) }
14
+ it { expect(matcher.description).to eq %(delegate name("Ms.") to #{receiver}) }
15
+ it { expect(matcher.failure_message_when_negated).to match(/was called with \("Ms."\)/) }
16
+ end
17
+
18
+ context 'with args changed' do
19
+ let(:matcher) { delegate(:name).with('Ms.').to(receiver).with('Mrs.') }
20
+ it { expect(matcher.description).to eq %(delegate name("Ms.") to #{receiver}.#{:name}("Mrs.")) }
21
+ it { expect(matcher.failure_message).to match(/was called with \("Ms."\)/) }
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,6 @@
1
+ shared_examples 'a delegator with args and a block' do |*args|
2
+ include_examples 'a delegator with args', *args
3
+ include_examples 'a delegator with a block'
4
+
5
+ it { should delegate(:name).to(receiver).with(*args).with_block }
6
+ end
@@ -0,0 +1,10 @@
1
+ module RSpec
2
+ module Matchers
3
+ module DelegateMatcher
4
+ class Author
5
+ def name
6
+ end
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,45 @@
1
+ shared_examples 'a delegator with a block' do
2
+ it { should delegate(:name).to(receiver).with_block }
3
+ it { should delegate(:name).to(receiver).with_a_block }
4
+
5
+ it { should_not delegate(:name).to(receiver).without_block }
6
+ it { should_not delegate(:name).to(receiver).without_a_block }
7
+
8
+ describe 'description and failure messages' do
9
+ before { matcher.matches? subject }
10
+
11
+ context 'with a block' do
12
+ let(:matcher) { delegate(:name).to(receiver).with_a_block }
13
+ it { expect(matcher.description).to eq "delegate name to #{receiver} with a block" }
14
+ it { expect(matcher.failure_message_when_negated).to match(/a block was passed/) }
15
+ end
16
+
17
+ context 'without a block' do
18
+ let(:matcher) { delegate(:name).to(receiver).without_a_block }
19
+ it { expect(matcher.description).to eq "delegate name to #{receiver} without a block" }
20
+ it { expect(matcher.failure_message).to match(/a block was passed/) }
21
+ end
22
+ end
23
+ end
24
+
25
+ shared_examples 'a delegator without a block' do
26
+ it { should delegate(:name).to(receiver).without_block }
27
+ it { should delegate(:name).to(receiver).without_a_block }
28
+
29
+ it { should_not delegate(:name).to(receiver).with_block }
30
+ it { should_not delegate(:name).to(receiver).with_a_block }
31
+
32
+ describe 'failure messages' do
33
+ before { matcher.matches? subject }
34
+
35
+ context 'with a block' do
36
+ let(:matcher) { delegate(:name).to(receiver).with_a_block }
37
+ it { expect(matcher.failure_message).to match(/a block was not passed/) }
38
+ end
39
+
40
+ context 'without a block' do
41
+ let(:matcher) { delegate(:name).to(receiver).without_a_block }
42
+ it { expect(matcher.failure_message_when_negated).to match(/a block was not passed/) }
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,12 @@
1
+ shared_examples 'a delegator with a different method name' do |other_name|
2
+ it { should delegate(:name).to(receiver).as(other_name) }
3
+
4
+ describe 'description and failure messages' do
5
+ let(:matcher) { delegate(:name).to(receiver).as(other_name) }
6
+ before { matcher.matches? subject }
7
+
8
+ it { expect(matcher.description).to eq "delegate name to #{receiver}.#{other_name}" }
9
+ it { expect(matcher.failure_message).to match(/expected .* to delegate name to #{receiver}.#{other_name}/) }
10
+ it { expect(matcher.failure_message_when_negated).to match(/expected .* not to delegate name to #{receiver}.#{other_name}/) }
11
+ end
12
+ end
@@ -0,0 +1,19 @@
1
+ shared_examples 'a delegator with a different return value' do |actual_return_value|
2
+ it { should delegate(:name).to(receiver).without_return }
3
+ it { should_not delegate(:name).to(receiver) }
4
+
5
+ describe 'description' do
6
+ let(:matcher) { delegate(:name).to(receiver).without_return }
7
+ before { matcher.matches? subject }
8
+
9
+ it { expect(matcher.description).to eq "delegate name to #{receiver} without using delegate return value" }
10
+ it { expect(matcher.failure_message_when_negated).to match(/expected .* not to delegate name to #{receiver} without using delegate return value/) }
11
+ end
12
+
13
+ describe 'failure message' do
14
+ let(:matcher) { delegate(:name).to(receiver) }
15
+ before { matcher.matches? subject }
16
+
17
+ it { expect(matcher.failure_message).to match(/a return value of "#{actual_return_value}" was returned instead of the delegate return value/) }
18
+ end
19
+ end
@@ -0,0 +1,52 @@
1
+ shared_examples 'a delegator with a nil check' do
2
+ it { should delegate(:name).to(receiver).allow_nil }
3
+ it { should delegate(:name).to(receiver).allow_nil(true) }
4
+ it { should_not delegate(:name).to(receiver).allow_nil(false) }
5
+
6
+ describe 'description' do
7
+ before { matcher.matches? subject }
8
+
9
+ context 'with allow nil at default' do
10
+ let(:matcher) { delegate(:name).to(receiver).allow_nil }
11
+ it { expect(matcher.description).to eq %(delegate name to #{receiver} with nil allowed) }
12
+ it { expect(matcher.failure_message_when_negated).to match(/#{receiver} was allowed to be nil/) }
13
+ end
14
+
15
+ context 'with allow nil true' do
16
+ let(:matcher) { delegate(:name).to(receiver).allow_nil(true) }
17
+ it { expect(matcher.description).to eq %(delegate name to #{receiver} with nil allowed) }
18
+ it { expect(matcher.failure_message_when_negated).to match(/#{receiver} was allowed to be nil/) }
19
+ end
20
+
21
+ context 'with allow nil false' do
22
+ let(:matcher) { delegate(:name).to(receiver).allow_nil(false) }
23
+ it { expect(matcher.description).to eq %(delegate name to #{receiver} with nil not allowed) }
24
+ it { expect(matcher.failure_message).to match(/#{receiver} was allowed to be nil/) }
25
+ end
26
+ end
27
+ end
28
+
29
+ shared_examples 'a delegator without a nil check' do
30
+ it { should delegate(:name).to(receiver).allow_nil(false) }
31
+ it { should_not delegate(:name).to(receiver).allow_nil(true) }
32
+ it { should_not delegate(:name).to(receiver).allow_nil }
33
+
34
+ describe 'description' do
35
+ before { matcher.matches? subject }
36
+
37
+ context 'with allow nil at default' do
38
+ let(:matcher) { delegate(:name).to(receiver).allow_nil }
39
+ it { expect(matcher.failure_message).to match(/#{receiver} was not allowed to be nil/) }
40
+ end
41
+
42
+ context 'with allow nil true' do
43
+ let(:matcher) { delegate(:name).to(receiver).allow_nil(true) }
44
+ it { expect(matcher.failure_message).to match(/#{receiver} was not allowed to be nil/) }
45
+ end
46
+
47
+ context 'with allow nil false' do
48
+ let(:matcher) { delegate(:name).to(receiver).allow_nil(false) }
49
+ it { expect(matcher.failure_message_when_negated).to match(/#{receiver} was not allowed to be nil/) }
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,16 @@
1
+ shared_examples 'a delegator with a prefix' do |prefix|
2
+ it { should delegate(:name).to(receiver).with_prefix }
3
+ it { should delegate(:name).to(receiver).with_prefix(prefix) }
4
+ it { should delegate(:name).to(receiver).with_prefix(prefix.to_sym) }
5
+
6
+ [prefix, nil].each do |test_prefix|
7
+ describe "description with prefix '#{test_prefix}'" do
8
+ let(:matcher) { delegate(:name).to(receiver).with_prefix(test_prefix) }
9
+ before { matcher.matches? subject }
10
+
11
+ it { expect(matcher.description).to eq "delegate #{prefix}_#{:name} to #{receiver}.#{:name}" }
12
+ it { expect(matcher.failure_message).to match(/expected .* to delegate #{prefix}_#{:name} to #{receiver}.#{:name}/) }
13
+ it { expect(matcher.failure_message_when_negated).to match(/expected .* not to delegate #{prefix}_#{:name} to #{receiver}.#{:name}/) }
14
+ end
15
+ end
16
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  require 'rspec'
2
2
  require 'rspec/its'
3
- require 'coveralls'
4
3
  require 'simplecov'
4
+ require 'coveralls'
5
+
6
+ require RUBY_VERSION =~ /2/ ? 'pry-byebug' : 'pry-debugger'
5
7
 
6
8
  SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
7
9
  SimpleCov::Formatter::HTMLFormatter,
@@ -9,10 +11,12 @@ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
9
11
  ]
10
12
  SimpleCov.start
11
13
 
12
- Coveralls.wear!
14
+ Coveralls.wear! if Coveralls.will_run?
13
15
 
14
16
  require 'delegate_matcher'
15
17
 
18
+ Dir[File.dirname(__FILE__) + '/lib/shared/*.rb'].each { |f| require f }
19
+
16
20
  RSpec.configure do |config|
17
21
  config.color = true
18
22
  config.filter_run focus: true
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delegate_matcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: '0.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Declan Whelan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-21 00:00:00.000000000 Z
11
+ date: 2015-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -52,6 +52,48 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.13'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.13'
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4.6'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4.6'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.3'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.3'
55
97
  - !ruby/object:Gem::Dependency
56
98
  name: rake
57
99
  requirement: !ruby/object:Gem::Requirement
@@ -129,22 +171,44 @@ executables: []
129
171
  extensions: []
130
172
  extra_rdoc_files: []
131
173
  files:
174
+ - ".bundle/config"
132
175
  - ".gitignore"
133
176
  - ".rubocop.yml"
134
177
  - ".travis.yml"
135
178
  - Gemfile
136
179
  - Gemfile.lock
180
+ - Guardfile
137
181
  - LICENSE.txt
138
182
  - README.md
139
183
  - Rakefile
140
184
  - delegate_matcher.gemspec
141
185
  - lib/delegate_matcher.rb
186
+ - lib/delegate_matcher/delegate.rb
142
187
  - lib/delegate_matcher/delegate_matcher.rb
188
+ - lib/delegate_matcher/delegation.rb
189
+ - lib/delegate_matcher/dispatcher.rb
190
+ - lib/delegate_matcher/expected.rb
191
+ - lib/delegate_matcher/nil_delegate.rb
192
+ - lib/delegate_matcher/stub_delegate.rb
143
193
  - lib/delegate_matcher/version.rb
144
194
  - spec/lib/active_support_delegation_spec.rb
145
- - spec/lib/delegate_matcher_spec.rb
195
+ - spec/lib/aggregate_delegate_matcher_spec.rb
196
+ - spec/lib/delegate_spec.rb
197
+ - spec/lib/delegate_to_class_variable_spec.rb
198
+ - spec/lib/delegate_to_constant_spec.rb
199
+ - spec/lib/delegate_to_instance_variable_spec.rb
200
+ - spec/lib/delegate_to_method_spec.rb
201
+ - spec/lib/delegate_to_object_spec.rb
146
202
  - spec/lib/forwardable_delegation_spec.rb
147
- - spec/lib/version_spec.rb
203
+ - spec/lib/shared/a_simple_delegator.rb
204
+ - spec/lib/shared/args.rb
205
+ - spec/lib/shared/args_and_a_block.rb
206
+ - spec/lib/shared/author.rb
207
+ - spec/lib/shared/block.rb
208
+ - spec/lib/shared/different_method_name.rb
209
+ - spec/lib/shared/different_return_value.rb
210
+ - spec/lib/shared/nil_check.rb
211
+ - spec/lib/shared/prefix.rb
148
212
  - spec/spec_helper.rb
149
213
  homepage: https://github.com/dwhelan/delegate_matcher
150
214
  licenses:
@@ -166,13 +230,27 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
230
  version: '0'
167
231
  requirements: []
168
232
  rubyforge_project:
169
- rubygems_version: 2.4.5
233
+ rubygems_version: 2.4.6
170
234
  signing_key:
171
235
  specification_version: 4
172
236
  summary: A matcher for testing ruby delegation.
173
237
  test_files:
174
238
  - spec/lib/active_support_delegation_spec.rb
175
- - spec/lib/delegate_matcher_spec.rb
239
+ - spec/lib/aggregate_delegate_matcher_spec.rb
240
+ - spec/lib/delegate_spec.rb
241
+ - spec/lib/delegate_to_class_variable_spec.rb
242
+ - spec/lib/delegate_to_constant_spec.rb
243
+ - spec/lib/delegate_to_instance_variable_spec.rb
244
+ - spec/lib/delegate_to_method_spec.rb
245
+ - spec/lib/delegate_to_object_spec.rb
176
246
  - spec/lib/forwardable_delegation_spec.rb
177
- - spec/lib/version_spec.rb
247
+ - spec/lib/shared/a_simple_delegator.rb
248
+ - spec/lib/shared/args.rb
249
+ - spec/lib/shared/args_and_a_block.rb
250
+ - spec/lib/shared/author.rb
251
+ - spec/lib/shared/block.rb
252
+ - spec/lib/shared/different_method_name.rb
253
+ - spec/lib/shared/different_return_value.rb
254
+ - spec/lib/shared/nil_check.rb
255
+ - spec/lib/shared/prefix.rb
178
256
  - spec/spec_helper.rb