### Home Classes Methods

### In Files

- lib/phusion_passenger/utils/json.rb

### Parent

Test::Unit::TestCase

### Methods

- #generate
- #test_array
- #test_bool
- #test_date
- #test_hash
- #test_invalid_json
- #test_invalid_object
- #test_nested_structure
- #test_null
- #test_string
- #test_string_unicode
- #test_symbol
- #test_time

### Class/Module Index

Quicksearch

- PhusionPassenger
- PhusionPassenger::AbstractInstaller
- PhusionPassenger::AbstractInstaller::Abort
- PhusionPassenger::AbstractInstaller::CommandError
- PhusionPassenger::AdminTools
- PhusionPassenger::AdminTools::MemoryStats
- PhusionPassenger::AdminTools::MemoryStats::Process
- PhusionPassenger::AdminTools::ServerInstance
- PhusionPassenger::AdminTools::ServerInstance::CorruptedDirectoryError
- PhusionPassenger::AdminTools::ServerInstance::GenerationsAbsentError
- PhusionPassenger::AdminTools::ServerInstance::Group
- PhusionPassenger::AdminTools::ServerInstance::Process
- PhusionPassenger::AdminTools::ServerInstance::RoleDeniedError
- PhusionPassenger::AdminTools::ServerInstance::StaleDirectoryError
- PhusionPassenger::AdminTools::ServerInstance::Stats
- PhusionPassenger::AdminTools::ServerInstance::UnsupportedGenerationStructureVersionError
- PhusionPassenger::AnalyticsLogger
- PhusionPassenger::AnalyticsLogger::Connection
- PhusionPassenger::AnalyticsLogger::Lock
- PhusionPassenger::AnalyticsLogger::Log
- PhusionPassenger::ClassicRails
- PhusionPassenger::ClassicRails::CGIFixed
- PhusionPassenger::ClassicRails::ThreadHandlerExtension
- PhusionPassenger::ConsoleTextTemplate
- PhusionPassenger::DebugLogging
- PhusionPassenger::LoaderSharedHelpers
- PhusionPassenger::MessageChannel
- PhusionPassenger::MessageChannel::InvalidHashError
- PhusionPassenger::MessageClient
- PhusionPassenger::NativeSupportLoader
- PhusionPassenger::Packaging
- PhusionPassenger::PlatformInfo
- PhusionPassenger::PlatformInfo::ApacheDetector
- PhusionPassenger::PlatformInfo::ApacheDetector::Result
- PhusionPassenger::PlatformInfo::Depcheck
- PhusionPassenger::PlatformInfo::Depcheck::ConsoleRunner
- PhusionPassenger::PlatformInfo::Depcheck::Dependency
- PhusionPassenger::PlatformInfo::RuntimeError
- PhusionPassenger::Plugin
- PhusionPassenger::PreloaderSharedHelpers
- PhusionPassenger::Rack
- PhusionPassenger::Rack::OutOfBandGc
- PhusionPassenger::Rack::ThreadHandlerExtension
- PhusionPassenger::Rails3Extensions
- PhusionPassenger::Rails3Extensions::AnalyticsLogging
- PhusionPassenger::Rails3Extensions::AnalyticsLogging::ACExtension
- PhusionPassenger::Rails3Extensions::AnalyticsLogging::ASBenchmarkableExtension
- PhusionPassenger::Rails3Extensions::AnalyticsLogging::ExceptionLogger
- PhusionPassenger::RequestHandler
- PhusionPassenger::RequestHandler::ThreadHandler
- PhusionPassenger::RequestHandler::ThreadHandler::Interrupted
- PhusionPassenger::SharedConstants
- PhusionPassenger::Standalone
- PhusionPassenger::Standalone::AppFinder
- PhusionPassenger::Standalone::Command
- PhusionPassenger::Standalone::ConfigFile
- PhusionPassenger::Standalone::ConfigFile::DisallowedContextError
- PhusionPassenger::Standalone::HelpCommand
- PhusionPassenger::Standalone::Main
- PhusionPassenger::Standalone::PackageRuntimeCommand
- PhusionPassenger::Standalone::RuntimeInstaller
- PhusionPassenger::Standalone::RuntimeLocator
- PhusionPassenger::Standalone::StartCommand
- PhusionPassenger::Standalone::StatusCommand
- PhusionPassenger::Standalone::StopCommand
- PhusionPassenger::Standalone::Utils
- PhusionPassenger::Standalone::VersionCommand
- PhusionPassenger::Utils
- PhusionPassenger::Utils::AnsiColors
- PhusionPassenger::Utils::FileSystemWatcher
- PhusionPassenger::Utils::FileSystemWatcher::DirInfo
- PhusionPassenger::Utils::FileSystemWatcher::FileInfo
- PhusionPassenger::Utils::GeneratorTest
- PhusionPassenger::Utils::HostsFileParser
- PhusionPassenger::Utils::JSON
- PhusionPassenger::Utils::JSON::Generator
- PhusionPassenger::Utils::ParserTest
- PhusionPassenger::Utils::TeeInput
- PhusionPassenger::Utils::TmpIO
- PhusionPassenger::Utils::UnseekableSocket
- CommonLibraryBuilder
- Exception
- GC
- IO
- Object
- Signal

No matching classes.

# 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 %([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 %([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 %(["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 [%("123": "abc"), %("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?(%("hash": {"1": 2}))
      assert json.include?(%("array": [1, 2]))
    end

test_null() click to toggle source

    # File lib/phusion_passenger/utils/json.rb, line 248
    def test_null
      assert_equal %([null]), generate([nil])
    end

test_string() click to toggle source

    # File lib/phusion_passenger/utils/json.rb, line 251
    def test_string
      assert_equal %(["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 %(["ć\\"č\\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 %(["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 %(["2012-04-19 01:02:03 UTC"]), generate([time])
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.