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

Updates for frozen-string-literal compatibility. #1165

Merged
merged 1 commit into from
Jun 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions lib/rspec/mocks/error_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ def raise_unexpected_message_args_error(expectation, args_for_multiple_calls, so

# @private
def raise_missing_default_stub_error(expectation, args_for_multiple_calls)
message = error_message(expectation, args_for_multiple_calls)
message << "\n Please stub a default value first if message might be received with other args as well. \n"

__raise message
__raise(
error_message(expectation, args_for_multiple_calls) +
"\n Please stub a default value first if message might be received with other args as well. \n"
)
end

# @private
Expand All @@ -69,7 +69,7 @@ def raise_similar_message_args_error(expectation, args_for_multiple_calls, backt
end

def default_error_message(expectation, expected_args, actual_args)
"#{intro} received #{expectation.message.inspect} #{unexpected_arguments_message(expected_args, actual_args)}"
"#{intro} received #{expectation.message.inspect} #{unexpected_arguments_message(expected_args, actual_args)}".dup
end

# rubocop:disable Style/ParameterLists
Expand All @@ -87,14 +87,14 @@ def raise_expectation_error(message, expected_received_count, argument_list_matc
def raise_unimplemented_error(doubled_module, method_name, object)
message = case object
when InstanceVerifyingDouble
"the %s class does not implement the instance method: %s" <<
"the %s class does not implement the instance method: %s".dup <<
if ObjectMethodReference.for(doubled_module, method_name).implemented?
". Perhaps you meant to use `class_double` instead?"
else
""
end
when ClassVerifyingDouble
"the %s class does not implement the class method: %s" <<
"the %s class does not implement the class method: %s".dup <<
if InstanceMethodReference.for(doubled_module, method_name).implemented?
". Perhaps you meant to use `instance_double` instead?"
else
Expand Down
8 changes: 4 additions & 4 deletions spec/rspec/mocks/any_instance_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -378,12 +378,12 @@ def private_method; :private_method_return_value; end

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

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

it "works with the non-standard constructor module" do
Expand Down Expand Up @@ -545,10 +545,10 @@ def inspect

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

expect_any_instance_of(Object).to receive(:foo)
'something'.foo
'something'.dup.foo
end

it "does not modify the return value of stubs set on an instance" do
Expand Down
2 changes: 1 addition & 1 deletion spec/rspec/mocks/diffing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def inspect
expect(RSpec::Support.is_a_matcher?(collab)).to be true

collab_inspect = collab.inspect
collab_pp = PP.pp(collab, "").strip
collab_pp = PP.pp(collab, "".dup).strip

expect(d).to receive(:foo).with(collab)
expect {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Mocks
end

example "for a raw message expectation on a partial double" do
expect(allow("partial double").to receive(:foo)).to have_string_representation(
expect(allow("partial double".dup).to receive(:foo)).to have_string_representation(
'#<RSpec::Mocks::MessageExpectation "partial double".foo(any arguments)>'
)
end
Expand Down
8 changes: 4 additions & 4 deletions spec/rspec/mocks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

describe ".teardown" do
it "resets method stubs" do
string = "foo"
string = "foo".dup
allow(string).to receive(:bar)
RSpec::Mocks.teardown
expect { string.bar }.to raise_error(NoMethodError)
Expand All @@ -56,7 +56,7 @@
RSpec::Mocks.teardown
RSpec::Mocks.teardown

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

RSpec::Mocks.setup
Expand Down Expand Up @@ -157,10 +157,10 @@
before(:all) do
RSpec::Mocks.with_temporary_scope do
allow_any_instance_of(String).to receive(:sum_with) { |val, x| val + x }
@sum = "foo".sum_with("bar")
@sum = "foo".dup.sum_with("bar")
end

capture_error { "you".sum_with("me") }
capture_error { "you".dup.sum_with("me") }
end

it 'allows the stub to be used' do
Expand Down