diff --git a/lib/rspec/its.rb b/lib/rspec/its.rb index 223606e..7217a94 100644 --- a/lib/rspec/its.rb +++ b/lib/rspec/its.rb @@ -112,7 +112,7 @@ def its(attribute, *options, &block) else attribute_chain = attribute.to_s.split('.') attribute_chain.inject(subject) do |inner_subject, attr| - inner_subject.send(attr) + inner_subject.public_send(attr) end end end diff --git a/spec/rspec/its_spec.rb b/spec/rspec/its_spec.rb index 4ba6422..e98ee35 100644 --- a/spec/rspec/its_spec.rb +++ b/spec/rspec/its_spec.rb @@ -211,6 +211,34 @@ def false_if_first_time expect(status).to eq(:passed) end end + + describe "with private method" do + subject do + Class.new do + def name + private_name + end + private + def private_name + "John" + end + end.new + end + + context "when referring indirectly" do + its(:name) { is_expected.to eq "John" } + end + + context "when attempting to refer directly" do + context "it raises an error" do + its(:private_name) do + expect do + should eq("John") + end.to raise_error(NoMethodError) + end + end + end + end end end end