shoulda-matchers 2.6.2 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/Appraisals +6 -1
  3. data/Gemfile +1 -1
  4. data/Gemfile.lock +26 -22
  5. data/NEWS.md +52 -1
  6. data/README.md +8 -6
  7. data/Rakefile +1 -1
  8. data/doc_config/gh-pages/index.html.erb +1 -1
  9. data/doc_config/yard/templates/default/fulldoc/html/css/global.css +1 -1
  10. data/doc_config/yard/templates/default/fulldoc/html/css/style.css +26 -0
  11. data/features/rails_integration.feature +18 -3
  12. data/features/step_definitions/rails_steps.rb +21 -3
  13. data/gemfiles/3.0.gemfile +1 -1
  14. data/gemfiles/3.0.gemfile.lock +30 -24
  15. data/gemfiles/3.1.gemfile +1 -1
  16. data/gemfiles/3.1.gemfile.lock +32 -26
  17. data/gemfiles/3.1_1.9.2.gemfile +1 -1
  18. data/gemfiles/3.1_1.9.2.gemfile.lock +22 -19
  19. data/gemfiles/3.2.gemfile +1 -1
  20. data/gemfiles/3.2.gemfile.lock +32 -26
  21. data/gemfiles/3.2_1.9.2.gemfile +1 -1
  22. data/gemfiles/3.2_1.9.2.gemfile.lock +8 -8
  23. data/gemfiles/4.0.0.gemfile +2 -2
  24. data/gemfiles/4.0.0.gemfile.lock +35 -31
  25. data/gemfiles/4.0.1.gemfile +2 -2
  26. data/gemfiles/4.0.1.gemfile.lock +24 -22
  27. data/gemfiles/4.1.gemfile +1 -1
  28. data/gemfiles/4.1.gemfile.lock +26 -22
  29. data/lib/shoulda/matchers/action_controller/filter_param_matcher.rb +10 -3
  30. data/lib/shoulda/matchers/action_controller/set_session_matcher.rb +24 -6
  31. data/lib/shoulda/matchers/active_model.rb +2 -2
  32. data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +1 -1
  33. data/lib/shoulda/matchers/active_model/ensure_length_of_matcher.rb +1 -1
  34. data/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb +5 -3
  35. data/lib/shoulda/matchers/active_model/{ensure_exclusion_of_matcher.rb → validate_exclusion_of_matcher.rb} +20 -10
  36. data/lib/shoulda/matchers/active_model/{ensure_inclusion_of_matcher.rb → validate_inclusion_of_matcher.rb} +52 -28
  37. data/lib/shoulda/matchers/active_model/validate_uniqueness_of_matcher.rb +28 -19
  38. data/lib/shoulda/matchers/active_record.rb +18 -16
  39. data/lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb +4 -4
  40. data/lib/shoulda/matchers/active_record/association_matcher.rb +17 -12
  41. data/lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb +86 -0
  42. data/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb +19 -0
  43. data/lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb +2 -1
  44. data/lib/shoulda/matchers/active_record/define_enum_for_matcher.rb +138 -0
  45. data/lib/shoulda/matchers/independent.rb +3 -2
  46. data/lib/shoulda/matchers/independent/{delegate_matcher.rb → delegate_method_matcher.rb} +69 -49
  47. data/lib/shoulda/matchers/independent/delegate_method_matcher/stubbed_target.rb +37 -0
  48. data/lib/shoulda/matchers/independent/delegate_method_matcher/target_not_defined_error.rb +15 -0
  49. data/lib/shoulda/matchers/version.rb +1 -1
  50. data/lib/shoulda/matchers/warn.rb +30 -2
  51. data/spec/shoulda/matchers/action_controller/filter_param_matcher_spec.rb +6 -0
  52. data/spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb +67 -5
  53. data/spec/shoulda/matchers/action_controller/strong_parameters_matcher_spec.rb +9 -9
  54. data/spec/shoulda/matchers/active_model/validate_absence_of_matcher_spec.rb +30 -3
  55. data/spec/shoulda/matchers/active_model/{ensure_exclusion_of_matcher_spec.rb → validate_exclusion_of_matcher_spec.rb} +29 -13
  56. data/spec/shoulda/matchers/active_model/{ensure_inclusion_of_matcher_spec.rb → validate_inclusion_of_matcher_spec.rb} +34 -16
  57. data/spec/shoulda/matchers/active_model/validate_uniqueness_of_matcher_spec.rb +35 -0
  58. data/spec/shoulda/matchers/active_record/association_matcher_spec.rb +56 -1
  59. data/spec/shoulda/matchers/active_record/define_enum_for_matcher_spec.rb +101 -0
  60. data/spec/shoulda/matchers/doublespeak/object_double_spec.rb +6 -6
  61. data/spec/shoulda/matchers/independent/{delegate_matcher → delegate_method_matcher}/stubbed_target_spec.rb +1 -1
  62. data/spec/shoulda/matchers/independent/{delegate_matcher_spec.rb → delegate_method_matcher_spec.rb} +88 -29
  63. data/spec/spec_helper.rb +2 -3
  64. data/spec/support/fail_with_message_including_matcher.rb +14 -3
  65. data/spec/support/fail_with_message_matcher.rb +14 -2
  66. data/spec/support/rails_versions.rb +4 -0
  67. metadata +19 -14
  68. data/lib/shoulda/matchers/independent/delegate_matcher/stubbed_target.rb +0 -35
@@ -1,6 +1,22 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Shoulda::Matchers::ActiveModel::EnsureInclusionOfMatcher do
3
+ describe Shoulda::Matchers::ActiveModel do
4
+ describe '#ensure_inclusion_of' do
5
+ it 'is aliased to #validate_inclusion_of' do
6
+ matchers.expects(:validate_inclusion_of).with(:attr)
7
+
8
+ silence_warnings do
9
+ matchers.ensure_inclusion_of(:attr)
10
+ end
11
+ end
12
+ end
13
+
14
+ def matchers
15
+ @_matchers ||= Object.new.extend(described_class)
16
+ end
17
+ end
18
+
19
+ describe Shoulda::Matchers::ActiveModel::ValidateInclusionOfMatcher do
4
20
  shared_context 'for a generic attribute' do
5
21
  def self.testing_values_of_option(option_name, &block)
6
22
  [nil, true, false].each do |option_value|
@@ -172,7 +188,7 @@ describe Shoulda::Matchers::ActiveModel::EnsureInclusionOfMatcher do
172
188
  end
173
189
 
174
190
  it 'does not match when validation uses the default message instead of given message' do
175
- pending 'does not work'
191
+ skip 'does not work'
176
192
 
177
193
  builder = build_object_allowing(valid_values)
178
194
 
@@ -182,7 +198,7 @@ describe Shoulda::Matchers::ActiveModel::EnsureInclusionOfMatcher do
182
198
  end
183
199
 
184
200
  it 'does not match when validation uses a message but it is not same as given' do
185
- pending 'does not work'
201
+ skip 'does not work'
186
202
 
187
203
  builder = build_object_allowing(valid_values, message: 'a different message')
188
204
 
@@ -202,7 +218,7 @@ describe Shoulda::Matchers::ActiveModel::EnsureInclusionOfMatcher do
202
218
  end
203
219
 
204
220
  it 'does not match when validation uses the default message instead of given message' do
205
- pending 'does not work'
221
+ skip 'does not work'
206
222
 
207
223
  builder = build_object_allowing(valid_values)
208
224
 
@@ -212,7 +228,7 @@ describe Shoulda::Matchers::ActiveModel::EnsureInclusionOfMatcher do
212
228
  end
213
229
 
214
230
  it 'does not match when validation uses a message but it does not match regex' do
215
- pending 'does not work'
231
+ skip 'does not work'
216
232
 
217
233
  builder = build_object_allowing(valid_values, message: 'a different message')
218
234
 
@@ -433,16 +449,18 @@ describe Shoulda::Matchers::ActiveModel::EnsureInclusionOfMatcher do
433
449
  end
434
450
  end
435
451
 
436
- it 'prints a warning' do
437
- valid_values = [true, false]
438
- builder = build_object_allowing(valid_values)
439
- message = 'You are using `ensure_inclusion_of` to assert that a boolean column allows boolean values and disallows non-boolean ones'
452
+ [[false, true], [true, false]].each do |booleans|
453
+ it 'prints a warning' do
454
+ valid_values = booleans
455
+ builder = build_object_allowing(valid_values)
456
+ message = 'You are using `validate_inclusion_of` to assert that a boolean column allows boolean values and disallows non-boolean ones'
440
457
 
441
- stderr = capture(:stderr) do
442
- expect_to_match_in_array(builder, valid_values)
443
- end
458
+ stderr = capture(:stderr) do
459
+ expect_to_match_in_array(builder, valid_values)
460
+ end
444
461
 
445
- expect(stderr.gsub(/\n+/, ' ')).to include(message)
462
+ expect(stderr.gsub(/\n+/, ' ')).to include(message)
463
+ end
446
464
  end
447
465
  end
448
466
  end
@@ -466,7 +484,7 @@ describe Shoulda::Matchers::ActiveModel::EnsureInclusionOfMatcher do
466
484
  it 'prints a warning' do
467
485
  valid_values = [nil]
468
486
  builder = build_object_allowing(valid_values)
469
- message = 'You are using `ensure_inclusion_of` to assert that a boolean column allows nil'
487
+ message = 'You are using `validate_inclusion_of` to assert that a boolean column allows nil'
470
488
 
471
489
  stderr = capture(:stderr) do
472
490
  expect_to_match_in_array(builder, valid_values)
@@ -599,13 +617,13 @@ describe Shoulda::Matchers::ActiveModel::EnsureInclusionOfMatcher do
599
617
  end
600
618
 
601
619
  def expect_to_match(builder)
602
- matcher = ensure_inclusion_of(builder.attribute)
620
+ matcher = validate_inclusion_of(builder.attribute)
603
621
  yield matcher if block_given?
604
622
  expect(builder.object).to(matcher)
605
623
  end
606
624
 
607
625
  def expect_not_to_match(builder)
608
- matcher = ensure_inclusion_of(builder.attribute)
626
+ matcher = validate_inclusion_of(builder.attribute)
609
627
  yield matcher if block_given?
610
628
  expect(builder.object).not_to(matcher)
611
629
  end
@@ -47,6 +47,41 @@ describe Shoulda::Matchers::ActiveModel::ValidateUniquenessOfMatcher do
47
47
  expect(Example.count).to eq 0
48
48
  expect(validating_uniqueness_with_other).to matcher
49
49
  end
50
+
51
+ context "and the table uses non-nullable columns, set beforehand" do
52
+ it "does not require the record to be persisted" do
53
+ model = define_model_with_non_nullable_column
54
+ record = model.new(required_attribute_name => "some value")
55
+ expect(record).to validate_uniqueness_of(unique_attribute_name)
56
+ end
57
+
58
+ def define_model_with_non_nullable_column
59
+ model = define_model(:example,
60
+ unique_attribute_name => :string,
61
+ required_attribute_name => {
62
+ type: :string,
63
+ options: { null: false }
64
+ }
65
+ )
66
+
67
+ model.tap do
68
+ model.attr_accessible(
69
+ required_attribute_name,
70
+ unique_attribute_name
71
+ )
72
+ model.validates_presence_of(required_attribute_name)
73
+ model.validates_uniqueness_of(unique_attribute_name)
74
+ end
75
+ end
76
+
77
+ def required_attribute_name
78
+ :required_attribute_name
79
+ end
80
+
81
+ def unique_attribute_name
82
+ :unique_attribute_name
83
+ end
84
+ end
50
85
  end
51
86
 
52
87
  def define_model_with_other(options = {})
@@ -712,7 +712,62 @@ describe Shoulda::Matchers::ActiveRecord::AssociationMatcher do
712
712
  has_and_belongs_to_many :relatives
713
713
  end
714
714
 
715
- expect(Person.new).not_to have_and_belong_to_many(:relatives)
715
+ expected_failure_message = "join table people_relatives doesn't exist"
716
+
717
+ expect do
718
+ expect(Person.new).to have_and_belong_to_many(:relatives)
719
+ end.to fail_with_message_including(expected_failure_message)
720
+ end
721
+
722
+ it 'rejects an association with a join table with incorrect columns' do
723
+ define_model :relative
724
+ define_model :person do
725
+ has_and_belongs_to_many :relatives
726
+ end
727
+
728
+ define_model :people_relative, id: false, some_crazy_id: :integer
729
+
730
+ expect do
731
+ expect(Person.new).to have_and_belong_to_many(:relatives)
732
+ end.to fail_with_message_including('missing columns: person_id, relative_id')
733
+ end
734
+
735
+ context 'using a custom foreign key' do
736
+ it 'rejects an association with a join table with incorrect columns' do
737
+ define_model :relative
738
+ define_model :person do
739
+ has_and_belongs_to_many :relatives,
740
+ foreign_key: :custom_foreign_key_id
741
+ end
742
+
743
+ define_model :people_relative,
744
+ id: false,
745
+ custom_foreign_key_id: :integer,
746
+ some_crazy_id: :integer
747
+
748
+ expect do
749
+ expect(Person.new).to have_and_belong_to_many(:relatives)
750
+ end.to fail_with_message_including('missing columns: custom_foreign_key_id, relative_id')
751
+ end
752
+ end
753
+
754
+ context 'using a custom association foreign key' do
755
+ it 'rejects an association with a join table with incorrect columns' do
756
+ define_model :relative
757
+ define_model :person do
758
+ has_and_belongs_to_many :relatives,
759
+ association_foreign_key: :custom_association_foreign_key_id
760
+ end
761
+
762
+ define_model :people_relative,
763
+ id: false,
764
+ custom_association_foreign_key_id: :integer,
765
+ some_crazy_id: :integer
766
+
767
+ expect do
768
+ expect(Person.new).to have_and_belong_to_many(:relatives)
769
+ end.to fail_with_message_including('missing columns: person_id, custom_association_foreign_key_id')
770
+ end
716
771
  end
717
772
 
718
773
  it 'rejects an association of the wrong type' do
@@ -0,0 +1,101 @@
1
+ require "spec_helper"
2
+
3
+ describe Shoulda::Matchers::ActiveRecord::DefineEnumForMatcher do
4
+ if active_record_supports_enum?
5
+ describe "with only the attribute name specified" do
6
+ it "accepts a record where the attribute is defined as an enum" do
7
+ expect(record_with_array_values).to define_enum_for(enum_attribute)
8
+ end
9
+
10
+ it "rejects a record where the attribute is not defined as an enum" do
11
+ message = "Expected #{record_with_array_values.class} to define :#{non_enum_attribute} as an enum"
12
+
13
+ expect do
14
+ expect(record_with_array_values).to define_enum_for(non_enum_attribute)
15
+ end.to fail_with_message(message)
16
+ end
17
+
18
+ it "rejects a record where the attribute is not defined as an enum with should not" do
19
+ message = "Did not expect #{record_with_array_values.class} to define :#{enum_attribute} as an enum"
20
+
21
+ expect do
22
+ expect(record_with_array_values).to_not define_enum_for(enum_attribute)
23
+ end.to fail_with_message(message)
24
+ end
25
+ end
26
+
27
+ describe "with both attribute name and enum values specified" do
28
+ context "when the actual enum values are an array" do
29
+ it "accepts a record where the attribute is defined as an enum and the enum values match" do
30
+ expect(record_with_array_values).to define_enum_for(enum_attribute).
31
+ with(["published", "unpublished", "draft"])
32
+ end
33
+
34
+ it "accepts a record where the attribute is not defined as an enum" do
35
+ message = %{Expected #{record_with_array_values.class} to define :#{non_enum_attribute} as an enum with ["open", "close"]}
36
+
37
+ expect do
38
+ expect(record_with_array_values).to define_enum_for(non_enum_attribute).with(["open", "close"])
39
+ end.to fail_with_message(message)
40
+ end
41
+
42
+ it "accepts a record where the attribute is defined as an enum but the enum values do not match" do
43
+ message = %{Expected #{record_with_array_values.class} to define :#{enum_attribute} as an enum with ["open", "close"]}
44
+
45
+ expect do
46
+ expect(record_with_array_values).to define_enum_for(enum_attribute).with(["open", "close"])
47
+ end.to fail_with_message(message)
48
+ end
49
+ end
50
+
51
+ context "when the actual enum values are a hash" do
52
+ it "accepts a record where the attribute is defined as an enum and the enum values match" do
53
+ expect(record_with_hash_values).to define_enum_for(enum_attribute).with(active: 0, archived: 1)
54
+ end
55
+
56
+ it "accepts a record where the enum values match when expected enum values are given as an array" do
57
+ expect(record_with_hash_values).to define_enum_for(enum_attribute).with(["active", "archived"])
58
+ end
59
+
60
+ it "accepts a record where the attribute is defined as an enum but the enum values do not match" do
61
+ message = %{Expected #{record_with_hash_values.class} to define :#{enum_attribute} as an enum with {:active=>5, :archived=>10}}
62
+
63
+ expect do
64
+ expect(record_with_hash_values).to define_enum_for(enum_attribute).with(active: 5, archived: 10)
65
+ end.to fail_with_message(message)
66
+ end
67
+
68
+ it "rejects a record where the attribute is not defined as an enum" do
69
+ message = %{Expected #{record_with_hash_values.class} to define :record_with_hash_values as an enum with {:active=>5, :archived=>10}}
70
+
71
+ expect do
72
+ expect(record_with_hash_values)
73
+ .to define_enum_for(:record_with_hash_values).with(active: 5, archived: 10)
74
+ end.to fail_with_message(message)
75
+ end
76
+ end
77
+ end
78
+
79
+ def enum_attribute
80
+ :status
81
+ end
82
+
83
+ def non_enum_attribute
84
+ :condition
85
+ end
86
+
87
+ def record_with_array_values
88
+ _enum_attribute = enum_attribute
89
+ define_model :record_with_array_values do
90
+ enum(_enum_attribute => %w(published unpublished draft))
91
+ end.new
92
+ end
93
+
94
+ def record_with_hash_values
95
+ _enum_attribute = enum_attribute
96
+ define_model :record_with_hash_values do
97
+ enum(_enum_attribute => { active: 0, archived: 1 })
98
+ end.new
99
+ end
100
+ end
101
+ end
@@ -5,17 +5,17 @@ module Shoulda::Matchers::Doublespeak
5
5
  it 'responds to any method' do
6
6
  double = described_class.new
7
7
 
8
- expect(double.respond_to?(:foo)).to be_true
9
- expect(double.respond_to?(:bar)).to be_true
10
- expect(double.respond_to?(:baz)).to be_true
8
+ expect(double.respond_to?(:foo)).to be true
9
+ expect(double.respond_to?(:bar)).to be true
10
+ expect(double.respond_to?(:baz)).to be true
11
11
  end
12
12
 
13
13
  it 'returns nil from any method call' do
14
14
  double = described_class.new
15
15
 
16
- expect(double.foo).to be_nil
17
- expect(double.bar).to be_nil
18
- expect(double.baz).to be_nil
16
+ expect(double.foo).to be nil
17
+ expect(double.bar).to be nil
18
+ expect(double.baz).to be nil
19
19
  end
20
20
 
21
21
  it 'records every method call' do
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Shoulda::Matchers::Independent::DelegateMatcher::StubbedTarget do
3
+ describe Shoulda::Matchers::Independent::DelegateMethodMatcher::StubbedTarget do
4
4
  subject(:target) { described_class.new(:stubbed_method) }
5
5
 
6
6
  describe '#has_received_method?' do
@@ -1,32 +1,68 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Shoulda::Matchers::Independent::DelegateMatcher do
3
+ describe Shoulda::Matchers::Independent::DelegateMethodMatcher do
4
4
  describe '#description' do
5
- context 'by default' do
6
- it 'states that it should delegate method to the right object' do
7
- matcher = delegate_method(:method_name).to(:target)
5
+ context 'against an instance' do
6
+ subject { Object.new }
8
7
 
9
- expect(matcher.description).
10
- to eq 'delegate method #method_name to :target'
8
+ context 'by default' do
9
+ it 'states that it should delegate method to the right object' do
10
+ matcher = delegate_method(:method_name).to(:target)
11
+
12
+ expect(matcher.description).
13
+ to eq 'delegate #method_name to #target object'
14
+ end
15
+ end
16
+
17
+ context 'with #as chain' do
18
+ it 'states that it should delegate method to the right object and method' do
19
+ matcher = delegate_method(:method_name).to(:target).as(:alternate)
20
+ message = 'delegate #method_name to #target object as #alternate'
21
+
22
+ expect(matcher.description).to eq message
23
+ end
11
24
  end
12
- end
13
25
 
14
- context 'with #as chain' do
15
- it 'states that it should delegate method to the right object and method' do
16
- matcher = delegate_method(:method_name).to(:target).as(:alternate)
17
- message = 'delegate method #method_name to :target as #alternate'
26
+ context 'with #with_argument chain' do
27
+ it 'states that it should delegate method to the right object with right argument' do
28
+ matcher = delegate_method(:method_name).to(:target).
29
+ with_arguments(:foo, bar: [1, 2])
30
+ message = 'delegate #method_name to #target object passing arguments [:foo, {:bar=>[1, 2]}]'
18
31
 
19
- expect(matcher.description).to eq message
32
+ expect(matcher.description).to eq message
33
+ end
20
34
  end
21
35
  end
22
36
 
23
- context 'with #with_argument chain' do
24
- it 'states that it should delegate method to the right object with right argument' do
25
- matcher = delegate_method(:method_name).to(:target).
26
- with_arguments(:foo, bar: [1, 2])
27
- message = 'delegate method #method_name to :target with arguments: [:foo, {:bar=>[1, 2]}]'
37
+ context 'against a class' do
38
+ subject { Object }
39
+
40
+ context 'by default' do
41
+ it 'states that it should delegate method to the right object' do
42
+ matcher = delegate_method(:method_name).to(:target)
43
+
44
+ expect(matcher.description).
45
+ to eq 'delegate .method_name to .target object'
46
+ end
47
+ end
48
+
49
+ context 'with #as chain' do
50
+ it 'states that it should delegate method to the right object and method' do
51
+ matcher = delegate_method(:method_name).to(:target).as(:alternate)
52
+ message = 'delegate .method_name to .target object as .alternate'
53
+
54
+ expect(matcher.description).to eq message
55
+ end
56
+ end
57
+
58
+ context 'with #with_argument chain' do
59
+ it 'states that it should delegate method to the right object with right argument' do
60
+ matcher = delegate_method(:method_name).to(:target).
61
+ with_arguments(:foo, bar: [1, 2])
62
+ message = 'delegate .method_name to .target object passing arguments [:foo, {:bar=>[1, 2]}]'
28
63
 
29
- expect(matcher.description).to eq message
64
+ expect(matcher.description).to eq message
65
+ end
30
66
  end
31
67
  end
32
68
  end
@@ -80,8 +116,8 @@ describe Shoulda::Matchers::Independent::DelegateMatcher do
80
116
  it 'has a failure message that indicates which method should have been delegated' do
81
117
  post_office = PostOffice.new
82
118
  message = [
83
- 'Expected PostOffice#deliver_mail to delegate to PostOffice#mailman',
84
- 'Calls on PostOffice#mailman: (none)'
119
+ 'Expected PostOffice to delegate #deliver_mail to #mailman object',
120
+ 'Method calls sent to PostOffice#mailman: (none)'
85
121
  ].join("\n")
86
122
 
87
123
  expect {
@@ -91,8 +127,8 @@ describe Shoulda::Matchers::Independent::DelegateMatcher do
91
127
 
92
128
  it 'uses the proper syntax for class methods in errors' do
93
129
  message = [
94
- 'Expected PostOffice.deliver_mail to delegate to PostOffice.mailman',
95
- 'Calls on PostOffice.mailman: (none)'
130
+ 'Expected PostOffice to delegate .deliver_mail to .mailman object',
131
+ 'Method calls sent to PostOffice.mailman: (none)'
96
132
  ].join("\n")
97
133
 
98
134
  expect {
@@ -123,7 +159,7 @@ describe Shoulda::Matchers::Independent::DelegateMatcher do
123
159
 
124
160
  it 'produces the correct failure message if the assertion was negated' do
125
161
  post_office = PostOffice.new
126
- message = 'Expected PostOffice#deliver_mail not to delegate to PostOffice#mailman, but it did'
162
+ message = 'Expected PostOffice not to delegate #deliver_mail to #mailman object, but it did'
127
163
 
128
164
  expect {
129
165
  expect(post_office).not_to delegate_method(:deliver_mail).to(:mailman)
@@ -131,6 +167,29 @@ describe Shoulda::Matchers::Independent::DelegateMatcher do
131
167
  end
132
168
  end
133
169
 
170
+ context 'given a private method that delegates properly' do
171
+ before do
172
+ define_class(:mailman)
173
+
174
+ define_class(:post_office) do
175
+ def deliver_mail
176
+ mailman.deliver_mail
177
+ end
178
+
179
+ def mailman
180
+ Mailman.new
181
+ end
182
+
183
+ private :mailman
184
+ end
185
+ end
186
+
187
+ it 'accepts' do
188
+ post_office = PostOffice.new
189
+ expect(post_office).to delegate_method(:deliver_mail).to(:mailman)
190
+ end
191
+ end
192
+
134
193
  context 'given a method that delegates properly with arguments' do
135
194
  before do
136
195
  define_class(:mailman)
@@ -155,7 +214,7 @@ describe Shoulda::Matchers::Independent::DelegateMatcher do
155
214
 
156
215
  it 'produces the correct failure message if the assertion was negated' do
157
216
  post_office = PostOffice.new
158
- message = 'Expected PostOffice#deliver_mail not to delegate to PostOffice#mailman with arguments: ["221B Baker St.", {:hastily=>true}], but it did'
217
+ message = 'Expected PostOffice not to delegate #deliver_mail to #mailman object passing arguments ["221B Baker St.", {:hastily=>true}], but it did'
159
218
 
160
219
  expect {
161
220
  expect(post_office).
@@ -177,8 +236,8 @@ describe Shoulda::Matchers::Independent::DelegateMatcher do
177
236
  it 'has a failure message that indicates which arguments were expected' do
178
237
  post_office = PostOffice.new
179
238
  message = [
180
- 'Expected PostOffice#deliver_mail to delegate to PostOffice#mailman with arguments: ["123 Nowhere Ln."]',
181
- 'Calls on PostOffice#mailman:',
239
+ 'Expected PostOffice to delegate #deliver_mail to #mailman object passing arguments ["123 Nowhere Ln."]',
240
+ 'Method calls sent to PostOffice#mailman:',
182
241
  '1) deliver_mail("221B Baker St.", {:hastily=>true})'
183
242
  ].join("\n")
184
243
 
@@ -214,7 +273,7 @@ describe Shoulda::Matchers::Independent::DelegateMatcher do
214
273
 
215
274
  it 'produces the correct failure message if the assertion was negated' do
216
275
  post_office = PostOffice.new
217
- message = 'Expected PostOffice#deliver_mail not to delegate to PostOffice#mailman as #deliver_mail_and_avoid_dogs, but it did'
276
+ message = 'Expected PostOffice not to delegate #deliver_mail to #mailman object as #deliver_mail_and_avoid_dogs, but it did'
218
277
 
219
278
  expect {
220
279
  expect(post_office).
@@ -235,8 +294,8 @@ describe Shoulda::Matchers::Independent::DelegateMatcher do
235
294
  it 'has a failure message that indicates which method was expected' do
236
295
  post_office = PostOffice.new
237
296
  message = [
238
- 'Expected PostOffice#deliver_mail to delegate to PostOffice#mailman as #watch_tv',
239
- 'Calls on PostOffice#mailman:',
297
+ 'Expected PostOffice to delegate #deliver_mail to #mailman object as #watch_tv',
298
+ 'Method calls sent to PostOffice#mailman:',
240
299
  '1) deliver_mail_and_avoid_dogs()'
241
300
  ].join("\n")
242
301