Skip to content

Commit

Permalink
Fix compatibility with --frozen-string-literal
Browse files Browse the repository at this point in the history
  • Loading branch information
chaadow committed Jun 23, 2024
1 parent c5987d5 commit c1d39e9
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 13 deletions.
15 changes: 9 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,24 @@ 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 +32,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 CI=true 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

0 comments on commit c1d39e9

Please sign in to comment.