Skip to content

Commit

Permalink
Fix have_attributes on objects that define #send.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Jan 24, 2024
1 parent 54a9b9c commit 1da1596
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/sus/have.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def call(assertions, subject)
assertions.nested(self) do |assertions|
assertions.assert(subject.respond_to?(@name), "has attribute")
if @predicate
Expect.new(assertions, subject.send(@name)).to(@predicate)
Expect.new(assertions, subject.public_send(@name)).to(@predicate)
end
end
end
Expand Down
22 changes: 22 additions & 0 deletions test/sus/have.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

User = Struct.new(:name, :age)

require 'socket'

describe Sus::Have do
describe User do
let(:user) {subject.new("Sus", 20)}
Expand Down Expand Up @@ -34,6 +36,26 @@
end
end

describe Socket do
def before
super

@socket = Socket.new(:INET, :STREAM)
end

def after
@socket.close

super
end

it 'can use have_attributes on object that defines #send' do
skip_unless_method_defined(:timeout, Socket)

expect(@socket).to have_attributes(timeout: be_nil)
end
end

describe Array do
let(:array) {[1, 2, 3]}

Expand Down

0 comments on commit 1da1596

Please sign in to comment.