delegate_matcher 0.3 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -3
- data/README.md +101 -8
- data/README.md.erb +216 -0
- data/Rakefile +6 -1
- data/delegate_matcher.gemspec +1 -1
- data/lib/delegate_matcher/delegate.rb +5 -12
- data/lib/delegate_matcher/delegate_matcher.rb +5 -14
- data/lib/delegate_matcher/delegation.rb +32 -23
- data/lib/delegate_matcher/dispatcher.rb +4 -1
- data/lib/delegate_matcher/expected.rb +31 -18
- data/lib/delegate_matcher/nil_delegate.rb +3 -2
- data/lib/delegate_matcher/stub_delegate.rb +7 -3
- data/lib/delegate_matcher/version.rb +1 -1
- data/spec/{lib → examples}/active_support_delegation_spec.rb +11 -2
- data/spec/{lib → examples}/forwardable_delegation_spec.rb +11 -2
- data/spec/shared/author.rb +23 -0
- data/spec/{lib/shared/a_simple_delegator.rb → shared/basic.rb} +4 -6
- data/spec/{lib/shared → shared}/nil_check.rb +15 -15
- data/spec/shared/post_delegation.rb +42 -0
- data/spec/shared/post_methods.rb +15 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/to_a_class_method_spec.rb +37 -0
- data/spec/to_a_class_variable_spec.rb +38 -0
- data/spec/to_a_constant_spec.rb +37 -0
- data/spec/to_an_instance_method_spec.rb +39 -0
- data/spec/to_an_instance_variable_spec.rb +35 -0
- data/spec/to_an_object_spec.rb +45 -0
- data/spec/to_multiple_targets_spec.rb +34 -0
- data/spec/with_args_spec.rb +151 -0
- data/spec/with_as_spec.rb +25 -0
- data/spec/with_block_spec.rb +75 -0
- data/spec/with_prefix_spec.rb +37 -0
- data/spec/with_return_value_spec.rb +46 -0
- data/spec/with_to_spec.rb +53 -0
- metadata +45 -43
- data/.bundle/config +0 -3
- data/spec/lib/aggregate_delegate_matcher_spec.rb +0 -62
- data/spec/lib/class_method_spec.rb +0 -84
- data/spec/lib/class_variable_spec.rb +0 -85
- data/spec/lib/constant_spec.rb +0 -86
- data/spec/lib/delegate_spec.rb +0 -15
- data/spec/lib/instance_method_spec.rb +0 -84
- data/spec/lib/instance_variable_spec.rb +0 -102
- data/spec/lib/object_spec.rb +0 -103
- data/spec/lib/shared/args.rb +0 -24
- data/spec/lib/shared/args_and_a_block.rb +0 -6
- data/spec/lib/shared/author.rb +0 -10
- data/spec/lib/shared/block.rb +0 -71
- data/spec/lib/shared/different_method_name.rb +0 -12
- data/spec/lib/shared/different_return_value.rb +0 -19
- data/spec/lib/shared/prefix.rb +0 -16
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
module Matchers
|
5
|
+
module DelegateMatcher
|
6
|
+
describe 'delegation to an instance method' do
|
7
|
+
let(:klass) do
|
8
|
+
Class.new do
|
9
|
+
include PostMethods
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@authors = [author]
|
13
|
+
end
|
14
|
+
|
15
|
+
def author
|
16
|
+
@author ||= Author.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def name
|
20
|
+
author.name
|
21
|
+
end
|
22
|
+
|
23
|
+
def name_allow_nil
|
24
|
+
author.name if author
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
subject { klass.new }
|
30
|
+
|
31
|
+
let(:receiver) { :author }
|
32
|
+
|
33
|
+
it_behaves_like 'a basic delegator'
|
34
|
+
it_behaves_like 'a delegator without a nil check'
|
35
|
+
it_behaves_like 'a delegator with a nil check'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
module Matchers
|
5
|
+
module DelegateMatcher
|
6
|
+
describe 'delegation to an instance variable' do
|
7
|
+
let(:klass) do
|
8
|
+
Class.new do
|
9
|
+
include PostMethods
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@author = Author.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def name
|
16
|
+
@author.name
|
17
|
+
end
|
18
|
+
|
19
|
+
def name_allow_nil
|
20
|
+
@author.name if @author
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
subject { klass.new }
|
26
|
+
|
27
|
+
let(:receiver) { :@author }
|
28
|
+
|
29
|
+
it_behaves_like 'a basic delegator'
|
30
|
+
it_behaves_like 'a delegator without a nil check'
|
31
|
+
it_behaves_like 'a delegator with a nil check'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
module Matchers
|
5
|
+
module DelegateMatcher
|
6
|
+
describe 'delegation to an object' do
|
7
|
+
let(:klass) do
|
8
|
+
Class.new do
|
9
|
+
include PostMethods
|
10
|
+
|
11
|
+
def initialize(author)
|
12
|
+
@author = author
|
13
|
+
end
|
14
|
+
|
15
|
+
def name
|
16
|
+
@author.name
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
subject { klass.new(author) }
|
22
|
+
|
23
|
+
let(:author) { Author.new }
|
24
|
+
let(:receiver) { author }
|
25
|
+
|
26
|
+
it_behaves_like 'a basic delegator'
|
27
|
+
|
28
|
+
it do
|
29
|
+
expect { should delegate(:name).to(author).allow_nil }.to \
|
30
|
+
raise_error RuntimeError, 'cannot verify "allow_nil" expectations when delegating to an object'
|
31
|
+
end
|
32
|
+
|
33
|
+
it do
|
34
|
+
expect { should delegate(:name).to(author).allow_nil(true) }.to \
|
35
|
+
raise_error RuntimeError, 'cannot verify "allow_nil" expectations when delegating to an object'
|
36
|
+
end
|
37
|
+
|
38
|
+
it do
|
39
|
+
expect { should delegate(:name).to(author).allow_nil(false) }.to \
|
40
|
+
raise_error RuntimeError, 'cannot verify "allow_nil" expectations when delegating to an object'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
module Matchers
|
5
|
+
module DelegateMatcher
|
6
|
+
module Composite
|
7
|
+
describe 'delegation to multiple targets' do
|
8
|
+
class Post
|
9
|
+
include PostMethods
|
10
|
+
|
11
|
+
attr_accessor :authors, :catherine_asaro, :isaac_asimov
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
self.catherine_asaro = Author.new('Catherine Asaro')
|
15
|
+
self.isaac_asimov = Author.new('Isaac Asimov')
|
16
|
+
self.authors = [catherine_asaro, isaac_asimov]
|
17
|
+
end
|
18
|
+
|
19
|
+
def name
|
20
|
+
authors.map(&:name)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
subject { Post.new }
|
25
|
+
|
26
|
+
it { should delegate(:name).to(*subject.authors) }
|
27
|
+
it { should delegate(:name).to(subject.catherine_asaro, subject.isaac_asimov) }
|
28
|
+
it { should delegate(:name).to(:catherine_asaro, :isaac_asimov) }
|
29
|
+
it { should delegate(:name).to(:@catherine_asaro, :@isaac_asimov) }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,151 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'active_support/core_ext/module'
|
3
|
+
|
4
|
+
module RSpec
|
5
|
+
module Matchers
|
6
|
+
# rubocop:disable Metrics/ModuleLength
|
7
|
+
module DelegateMatcher
|
8
|
+
shared_examples 'a delegator with empty args' do
|
9
|
+
let(:matcher) { delegate(:name).with.to(:@author) }
|
10
|
+
|
11
|
+
it { should matcher }
|
12
|
+
it { expect(matcher.description).to eq 'delegate name() to "@author"' }
|
13
|
+
|
14
|
+
it { should matcher.with }
|
15
|
+
it { expect(matcher.with.description).to eq 'delegate name() to "@author"' }
|
16
|
+
|
17
|
+
it { should matcher.with(no_args) }
|
18
|
+
it { expect(matcher.with(no_args).description).to eq 'delegate name() to "@author".name(no args)' }
|
19
|
+
|
20
|
+
it { expect(matcher.failure_message_when_negated).to match(/was called with ()/) }
|
21
|
+
end
|
22
|
+
|
23
|
+
shared_examples 'a delegator with no_args' do
|
24
|
+
let(:matcher) { delegate(:name).with(no_args).to(:@author) }
|
25
|
+
|
26
|
+
it { should matcher }
|
27
|
+
it { expect(matcher.description).to eq 'delegate name(no args) to "@author"' }
|
28
|
+
|
29
|
+
it { should matcher.with }
|
30
|
+
it { expect(matcher.with.description).to eq 'delegate name(no args) to "@author".name()' }
|
31
|
+
|
32
|
+
it { should matcher.with(no_args) }
|
33
|
+
it { expect(matcher.with(no_args).description).to eq 'delegate name(no args) to "@author"' }
|
34
|
+
|
35
|
+
it { expect(matcher.failure_message_when_negated).to match(/was called with ()/) }
|
36
|
+
end
|
37
|
+
|
38
|
+
shared_examples 'a delegator with same args' do |*args|
|
39
|
+
let(:args_description) { args.map(&:inspect).join(', ') }
|
40
|
+
let(:matcher) { delegate(:name).with(*args).to(:@author) }
|
41
|
+
|
42
|
+
it { should matcher }
|
43
|
+
it { expect(matcher.description).to eq %(delegate name(#{args_description}) to "@author") }
|
44
|
+
|
45
|
+
it { should matcher.with(*args) }
|
46
|
+
it { expect(matcher.with(*args).description).to eq %(delegate name(#{args_description}) to "@author") }
|
47
|
+
end
|
48
|
+
|
49
|
+
shared_examples 'a delegator with any args' do |*args|
|
50
|
+
let(:matcher) { delegate(:name).with(*args).to(:@author).with(any_args) }
|
51
|
+
|
52
|
+
it { should matcher }
|
53
|
+
it { expect(matcher.description).to eq %(delegate name(#{args.map(&:inspect).join(', ')}) to "@author".name(*(any args))) }
|
54
|
+
end
|
55
|
+
|
56
|
+
shared_examples 'a delegator with anything' do |*args|
|
57
|
+
let(:matcher) { delegate(:name).with(*args).to(:@author).with(anything) }
|
58
|
+
|
59
|
+
it { should matcher }
|
60
|
+
it { expect(matcher.description).to eq %(delegate name(#{args.map(&:inspect).join(', ')}) to "@author".name(anything)) }
|
61
|
+
end
|
62
|
+
|
63
|
+
describe 'argument matching' do
|
64
|
+
include_context 'Post delegation'
|
65
|
+
|
66
|
+
context <<-END.gsub(/^\s{6}/, '') do
|
67
|
+
# With no parameters
|
68
|
+
def name
|
69
|
+
@author.name
|
70
|
+
end
|
71
|
+
END
|
72
|
+
it_behaves_like 'a delegator with empty args'
|
73
|
+
it_behaves_like 'a delegator with no_args'
|
74
|
+
it_behaves_like 'a delegator with same args'
|
75
|
+
it_behaves_like 'a delegator with any args'
|
76
|
+
|
77
|
+
it { should_not delegate(:name).with.to(:@author).with(anything) }
|
78
|
+
end
|
79
|
+
|
80
|
+
context <<-END.gsub(/^\s{6}/, '') do
|
81
|
+
# With optional parameters
|
82
|
+
def name(*args)
|
83
|
+
@author.name(*args)
|
84
|
+
end
|
85
|
+
END
|
86
|
+
|
87
|
+
it_behaves_like 'a delegator with empty args'
|
88
|
+
it_behaves_like 'a delegator with no_args'
|
89
|
+
it_behaves_like 'a delegator with same args', 'Ms.'
|
90
|
+
it_behaves_like 'a delegator with anything', 'Ms.'
|
91
|
+
it_behaves_like 'a delegator with any args'
|
92
|
+
it_behaves_like 'a delegator with any args', 'Ms.'
|
93
|
+
it_behaves_like 'a delegator with any args', 'Ms.', 'Mrs.'
|
94
|
+
|
95
|
+
it { should_not delegate(:name).with('Ms.').to(:@author).with(no_args) }
|
96
|
+
end
|
97
|
+
|
98
|
+
context <<-END.gsub(/^\s{6}/, '') do
|
99
|
+
# With a required parameter
|
100
|
+
def name(title)
|
101
|
+
@author.name(title)
|
102
|
+
end
|
103
|
+
END
|
104
|
+
|
105
|
+
it_behaves_like 'a delegator with same args', 'Ms.'
|
106
|
+
it_behaves_like 'a delegator with any args', 'Ms.'
|
107
|
+
it_behaves_like 'a delegator with anything', 'Ms.'
|
108
|
+
|
109
|
+
let(:matcher) { delegate(:name).to(:@author).with('Ms.') }
|
110
|
+
|
111
|
+
it { should matcher }
|
112
|
+
it { expect(matcher.description).to eq 'delegate name("Ms.") to "@author"' }
|
113
|
+
it { expect(matcher.failure_message_when_negated).to match(/was called with \("Ms."\)/) }
|
114
|
+
it { should_not delegate(:name).with('Ms.').to(:@author).with(no_args) }
|
115
|
+
end
|
116
|
+
|
117
|
+
context <<-END.gsub(/^\s{6}/, '') do
|
118
|
+
# With an optional parameter
|
119
|
+
def name(title = 'Ms.')
|
120
|
+
@author.name(title)
|
121
|
+
end
|
122
|
+
END
|
123
|
+
|
124
|
+
it_behaves_like 'a delegator with same args', 'Ms.'
|
125
|
+
it_behaves_like 'a delegator with any args', 'Ms.'
|
126
|
+
it_behaves_like 'a delegator with anything', 'Ms.'
|
127
|
+
|
128
|
+
let(:matcher) { delegate(:name).to(:@author).with('Ms.') }
|
129
|
+
|
130
|
+
it { should matcher }
|
131
|
+
it { expect(matcher.description).to eq 'delegate name("Ms.") to "@author"' }
|
132
|
+
it { expect(matcher.failure_message_when_negated).to match(/was called with \("Ms."\)/) }
|
133
|
+
end
|
134
|
+
|
135
|
+
context <<-END.gsub(/^\s{6}/, '') do
|
136
|
+
# With arguments changed
|
137
|
+
def name(title)
|
138
|
+
@author.name(title.downcase)
|
139
|
+
end
|
140
|
+
END
|
141
|
+
|
142
|
+
let(:matcher) { delegate(:name).with('Ms.').to(:@author).with('ms.') }
|
143
|
+
|
144
|
+
it { should matcher }
|
145
|
+
it { expect(matcher.description).to eq 'delegate name("Ms.") to "@author".name("ms.")' }
|
146
|
+
it { expect(matcher.failure_message_when_negated).to match(/was called with \("ms."\)/) }
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
module Matchers
|
5
|
+
module DelegateMatcher
|
6
|
+
describe 'as matching' do
|
7
|
+
include_context 'Post delegation'
|
8
|
+
|
9
|
+
context <<-END.gsub(/^\s{6}/, '') do
|
10
|
+
# With a block
|
11
|
+
def name
|
12
|
+
@author.other_name
|
13
|
+
end
|
14
|
+
END
|
15
|
+
|
16
|
+
let(:matcher) { delegate(:name).to(:@author).as(:other_name) }
|
17
|
+
|
18
|
+
it { expect(matcher.description).to match(/to "@author".other_name/) }
|
19
|
+
it { expect(matcher.failure_message_when_negated).to match(/to "@author".other_name/) }
|
20
|
+
it { expect(matcher.as('bad_name').failure_message).to match(/to "@author".bad_name/) }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
module Matchers
|
5
|
+
module DelegateMatcher
|
6
|
+
describe 'block matching' do
|
7
|
+
include_context 'Post delegation'
|
8
|
+
|
9
|
+
context <<-END.gsub(/^\s{6}/, '') do
|
10
|
+
# With a block
|
11
|
+
def name(&block)
|
12
|
+
@author.name(&block)
|
13
|
+
end
|
14
|
+
END
|
15
|
+
|
16
|
+
it { should matcher.with_block }
|
17
|
+
it { should matcher.with_a_block }
|
18
|
+
it { expect(matcher.with_block.description).to match(/with a block/) }
|
19
|
+
it { expect(matcher.with_block.failure_message_when_negated).to match(/a block was passed/) }
|
20
|
+
|
21
|
+
it { should_not matcher.without_block }
|
22
|
+
it { expect(matcher.without_block.failure_message).to match(/a block .* was passed/) }
|
23
|
+
end
|
24
|
+
|
25
|
+
context <<-END.gsub(/^\s{6}/, '') do
|
26
|
+
# Without a block
|
27
|
+
def name(&block)
|
28
|
+
@author.name
|
29
|
+
end
|
30
|
+
END
|
31
|
+
|
32
|
+
it { should matcher.without_block }
|
33
|
+
it { should matcher.without_a_block }
|
34
|
+
it { expect(matcher.without_block.description).to match(/without a block/) }
|
35
|
+
it { expect(matcher.without_block.failure_message_when_negated).to match(/a block was not passed/) }
|
36
|
+
|
37
|
+
it { should_not matcher.with_block }
|
38
|
+
it { expect(matcher.with_block.failure_message).to match(/a block was not passed/) }
|
39
|
+
end
|
40
|
+
|
41
|
+
context <<-END.gsub(/^\s{6}/, '') do
|
42
|
+
# With a custom block
|
43
|
+
def name(&block)
|
44
|
+
@author.name { 'yo' }
|
45
|
+
end
|
46
|
+
END
|
47
|
+
|
48
|
+
# To extract the proc source it must not eval'd so we redefine the method here
|
49
|
+
before do
|
50
|
+
klass.class_eval do
|
51
|
+
def name
|
52
|
+
@author.name { 'yo' }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# To extract the proc source it must be the only proc defined on the same line
|
58
|
+
let(:prc) do
|
59
|
+
proc { 'yo' }
|
60
|
+
end
|
61
|
+
|
62
|
+
let(:matcher) { delegate(:name).to(:@author).with_block(&prc) }
|
63
|
+
|
64
|
+
it { should matcher }
|
65
|
+
|
66
|
+
it { expect(matcher.description).to match(/with block "proc { "yo" }"/) }
|
67
|
+
it { expect(matcher.failure_message_when_negated).to match(/with block "proc { "yo" }"/) }
|
68
|
+
|
69
|
+
it { should_not matcher.without_block }
|
70
|
+
it { expect(matcher.without_block.failure_message).to match(/a block .* was passed/) }
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
module Matchers
|
5
|
+
module DelegateMatcher
|
6
|
+
describe 'prefix matching' do
|
7
|
+
include_context 'Post delegation'
|
8
|
+
|
9
|
+
context <<-END.gsub(/^\s{6}/, '') do
|
10
|
+
# With a default prefix
|
11
|
+
def author_name
|
12
|
+
@author.name
|
13
|
+
end
|
14
|
+
END
|
15
|
+
|
16
|
+
let(:matcher) { delegate(:name).to(:@author).with_prefix }
|
17
|
+
|
18
|
+
it { expect(matcher.description).to match(/author_name to "@author".name/) }
|
19
|
+
it { expect(matcher.failure_message_when_negated).to match(/author_name to "@author".name/) }
|
20
|
+
end
|
21
|
+
|
22
|
+
context <<-END.gsub(/^\s{6}/, '') do
|
23
|
+
# With a default prefix
|
24
|
+
def writer_name
|
25
|
+
@author.name
|
26
|
+
end
|
27
|
+
END
|
28
|
+
|
29
|
+
let(:matcher) { delegate(:name).to(:@author).with_prefix('writer') }
|
30
|
+
|
31
|
+
it { expect(matcher.description).to match(/writer_name to "@author".name/) }
|
32
|
+
it { expect(matcher.failure_message_when_negated).to match(/writer_name to "@author".name/) }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
module Matchers
|
5
|
+
module DelegateMatcher
|
6
|
+
describe 'return value matching' do
|
7
|
+
include_context 'Post delegation'
|
8
|
+
|
9
|
+
context <<-END.gsub(/^\s{6}/, '') do
|
10
|
+
# With a different return value
|
11
|
+
def name
|
12
|
+
@author.name
|
13
|
+
'Ann Rand'
|
14
|
+
end
|
15
|
+
END
|
16
|
+
|
17
|
+
it { should_not matcher }
|
18
|
+
it { expect(matcher.failure_message).to match(/a value of \"Ann Rand\" was returned instead of/) }
|
19
|
+
|
20
|
+
describe 'without_return' do
|
21
|
+
let(:matcher) { delegate(:name).to(:@author).without_return }
|
22
|
+
|
23
|
+
it { should matcher }
|
24
|
+
it { expect(matcher.description).to match(/ without using delegate return value/) }
|
25
|
+
it { expect(matcher.failure_message_when_negated).to match(/ without using delegate return value/) }
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'and_return' do
|
29
|
+
let(:matcher) { delegate(:name).to(:@author).and_return('Ann Rand') }
|
30
|
+
|
31
|
+
it { should matcher }
|
32
|
+
it { expect(matcher.description).to match(/ and return "Ann Rand"/) }
|
33
|
+
it { expect(matcher.failure_message_when_negated).to match(/ and return "Ann Rand"/) }
|
34
|
+
end
|
35
|
+
|
36
|
+
describe 'and_return incorrect value' do
|
37
|
+
let(:matcher) { delegate(:name).to(:@author).and_return('Isaac Asimov') }
|
38
|
+
|
39
|
+
it { should_not matcher }
|
40
|
+
it { expect(matcher.failure_message).to match(/a value of "Ann Rand" was returned instead of "Isaac Asimov"/) }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
module Matchers
|
5
|
+
module DelegateMatcher
|
6
|
+
describe 'to' do
|
7
|
+
let(:klass) do
|
8
|
+
Class.new do
|
9
|
+
include PostMethods
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@author = Author.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def name
|
16
|
+
@author.name
|
17
|
+
end
|
18
|
+
|
19
|
+
def name_allow_nil
|
20
|
+
@author.name if @author
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
subject { klass.new }
|
26
|
+
|
27
|
+
it 'should require a "to"' do
|
28
|
+
expect { should delegate(:name) }.to raise_error do |error|
|
29
|
+
expect(error.message).to match(/need to provide a "to"/)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should raise if the "to" method is invalid' do
|
34
|
+
expect { should delegate(:name).to(:does_not_exist) }.to raise_error do |error|
|
35
|
+
expect(error.message).to match(/undefined local variable or method .*does_not_exist/)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should raise if "to" constant is invalid' do
|
40
|
+
expect { should delegate(:name).to(:DOES_NOT_EXIST) }.to raise_error do |error|
|
41
|
+
expect(error.message).to match(/uninitialized constant .*DOES_NOT_EXIST/)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should raise if "to" instance variable is nil' do
|
46
|
+
expect { should delegate(:name).to(:@does_not_exist) }.to raise_error do |error|
|
47
|
+
expect(error.message).to match(/undefined method `name' for nil:NilClass/)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
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.
|
4
|
+
version: '0.4'
|
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-12-
|
11
|
+
date: 2015-12-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: proc_extensions
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
19
|
+
version: '0.2'
|
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: '0.
|
26
|
+
version: '0.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activesupport
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -185,7 +185,6 @@ executables: []
|
|
185
185
|
extensions: []
|
186
186
|
extra_rdoc_files: []
|
187
187
|
files:
|
188
|
-
- ".bundle/config"
|
189
188
|
- ".gitignore"
|
190
189
|
- ".rubocop.yml"
|
191
190
|
- ".travis.yml"
|
@@ -194,6 +193,7 @@ files:
|
|
194
193
|
- Guardfile
|
195
194
|
- LICENSE.txt
|
196
195
|
- README.md
|
196
|
+
- README.md.erb
|
197
197
|
- Rakefile
|
198
198
|
- delegate_matcher.gemspec
|
199
199
|
- lib/delegate_matcher.rb
|
@@ -206,26 +206,27 @@ files:
|
|
206
206
|
- lib/delegate_matcher/nil_delegate.rb
|
207
207
|
- lib/delegate_matcher/stub_delegate.rb
|
208
208
|
- lib/delegate_matcher/version.rb
|
209
|
-
- spec/
|
210
|
-
- spec/
|
211
|
-
- spec/
|
212
|
-
- spec/
|
213
|
-
- spec/
|
214
|
-
- spec/
|
215
|
-
- spec/
|
216
|
-
- spec/lib/instance_method_spec.rb
|
217
|
-
- spec/lib/instance_variable_spec.rb
|
218
|
-
- spec/lib/object_spec.rb
|
219
|
-
- spec/lib/shared/a_simple_delegator.rb
|
220
|
-
- spec/lib/shared/args.rb
|
221
|
-
- spec/lib/shared/args_and_a_block.rb
|
222
|
-
- spec/lib/shared/author.rb
|
223
|
-
- spec/lib/shared/block.rb
|
224
|
-
- spec/lib/shared/different_method_name.rb
|
225
|
-
- spec/lib/shared/different_return_value.rb
|
226
|
-
- spec/lib/shared/nil_check.rb
|
227
|
-
- spec/lib/shared/prefix.rb
|
209
|
+
- spec/examples/active_support_delegation_spec.rb
|
210
|
+
- spec/examples/forwardable_delegation_spec.rb
|
211
|
+
- spec/shared/author.rb
|
212
|
+
- spec/shared/basic.rb
|
213
|
+
- spec/shared/nil_check.rb
|
214
|
+
- spec/shared/post_delegation.rb
|
215
|
+
- spec/shared/post_methods.rb
|
228
216
|
- spec/spec_helper.rb
|
217
|
+
- spec/to_a_class_method_spec.rb
|
218
|
+
- spec/to_a_class_variable_spec.rb
|
219
|
+
- spec/to_a_constant_spec.rb
|
220
|
+
- spec/to_an_instance_method_spec.rb
|
221
|
+
- spec/to_an_instance_variable_spec.rb
|
222
|
+
- spec/to_an_object_spec.rb
|
223
|
+
- spec/to_multiple_targets_spec.rb
|
224
|
+
- spec/with_args_spec.rb
|
225
|
+
- spec/with_as_spec.rb
|
226
|
+
- spec/with_block_spec.rb
|
227
|
+
- spec/with_prefix_spec.rb
|
228
|
+
- spec/with_return_value_spec.rb
|
229
|
+
- spec/with_to_spec.rb
|
229
230
|
homepage: https://github.com/dwhelan/delegate_matcher
|
230
231
|
licenses:
|
231
232
|
- MIT
|
@@ -251,23 +252,24 @@ signing_key:
|
|
251
252
|
specification_version: 4
|
252
253
|
summary: A matcher for testing ruby delegation.
|
253
254
|
test_files:
|
254
|
-
- spec/
|
255
|
-
- spec/
|
256
|
-
- spec/
|
257
|
-
- spec/
|
258
|
-
- spec/
|
259
|
-
- spec/
|
260
|
-
- spec/
|
261
|
-
- spec/lib/instance_method_spec.rb
|
262
|
-
- spec/lib/instance_variable_spec.rb
|
263
|
-
- spec/lib/object_spec.rb
|
264
|
-
- spec/lib/shared/a_simple_delegator.rb
|
265
|
-
- spec/lib/shared/args.rb
|
266
|
-
- spec/lib/shared/args_and_a_block.rb
|
267
|
-
- spec/lib/shared/author.rb
|
268
|
-
- spec/lib/shared/block.rb
|
269
|
-
- spec/lib/shared/different_method_name.rb
|
270
|
-
- spec/lib/shared/different_return_value.rb
|
271
|
-
- spec/lib/shared/nil_check.rb
|
272
|
-
- spec/lib/shared/prefix.rb
|
255
|
+
- spec/examples/active_support_delegation_spec.rb
|
256
|
+
- spec/examples/forwardable_delegation_spec.rb
|
257
|
+
- spec/shared/author.rb
|
258
|
+
- spec/shared/basic.rb
|
259
|
+
- spec/shared/nil_check.rb
|
260
|
+
- spec/shared/post_delegation.rb
|
261
|
+
- spec/shared/post_methods.rb
|
273
262
|
- spec/spec_helper.rb
|
263
|
+
- spec/to_a_class_method_spec.rb
|
264
|
+
- spec/to_a_class_variable_spec.rb
|
265
|
+
- spec/to_a_constant_spec.rb
|
266
|
+
- spec/to_an_instance_method_spec.rb
|
267
|
+
- spec/to_an_instance_variable_spec.rb
|
268
|
+
- spec/to_an_object_spec.rb
|
269
|
+
- spec/to_multiple_targets_spec.rb
|
270
|
+
- spec/with_args_spec.rb
|
271
|
+
- spec/with_as_spec.rb
|
272
|
+
- spec/with_block_spec.rb
|
273
|
+
- spec/with_prefix_spec.rb
|
274
|
+
- spec/with_return_value_spec.rb
|
275
|
+
- spec/with_to_spec.rb
|
data/.bundle/config
DELETED