Skip to content

Commit 817bd4e

Browse files
authored
Merge pull request #101 from rspec/use-public-send
Use public_send
2 parents b4a28c0 + 9ee0cff commit 817bd4e

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

Diff for: Changelog.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
### 2.0.0.pre
22

3-
Version 2.0.0 is a maintenance release, it drops support for Ruby below 3, and
4-
changes the supported RSpec version to "main" and current release series.
5-
(At the time of writing this is 3.13.x, but it means the current supported
6-
release only).
3+
Version 2.0.0 drops support for Ruby below 3, and changes the supported RSpec version to "main" and current release series.
4+
(At the time of writing this is 3.13.x, but it means the current supported release only).
5+
6+
Breaking changes:
7+
8+
* Now uses `public_send` so that private methods will not be accidentally reachable. (James Ottaway #33, #101)
79

810
### 1.3.1 / 2024-10-23
911
[full changelog](http://github.com/rspec/rspec-its/compare/v1.3.0...v1.3.1)

Diff for: lib/rspec/its/subject.rb

+1-1
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

Diff for: spec/rspec/its_spec.rb

+28
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)