Skip to content

Commit 9680201

Browse files
committed
Fix compatibility with --frozen-string-literal
1 parent c5987d5 commit 9680201

File tree

6 files changed

+31
-14
lines changed

6 files changed

+31
-14
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,24 @@ jobs:
66
strategy:
77
fail-fast: false
88
matrix:
9-
ruby: [ '3.1', '3.2', '3.3', 'head' ]
9+
ruby: [ '3.1', '3.2', 'head' ]
1010
rails: [ '7.1', 'edge' ]
11+
rubyopt: [""]
1112
include:
12-
- ruby: '2.7'
13-
rails: '6.1'
1413
- ruby: '3.0'
1514
rails: '6.1'
1615
- ruby: '3.1'
1716
rails: '7.0'
17+
- ruby: '3.3'
18+
rails: '7.1'
19+
rubyopt: "--enable-frozen-string-literal"
1820

1921
env:
2022
RAILS_VERSION: ${{ matrix.rails }}
23+
RUBYOPT: ${{ matrix.rubyopt }}
2124

2225
steps:
23-
- uses: actions/checkout@v2
26+
- uses: actions/checkout@v4
2427

2528
- name: Set up Ruby
2629
uses: ruby/setup-ruby@v1
@@ -29,10 +32,10 @@ jobs:
2932
bundler-cache: true
3033

3134
- name: Run unit tests
32-
run: bundle exec rake test:unit
35+
run: bundle exec rake test:unit RUBYOPT="${{ matrix.rubyopt }}"
3336
timeout-minutes: 3
3437

3538
- name: Run acceptance tests
36-
run: bundle exec rake test:acceptance
39+
run: bundle exec rake test:acceptance CI=true RUBYOPT="${{ matrix.rubyopt }}"
3740
timeout-minutes: 10
3841
if: ${{ matrix.rails != 'edge' && matrix.ruby != 'head' }} # Acceptance tests use `gem install rails && rails new`

lib/spring/application_manager.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ def with_child
6060
# Returns the pid of the process running the command, or nil if the application process died.
6161
def run(client)
6262
with_child do
63-
child.send_io client
63+
begin
64+
child.send_io client
65+
rescue Errno::EINVAL
66+
end
6467
child.gets or raise Errno::EPIPE
6568
end
6669

lib/spring/json.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# encoding: UTF-8
1+
# frozen_string_literal: true
22

33
# ### WHY SPRING VENDORS A JSON LIBRARY ###
44
#
@@ -13,7 +13,6 @@
1313
module Spring
1414
module JSON
1515
def self.load(string)
16-
string.force_encoding("utf-8")
1716
OkJson.decode(string)
1817
end
1918

@@ -364,7 +363,7 @@ def unquote(q)
364363
end
365364
end
366365
if rubydoesenc?
367-
a[w] = '' << uchar
366+
a[w] = +'' << uchar
368367
w += 1
369368
else
370369
w += ucharenc(a, w, uchar)

test/support/acceptance_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ class AcceptanceTest < ActiveSupport::TestCase
1212

1313
def rails_version
1414
if ENV['RAILS_VERSION'] == "edge"
15-
">= 7.1.0.alpha"
15+
">= 8.0.0.alpha"
1616
else
17-
"~> #{ENV['RAILS_VERSION'] || "6.1"}.0"
17+
"~> #{ENV['RAILS_VERSION'] || "7.1"}.0"
1818
end
1919
end
2020

test/support/application.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,15 @@ def read_streams
168168
end
169169

170170
def read_stream(stream)
171-
output = ""
171+
output = +""
172172
while IO.select([stream], [], [], 0.5) && !stream.eof?
173173
output << stream.readpartial(10240)
174174
end
175175
output
176176
end
177177

178178
def dump_streams(command, streams)
179-
output = "$ #{command}\n"
179+
output = +"$ #{command}\n"
180180

181181
streams.each do |name, stream|
182182
unless stream.chomp.empty?

test/unit/json_test.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
require_relative "../helper"
2+
require 'spring/json'
3+
4+
class JsonTest < ActiveSupport::TestCase
5+
test 'can decode unicode characters' do
6+
assert_equal({"unicode_example"=>"©"}, Spring::JSON.load('{"unicode_example": "\u00A9"}'))
7+
end
8+
9+
test 'can encode' do
10+
assert_equal('{}', Spring::JSON.dump({}))
11+
end
12+
end

0 commit comments

Comments
 (0)