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

Commit 8c1e0e4

Browse files
patmyronmarston
authored andcommitted
Updates for frozen-string-literal compatibility. (#997)
1 parent 955d603 commit 8c1e0e4

File tree

9 files changed

+22
-21
lines changed

9 files changed

+22
-21
lines changed

lib/rspec/matchers/built_in/base_matcher.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ module DefaultFailureMessages
165165
# you often only need to override `description`.
166166
# @return [String]
167167
def failure_message
168-
"expected #{description_of @actual} to #{description}"
168+
"expected #{description_of @actual} to #{description}".dup
169169
end
170170

171171
# @api private
@@ -174,7 +174,7 @@ def failure_message
174174
# you often only need to override `description`.
175175
# @return [String]
176176
def failure_message_when_negated
177-
"expected #{description_of @actual} not to #{description}"
177+
"expected #{description_of @actual} not to #{description}".dup
178178
end
179179

180180
# @private

lib/rspec/matchers/built_in/be.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def failure_message_expecting(value)
270270
def validity_message
271271
return nil if predicate_accessible?
272272

273-
msg = "expected #{actual_formatted} to respond to `#{predicate}`"
273+
msg = "expected #{actual_formatted} to respond to `#{predicate}`".dup
274274

275275
if private_predicate?
276276
msg << " but `#{predicate}` is a private method"

lib/rspec/matchers/built_in/respond_to.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def matches_arity?(actual, name)
131131
end
132132

133133
def with_arity
134-
str = ''
134+
str = ''.dup
135135
str << " with #{with_arity_string}" if @expected_arity
136136
str << " #{str.length == 0 ? 'with' : 'and'} #{with_keywords_string}" if @expected_keywords && @expected_keywords.count > 0
137137
str << " #{str.length == 0 ? 'with' : 'and'} unlimited arguments" if @unlimited_arguments

lib/rspec/matchers/built_in/yield.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ def failure_message_when_negated
299299
# @private
300300
def description
301301
desc = 'yield with args'
302-
desc << "(#{expected_arg_description})" unless @expected.empty?
302+
desc = "#{desc}(#{expected_arg_description})" unless @expected.empty?
303303
desc
304304
end
305305

spec/rspec/matchers/built_in/change_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class SomethingExpected
156156

157157
context "with a string" do
158158
it "passes when actual is modified by the block" do
159-
string = "ab"
159+
string = "ab".dup
160160
expect { string << "c" }.to change { string }
161161
end
162162

spec/rspec/matchers/built_in/equal_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def inspect_object(o)
1414
end
1515

1616
it "does not match when !actual.equal?(expected)" do
17-
expect("1").not_to equal("1")
17+
expect("1").not_to equal("1".dup)
1818
end
1919

2020
it "describes itself" do
@@ -33,7 +33,7 @@ def inspect_object(o)
3333

3434
context "when the expected object's #equal? always returns true" do
3535
let(:strange_string) do
36-
string = "foo"
36+
string = "foo".dup
3737

3838
def string.equal?(other)
3939
true
@@ -96,7 +96,7 @@ def string.equal?(other)
9696
end
9797

9898
it "suggests the `eq` matcher on failure" do
99-
expected, actual = "1", "1"
99+
expected, actual = "1", "1".dup
100100
expect {
101101
expect(actual).to equal(expected)
102102
}.to fail_with <<-MESSAGE

spec/rspec/matchers/built_in/operators_spec.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def method_missing(name, *args, &block)
1515
RSpec.describe "operator matchers", :uses_should do
1616
describe "should ==" do
1717
it "delegates message to target" do
18-
subject = "apple"
18+
subject = "apple".dup
1919
expect(subject).to receive(:==).with("apple").and_return(true)
2020
subject.should == "apple"
2121
end
@@ -75,7 +75,7 @@ def method_missing(name, *args, &block)
7575

7676
describe "should_not ==" do
7777
it "delegates message to target" do
78-
subject = "orange"
78+
subject = "orange".dup
7979
expect(subject).to receive(:==).with("apple").and_return(false)
8080
subject.should_not == "apple"
8181
end
@@ -94,13 +94,13 @@ def method_missing(name, *args, &block)
9494

9595
describe "should ===" do
9696
it "delegates message to target" do
97-
subject = "apple"
97+
subject = "apple".dup
9898
expect(subject).to receive(:===).with("apple").and_return(true)
9999
subject.should === "apple"
100100
end
101101

102102
it "fails when target.===(actual) returns false" do
103-
subject = "apple"
103+
subject = "apple".dup
104104
expect(subject).to receive(:===).with("orange").and_return(false)
105105
expect(RSpec::Expectations).to receive(:fail_with).with(%[expected: "orange"\n got: "apple" (using ===)], "orange", "apple")
106106
subject.should === "orange"
@@ -109,13 +109,13 @@ def method_missing(name, *args, &block)
109109

110110
describe "should_not ===" do
111111
it "delegates message to target" do
112-
subject = "orange"
112+
subject = "orange".dup
113113
expect(subject).to receive(:===).with("apple").and_return(false)
114114
subject.should_not === "apple"
115115
end
116116

117117
it "fails when target.===(actual) returns false" do
118-
subject = "apple"
118+
subject = "apple".dup
119119
expect(subject).to receive(:===).with("apple").and_return(true)
120120
expect(RSpec::Expectations).to receive(:fail_with).with(%[expected not: === "apple"\n got: "apple"], "apple", "apple")
121121
subject.should_not === "apple"
@@ -124,13 +124,13 @@ def method_missing(name, *args, &block)
124124

125125
describe "should =~" do
126126
it "delegates message to target" do
127-
subject = "foo"
127+
subject = "foo".dup
128128
expect(subject).to receive(:=~).with(/oo/).and_return(true)
129129
subject.should =~ /oo/
130130
end
131131

132132
it "fails when target.=~(actual) returns false" do
133-
subject = "fu"
133+
subject = "fu".dup
134134
expect(subject).to receive(:=~).with(/oo/).and_return(false)
135135
expect(RSpec::Expectations).to receive(:fail_with).with(%[expected: /oo/\n got: "fu" (using =~)], /oo/, "fu")
136136
subject.should =~ /oo/
@@ -139,13 +139,13 @@ def method_missing(name, *args, &block)
139139

140140
describe "should_not =~" do
141141
it "delegates message to target" do
142-
subject = "fu"
142+
subject = "fu".dup
143143
expect(subject).to receive(:=~).with(/oo/).and_return(false)
144144
subject.should_not =~ /oo/
145145
end
146146

147147
it "fails when target.=~(actual) returns false" do
148-
subject = "foo"
148+
subject = "foo".dup
149149
expect(subject).to receive(:=~).with(/oo/).and_return(true)
150150
expect(RSpec::Expectations).to receive(:fail_with).with(%[expected not: =~ /oo/\n got: "foo"], /oo/, "foo")
151151
subject.should_not =~ /oo/

spec/rspec/matchers/built_in/yield_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,9 +733,10 @@ def each_arg(*args, &block)
733733
end
734734

735735
it 'fails when the successively yielded args match the matchers (at yield time only)' do
736+
values = %w[ food barn ].collect { |value| value.dup }
736737
expect {
737738
expect { |b|
738-
%w[ food barn ].each do |val|
739+
values.each do |val|
739740
_yield_with_args(val, &b)
740741
val.sub!(/.+/, '')
741742
end

spec/rspec/matchers/dsl_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,7 @@ def a_method_in_the_example
12591259
end
12601260

12611261
expected_msg = "RSpec::Matchers::DSL::Matcher"
1262-
expected_msg << " __raise_no_method_error" unless rbx?
1262+
expected_msg = "#{expected_msg} __raise_no_method_error" unless rbx?
12631263

12641264
expect {
12651265
expect(example).to __raise_no_method_error

0 commit comments

Comments
 (0)