Skip to content

Commit 8fabcc7

Browse files
committed
Use public_send
1 parent b4a28c0 commit 8fabcc7

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

lib/rspec/its/subject.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def for(attribute, subject)
1515
else
1616
attribute_chain = attribute.to_s.split('.')
1717
attribute_chain.inject(subject) do |inner_subject, attr|
18-
inner_subject.send(attr)
18+
inner_subject.public_send(attr)
1919
end
2020
end
2121
end

spec/rspec/its_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,4 +393,32 @@ def self.example(*_args)
393393

394394
its(:will_still_work) { is_expected.to be true }
395395
end
396+
397+
context "with private method" do
398+
subject(:klass) do
399+
Class.new do
400+
def name
401+
private_name
402+
end
403+
404+
private
405+
406+
def private_name
407+
"John"
408+
end
409+
end.new
410+
end
411+
412+
context "when referring indirectly" do
413+
its(:name) { is_expected.to eq "John" }
414+
end
415+
416+
context "when attempting to refer directly" do
417+
context "it raises an error" do
418+
its(:private_name) do
419+
expect { is_expected.to eq("John") }.to raise_error(NoMethodError)
420+
end
421+
end
422+
end
423+
end
396424
end

0 commit comments

Comments
 (0)