Sha256: eb344f829aea5661890e79400ffacfc03ec0b9465f0ef0b6d28cbd3c4ba8fd41

Contents?: true

Size: 1.35 KB

Versions: 3

Compression:

Stored size: 1.35 KB

Contents

# encoding: UTF-8

require 'test_helper'

class TestMember < Test::Unit::TestCase
  def member(key, value=nil, &block)
    JSONBuilder::Member.new(key, nil, value, &block)
  end

  def test_is_a_builder_value
    assert_equal JSONBuilder::Member, member(:hello, true).class
  end

  def test_key_as_symbol
    assert_equal '"hello": true', member(:hello, true).to_s
  end

  def test_key_as_unicoded_symbol
    assert_equal '"hellyé": true', member('hellyé', true).to_s
  end

  def test_key_as_string
    assert_equal '"hello": true', member('hello', true).to_s
  end

  def test_value_as_array
    assert_equal '"hello": [{"ruby":true}]', member('hello', [{ :ruby => true }]).to_s
  end

  def test_value_as_block
    assert_equal '"hello": "hi"', member('hello') { 'hi' }.to_s
  end

  def test_value_as_block_with_hash
    assert_equal '"hello": {"ruby":true}', member('hello') { { :ruby => true } }.to_s
  end

  def test_custom_class
    assert_equal '"hello": "olleh"', member('hello', Dozer.new('hello')).to_s
  end

  def test_double_quoted_value
    assert_equal '"hello": "\"Hello\" he said"', member('hello', '"Hello" he said').to_s
  end

  def test_single_quoted_value
    assert_equal %Q("hello": "hello 'test'!"), member('hello', "hello 'test'!").to_s
  end

  def test_without_key
    assert_raises(JSONBuilder::MissingKeyError) { member(nil, true).to_s }
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
json_builder-3.1.7 test/member_test.rb
json_builder-3.1.6 test/member_test.rb
json_builder-3.1.5 test/member_test.rb