class PhusionPassenger::Utils::GeneratorTest
Public Instance Methods
generate(obj)
click to toggle source
# File src/ruby_supportlib/phusion_passenger/utils/json.rb, line 307 def generate(obj) JSON.generate(obj) end
test_array()
click to toggle source
# File src/ruby_supportlib/phusion_passenger/utils/json.rb, line 308 def test_array assert_equal %Q([1, 2, 3]), generate([1, 2, 3]) end
test_bool()
click to toggle source
# File src/ruby_supportlib/phusion_passenger/utils/json.rb, line 311 def test_bool assert_equal %Q([true, false]), generate([true, false]) end
test_date()
click to toggle source
# File src/ruby_supportlib/phusion_passenger/utils/json.rb, line 327 def test_date time = Date.new(2012, 04, 19) assert_equal %Q(["2012-04-19"]), generate([time]) end
test_hash()
click to toggle source
# File src/ruby_supportlib/phusion_passenger/utils/json.rb, line 334 def test_hash json = generate(:abc => 123, 123 => 'abc') assert_match /^\{/, json assert_match /\}$/, json assert_equal [%Q("123": "abc"), %Q("abc": 123)], json[1...-1].split(', ').sort end
test_invalid_json()
click to toggle source
# File src/ruby_supportlib/phusion_passenger/utils/json.rb, line 345 def test_invalid_json assert_raises(ArgumentError) { generate("abc") } end
test_invalid_object()
click to toggle source
# File src/ruby_supportlib/phusion_passenger/utils/json.rb, line 348 def test_invalid_object err = assert_raises(ArgumentError) { generate("a" => Object.new) } assert_equal "can't serialize Object", err.message end
test_nested_structure()
click to toggle source
# File src/ruby_supportlib/phusion_passenger/utils/json.rb, line 340 def test_nested_structure json = generate(:hash => {1=>2}, :array => [1,2]) assert json.include?(%Q("hash": {"1": 2})) assert json.include?(%Q("array": [1, 2])) end
test_null()
click to toggle source
# File src/ruby_supportlib/phusion_passenger/utils/json.rb, line 314 def test_null assert_equal %Q([null]), generate([nil]) end
test_string()
click to toggle source
# File src/ruby_supportlib/phusion_passenger/utils/json.rb, line 317 def test_string assert_equal %Q(["abc\\n123"]), generate(["abc\n123"]) end
test_string_unicode()
click to toggle source
# File src/ruby_supportlib/phusion_passenger/utils/json.rb, line 320 def test_string_unicode assert_equal %Q(["ć\\"č\\nž\\tš\\\\đ"]), generate(["ć\"č\nž\tš\\đ"]) end
test_symbol()
click to toggle source
# File src/ruby_supportlib/phusion_passenger/utils/json.rb, line 331 def test_symbol assert_equal %Q(["abc"]), generate([:abc]) end
test_time()
click to toggle source
# File src/ruby_supportlib/phusion_passenger/utils/json.rb, line 323 def test_time time = Time.utc(2012, 04, 19, 1, 2, 3) assert_equal %Q(["2012-04-19 01:02:03 UTC"]), generate([time]) end