Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit 38015e1

Browse files
patmyronmarston
authored andcommitted
Updates for frozen-string-literal compatibility. (#1165)
1 parent cd7adc9 commit 38015e1

File tree

5 files changed

+17
-17
lines changed

5 files changed

+17
-17
lines changed

lib/rspec/mocks/error_generator.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ def raise_unexpected_message_args_error(expectation, args_for_multiple_calls, so
5757

5858
# @private
5959
def raise_missing_default_stub_error(expectation, args_for_multiple_calls)
60-
message = error_message(expectation, args_for_multiple_calls)
61-
message << "\n Please stub a default value first if message might be received with other args as well. \n"
62-
63-
__raise message
60+
__raise(
61+
error_message(expectation, args_for_multiple_calls) +
62+
"\n Please stub a default value first if message might be received with other args as well. \n"
63+
)
6464
end
6565

6666
# @private
@@ -69,7 +69,7 @@ def raise_similar_message_args_error(expectation, args_for_multiple_calls, backt
6969
end
7070

7171
def default_error_message(expectation, expected_args, actual_args)
72-
"#{intro} received #{expectation.message.inspect} #{unexpected_arguments_message(expected_args, actual_args)}"
72+
"#{intro} received #{expectation.message.inspect} #{unexpected_arguments_message(expected_args, actual_args)}".dup
7373
end
7474

7575
# rubocop:disable Style/ParameterLists
@@ -87,14 +87,14 @@ def raise_expectation_error(message, expected_received_count, argument_list_matc
8787
def raise_unimplemented_error(doubled_module, method_name, object)
8888
message = case object
8989
when InstanceVerifyingDouble
90-
"the %s class does not implement the instance method: %s" <<
90+
"the %s class does not implement the instance method: %s".dup <<
9191
if ObjectMethodReference.for(doubled_module, method_name).implemented?
9292
". Perhaps you meant to use `class_double` instead?"
9393
else
9494
""
9595
end
9696
when ClassVerifyingDouble
97-
"the %s class does not implement the class method: %s" <<
97+
"the %s class does not implement the class method: %s".dup <<
9898
if InstanceMethodReference.for(doubled_module, method_name).implemented?
9999
". Perhaps you meant to use `instance_double` instead?"
100100
else

spec/rspec/mocks/any_instance_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,12 +378,12 @@ def private_method; :private_method_return_value; end
378378

379379
it "works with the non-standard constructor \"\"" do
380380
allow_any_instance_of(String).to receive(:foo).and_return(1)
381-
expect("".foo).to eq(1)
381+
expect("".dup.foo).to eq(1)
382382
end
383383

384384
it "works with the non-standard constructor \'\'" do
385385
allow_any_instance_of(String).to receive(:foo).and_return(1)
386-
expect(''.foo).to eq(1)
386+
expect(''.dup.foo).to eq(1)
387387
end
388388

389389
it "works with the non-standard constructor module" do
@@ -545,10 +545,10 @@ def inspect
545545

546546
it "does not set the expectation on every instance" do
547547
# Setup an unrelated object of the same class that won't receive the expected message.
548-
allow('non-related object').to receive(:non_related_method)
548+
allow('non-related object'.dup).to receive(:non_related_method)
549549

550550
expect_any_instance_of(Object).to receive(:foo)
551-
'something'.foo
551+
'something'.dup.foo
552552
end
553553

554554
it "does not modify the return value of stubs set on an instance" do

spec/rspec/mocks/diffing_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def inspect
157157
expect(RSpec::Support.is_a_matcher?(collab)).to be true
158158

159159
collab_inspect = collab.inspect
160-
collab_pp = PP.pp(collab, "").strip
160+
collab_pp = PP.pp(collab, "".dup).strip
161161

162162
expect(d).to receive(:foo).with(collab)
163163
expect {

spec/rspec/mocks/message_expectation_string_representation_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module Mocks
1010
end
1111

1212
example "for a raw message expectation on a partial double" do
13-
expect(allow("partial double").to receive(:foo)).to have_string_representation(
13+
expect(allow("partial double".dup).to receive(:foo)).to have_string_representation(
1414
'#<RSpec::Mocks::MessageExpectation "partial double".foo(any arguments)>'
1515
)
1616
end

spec/rspec/mocks_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
describe ".teardown" do
4747
it "resets method stubs" do
48-
string = "foo"
48+
string = "foo".dup
4949
allow(string).to receive(:bar)
5050
RSpec::Mocks.teardown
5151
expect { string.bar }.to raise_error(NoMethodError)
@@ -56,7 +56,7 @@
5656
RSpec::Mocks.teardown
5757
RSpec::Mocks.teardown
5858

59-
string = "foo"
59+
string = "foo".dup
6060
expect { allow(string).to receive(:bar) }.to raise_error(RSpec::Mocks::OutsideOfExampleError)
6161

6262
RSpec::Mocks.setup
@@ -157,10 +157,10 @@
157157
before(:all) do
158158
RSpec::Mocks.with_temporary_scope do
159159
allow_any_instance_of(String).to receive(:sum_with) { |val, x| val + x }
160-
@sum = "foo".sum_with("bar")
160+
@sum = "foo".dup.sum_with("bar")
161161
end
162162

163-
capture_error { "you".sum_with("me") }
163+
capture_error { "you".dup.sum_with("me") }
164164
end
165165

166166
it 'allows the stub to be used' do

0 commit comments

Comments
 (0)