Sha256: ec1d2367804aa725044ef97bd8fd98884a3c85ad29653547d07e7565eae8f8a9

Contents?: true

Size: 1.95 KB

Versions: 1

Compression:

Stored size: 1.95 KB

Contents

require 'rubygems'
require 'spec'
dir = File.dirname(__FILE__)
require File.expand_path("#{dir}/spec_helper")
require File.expand_path("#{dir}/../lib/fjson")

context "A JSON state" do
  specify "method from_state should return the passed in object when a state is passed in" do
    state = JSON::State.new
    JSON::State.from_state(state).should_eql state
  end

  specify "method from_state should return a new state with hash values when a hash is passed in" do
    shim_state_class = Object.new
    shim_state_class.extend JSON::State::ClassMethods
    passed_params = nil
    shim_state_class.define_instance_method(:new) {|params| passed_params = params}

    args = {}
    shim_state_class.from_state(args)
    passed_params.should_eql args
  end

  specify "method from_state should return a new state with default parameters when an object that is not " +
          "a state or a hash is passed in" do
    state = JSON::State.from_state(Object.new)
    state.should_be_instance_of JSON::State
  end

  specify "should initialize its attributes to their defaults" do
    state = JSON::State.new
    state.indent.should_eql ""
    state.space.should_eql ""
    state.object_nl.should_eql ""
    state.array_nl.should_eql ""
  end

  specify "should initialize its attributes with passed in values" do
    params = {
      :indent => Object.new,
      :space => Object.new,
      :object_nl => Object.new,
      :array_nl => Object.new
    }
    state = JSON::State.new(params)
    state.indent.should_eql params[:indent]
    state.space.should_eql params[:space]
    state.object_nl.should_eql params[:object_nl]
    state.array_nl.should_eql params[:array_nl]
  end

  specify "should remember objects" do
    state = JSON::State.new
    obj = Object.new
    state.remember(obj)
    state.should_be_seen(obj)
  end

  specify "should forget objects" do
    state = JSON::State.new
    obj = Object.new
    state.remember(obj)
    state.forget(obj)
    state.should_not_be_seen(obj)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fjson-0.1.1 spec/state_spec.rb