delegate_matcher 0.3 → 0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +3 -3
  3. data/README.md +101 -8
  4. data/README.md.erb +216 -0
  5. data/Rakefile +6 -1
  6. data/delegate_matcher.gemspec +1 -1
  7. data/lib/delegate_matcher/delegate.rb +5 -12
  8. data/lib/delegate_matcher/delegate_matcher.rb +5 -14
  9. data/lib/delegate_matcher/delegation.rb +32 -23
  10. data/lib/delegate_matcher/dispatcher.rb +4 -1
  11. data/lib/delegate_matcher/expected.rb +31 -18
  12. data/lib/delegate_matcher/nil_delegate.rb +3 -2
  13. data/lib/delegate_matcher/stub_delegate.rb +7 -3
  14. data/lib/delegate_matcher/version.rb +1 -1
  15. data/spec/{lib → examples}/active_support_delegation_spec.rb +11 -2
  16. data/spec/{lib → examples}/forwardable_delegation_spec.rb +11 -2
  17. data/spec/shared/author.rb +23 -0
  18. data/spec/{lib/shared/a_simple_delegator.rb → shared/basic.rb} +4 -6
  19. data/spec/{lib/shared → shared}/nil_check.rb +15 -15
  20. data/spec/shared/post_delegation.rb +42 -0
  21. data/spec/shared/post_methods.rb +15 -0
  22. data/spec/spec_helper.rb +1 -1
  23. data/spec/to_a_class_method_spec.rb +37 -0
  24. data/spec/to_a_class_variable_spec.rb +38 -0
  25. data/spec/to_a_constant_spec.rb +37 -0
  26. data/spec/to_an_instance_method_spec.rb +39 -0
  27. data/spec/to_an_instance_variable_spec.rb +35 -0
  28. data/spec/to_an_object_spec.rb +45 -0
  29. data/spec/to_multiple_targets_spec.rb +34 -0
  30. data/spec/with_args_spec.rb +151 -0
  31. data/spec/with_as_spec.rb +25 -0
  32. data/spec/with_block_spec.rb +75 -0
  33. data/spec/with_prefix_spec.rb +37 -0
  34. data/spec/with_return_value_spec.rb +46 -0
  35. data/spec/with_to_spec.rb +53 -0
  36. metadata +45 -43
  37. data/.bundle/config +0 -3
  38. data/spec/lib/aggregate_delegate_matcher_spec.rb +0 -62
  39. data/spec/lib/class_method_spec.rb +0 -84
  40. data/spec/lib/class_variable_spec.rb +0 -85
  41. data/spec/lib/constant_spec.rb +0 -86
  42. data/spec/lib/delegate_spec.rb +0 -15
  43. data/spec/lib/instance_method_spec.rb +0 -84
  44. data/spec/lib/instance_variable_spec.rb +0 -102
  45. data/spec/lib/object_spec.rb +0 -103
  46. data/spec/lib/shared/args.rb +0 -24
  47. data/spec/lib/shared/args_and_a_block.rb +0 -6
  48. data/spec/lib/shared/author.rb +0 -10
  49. data/spec/lib/shared/block.rb +0 -71
  50. data/spec/lib/shared/different_method_name.rb +0 -12
  51. data/spec/lib/shared/different_return_value.rb +0 -19
  52. data/spec/lib/shared/prefix.rb +0 -16
@@ -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
@@ -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