Skip to content

Commit

Permalink
Assert that strings generated by Puma::JSON roundtrip when using ::JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
cjlarose committed Nov 6, 2020
1 parent be2ad5a commit b905c34
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions test/test_json.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require_relative "helper"
require "json"
require "puma/json"

class TestJSON < Minitest::Test
Expand All @@ -11,7 +12,7 @@ def test_json_generates_string_for_hash_with_string_keys

def test_json_generates_string_for_hash_with_symbol_keys
value = { key: 'value' }
assert_puma_json_generates_string '{"key":"value"}', value
assert_puma_json_generates_string '{"key":"value"}', value, expected_roundtrip: { "key" => "value" }
end

def test_generate_raises_error_for_unexpected_key_type
Expand Down Expand Up @@ -92,7 +93,14 @@ def test_generate_raises_error_for_unexpected_value_type

private

def assert_puma_json_generates_string(expected_output, value_to_serialize)
assert_equal expected_output, Puma::JSON.generate(value_to_serialize)
def assert_puma_json_generates_string(expected_output, value_to_serialize, expected_roundtrip: value_to_serialize)
actual_output = Puma::JSON.generate(value_to_serialize)
assert_equal expected_output, actual_output

if value_to_serialize.nil?
assert_nil ::JSON.parse(actual_output)
else
assert_equal expected_roundtrip, ::JSON.parse(actual_output)
end
end
end

0 comments on commit b905c34

Please sign in to comment.