diff --git a/lib/rspec/its.rb b/lib/rspec/its.rb index 8345f2c..d6bd9fb 100644 --- a/lib/rspec/its.rb +++ b/lib/rspec/its.rb @@ -112,7 +112,11 @@ def its(attribute, *options, &block) else attribute_chain = attribute.to_s.split('.') attribute_chain.inject(subject) do |inner_subject, attr| - inner_subject.send(attr) + if inner_subject.respond_to?(:public_send) + inner_subject.public_send(attr) + else + inner_subject.send(attr) + end end end end diff --git a/spec/rspec/its_spec.rb b/spec/rspec/its_spec.rb index 91eed5f..120ff0b 100644 --- a/spec/rspec/its_spec.rb +++ b/spec/rspec/its_spec.rb @@ -218,6 +218,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) unless RUBY_VERSION == '1.8.7' + end + end + end + end end context "with metadata" do context "preserves access to metadata that doesn't end in hash" do