class PhusionPassenger::Utils::GeneratorTest
Public Instance Methods
generate(obj)
click to toggle source
# File lib/phusion_passenger/utils/json.rb, line 241 def generate(obj) JSON.generate(obj) end
test_array()
click to toggle source
# File lib/phusion_passenger/utils/json.rb, line 242 def test_array assert_equal %Q([1, 2, 3]), generate([1, 2, 3]) end
test_bool()
click to toggle source
# File lib/phusion_passenger/utils/json.rb, line 245 def test_bool assert_equal %Q([true, false]), generate([true, false]) end
test_date()
click to toggle source
# File lib/phusion_passenger/utils/json.rb, line 261 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 lib/phusion_passenger/utils/json.rb, line 268 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 lib/phusion_passenger/utils/json.rb, line 279 def test_invalid_json assert_raises(ArgumentError) { generate("abc") } end
test_invalid_object()
click to toggle source
# File lib/phusion_passenger/utils/json.rb, line 282 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 lib/phusion_passenger/utils/json.rb, line 274 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 lib/phusion_passenger/utils/json.rb, line 248 def test_null assert_equal %Q([null]), generate([nil]) end
test_string()
click to toggle source
# File lib/phusion_passenger/utils/json.rb, line 251 def test_string assert_equal %Q(["abc\\n123"]), generate(["abc\n123"]) end
test_string_unicode()
click to toggle source
# File lib/phusion_passenger/utils/json.rb, line 254 def test_string_unicode assert_equal %Q(["ć\\"č\\nž\\tš\\\\đ"]), generate(["ć\"č\nž\tš\\đ"]) end
test_symbol()
click to toggle source
# File lib/phusion_passenger/utils/json.rb, line 265 def test_symbol assert_equal %Q(["abc"]), generate([:abc]) end
test_time()
click to toggle source
# File lib/phusion_passenger/utils/json.rb, line 257 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