Skip to content

Commit

Permalink
Fix frozen string literal warning in Mockery
Browse files Browse the repository at this point in the history
Thanks to @radville for pointing this out in #669. I've tackled it
slightly differently by using an Array to build up the lines and then
joining them into a String at the end rather than calling `String#dup`
multiple times.

Previously I was seeing a lot of the following warnings when running
the tests under Ruby v3.4:

    lib/mocha/mockery.rb:118: warning: literal string will be frozen in the future
  • Loading branch information
floehopper committed Jul 30, 2024
1 parent c4fe850 commit 55dd0fc
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/mocha/mockery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ def sequences
end

def mocha_inspect
message = ''
message << "unsatisfied expectations:\n- #{unsatisfied_expectations.map(&:mocha_inspect).join("\n- ")}\n" if unsatisfied_expectations.any?
message << "satisfied expectations:\n- #{satisfied_expectations.map(&:mocha_inspect).join("\n- ")}\n" if satisfied_expectations.any?
message << "states:\n- #{state_machines.map(&:mocha_inspect).join("\n- ")}\n" if state_machines.any?
message
lines = []
lines << "unsatisfied expectations:\n- #{unsatisfied_expectations.map(&:mocha_inspect).join("\n- ")}\n" if unsatisfied_expectations.any?
lines << "satisfied expectations:\n- #{satisfied_expectations.map(&:mocha_inspect).join("\n- ")}\n" if satisfied_expectations.any?
lines << "states:\n- #{state_machines.map(&:mocha_inspect).join("\n- ")}\n" if state_machines.any?
lines.join
end

def on_stubbing(object, method)
Expand Down

0 comments on commit 55dd0fc

Please sign in to comment.