diff --git a/lib/rspec/its/subject.rb b/lib/rspec/its/subject.rb index 0efd63d..591277c 100644 --- a/lib/rspec/its/subject.rb +++ b/lib/rspec/its/subject.rb @@ -15,7 +15,7 @@ def for(attribute, subject) 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 b286baf..069c4e7 100644 --- a/spec/rspec/its_spec.rb +++ b/spec/rspec/its_spec.rb @@ -393,4 +393,32 @@ def self.example(*_args) its(:will_still_work) { is_expected.to be true } end + + context "with private method" do + subject(:klass) 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 { is_expected.to eq("John") }.to raise_error(NoMethodError) + end + end + end + end end