Sha256: 0547863c32694774c4ff2ed327a73d65e4b0c5d1bf327c2dab35c40ddfbabd9c

Contents?: true

Size: 1.11 KB

Versions: 3

Compression:

Stored size: 1.11 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_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.2 test/member_test.rb
json_builder-3.1.1 test/member_test.rb
json_builder-3.1.0 test/member_test.rb