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
data/spec/lib/shared/block.rb
DELETED
@@ -1,71 +0,0 @@
|
|
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 with its own block' do
|
26
|
-
# rubocop:disable Style/SymbolProc
|
27
|
-
it { should delegate(:tainted?).to(:@authors).as(:all?).with_block { |a| a.tainted? } }
|
28
|
-
it { should_not delegate(:tainted?).to(:@authors).as(:all?).with_block { |a| a.to_s } }
|
29
|
-
|
30
|
-
describe 'description' do
|
31
|
-
before { matcher.matches? subject }
|
32
|
-
|
33
|
-
context 'with a block' do
|
34
|
-
let(:matcher) { delegate(:tainted?).to(:@authors).as(:all?).with_block { |a| a.tainted? } }
|
35
|
-
it { expect(matcher.description).to eq "delegate tainted? to @authors.all? with block 'proc { |a| a.tainted? }'" }
|
36
|
-
it { expect(matcher.failure_message_when_negated).to match(/a block was passed/) }
|
37
|
-
end
|
38
|
-
|
39
|
-
context 'with a different block' do
|
40
|
-
let(:matcher) { delegate(:tainted?).to(:@authors).as(:all?).with_block { |a| a.to_s } }
|
41
|
-
it { expect(matcher.failure_message).to match(/a different block 'proc { |a| a.tainted? }' was passed/) }
|
42
|
-
end
|
43
|
-
|
44
|
-
context 'without a block' do
|
45
|
-
let(:matcher) { delegate(:tainted?).to(:@authors).as(:all?).without_block }
|
46
|
-
it { expect(matcher.failure_message).to match(/a block was passed/) }
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
shared_examples 'a delegator without a block' do
|
52
|
-
it { should delegate(:name).to(receiver).without_block }
|
53
|
-
it { should delegate(:name).to(receiver).without_a_block }
|
54
|
-
|
55
|
-
it { should_not delegate(:name).to(receiver).with_block }
|
56
|
-
it { should_not delegate(:name).to(receiver).with_a_block }
|
57
|
-
|
58
|
-
describe 'failure messages' do
|
59
|
-
before { matcher.matches? subject }
|
60
|
-
|
61
|
-
context 'with a block' do
|
62
|
-
let(:matcher) { delegate(:name).to(receiver).with_a_block }
|
63
|
-
it { expect(matcher.failure_message).to match(/a block was not passed/) }
|
64
|
-
end
|
65
|
-
|
66
|
-
context 'without a block' do
|
67
|
-
let(:matcher) { delegate(:name).to(receiver).without_a_block }
|
68
|
-
it { expect(matcher.failure_message_when_negated).to match(/a block was not passed/) }
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
@@ -1,12 +0,0 @@
|
|
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
|
@@ -1,19 +0,0 @@
|
|
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
|
data/spec/lib/shared/prefix.rb
DELETED
@@ -1,16 +0,0 @@
|
|
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
|