Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix frozen string literal for ruby 3.4 #719

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
19 changes: 9 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,20 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: [ '3.1', '3.2', '3.3', 'head' ]
ruby: [ '3.1', '3.2', 'head' ]
rails: [ '7.1', 'edge' ]
rubyopt: [""]
include:
- ruby: '2.7'
rails: '6.1'
- ruby: '3.0'
rails: '6.1'
- ruby: '3.1'
rails: '7.0'
- ruby: '3.3'
rails: '7.1'
rubyopt: "--enable-frozen-string-literal"

env:
RAILS_VERSION: ${{ matrix.rails }}
RUBYOPT: ${{ matrix.rubyopt }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up Ruby
uses: ruby/setup-ruby@v1
Expand All @@ -29,10 +28,10 @@ jobs:
bundler-cache: true

- name: Run unit tests
run: bundle exec rake test:unit
run: bundle exec rake test:unit RUBYOPT="${{ matrix.rubyopt }}"
timeout-minutes: 3

- name: Run acceptance tests
run: bundle exec rake test:acceptance
run: bundle exec rake test:acceptance RUBYOPT="${{ matrix.rubyopt }}"
timeout-minutes: 10
if: ${{ matrix.rails != 'edge' && matrix.ruby != 'head' }} # Acceptance tests use `gem install rails && rails new`
5 changes: 2 additions & 3 deletions lib/spring/json.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# encoding: UTF-8
# frozen_string_literal: true

# ### WHY SPRING VENDORS A JSON LIBRARY ###
#
Expand All @@ -13,7 +13,6 @@
module Spring
module JSON
def self.load(string)
string.force_encoding("utf-8")
OkJson.decode(string)
end

Expand Down Expand Up @@ -364,7 +363,7 @@ def unquote(q)
end
end
if rubydoesenc?
a[w] = '' << uchar
a[w] = +'' << uchar
w += 1
else
w += ucharenc(a, w, uchar)
Expand Down
4 changes: 2 additions & 2 deletions test/support/acceptance_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ class AcceptanceTest < ActiveSupport::TestCase

def rails_version
if ENV['RAILS_VERSION'] == "edge"
">= 7.1.0.alpha"
">= 8.0.0.alpha"
else
"~> #{ENV['RAILS_VERSION'] || "6.1"}.0"
"~> #{ENV['RAILS_VERSION'] || "7.1"}.0"
end
end

Expand Down
4 changes: 2 additions & 2 deletions test/support/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,15 @@ def read_streams
end

def read_stream(stream)
output = ""
output = +""
while IO.select([stream], [], [], 0.5) && !stream.eof?
output << stream.readpartial(10240)
end
output
end

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

streams.each do |name, stream|
unless stream.chomp.empty?
Expand Down
12 changes: 12 additions & 0 deletions test/unit/json_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require_relative "../helper"
require 'spring/json'

class JsonTest < ActiveSupport::TestCase
test 'can decode unicode characters' do
assert_equal({"unicode_example"=>"©"}, Spring::JSON.load('{"unicode_example": "\u00A9"}'))
end

test 'can encode' do
assert_equal('{}', Spring::JSON.dump({}))
end
end
Loading