File: generate_spec.rb

package info (click to toggle)
ruby-jsonify 0.4.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 240 kB
  • sloc: ruby: 748; makefile: 2
file content (35 lines) | stat: -rw-r--r-- 1,022 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
require 'spec_helper'

describe Jsonify::Generate do
  let(:links) do
    { :links => 
       [
         {:rel => 'foo', :href => 'goo'},
         {:rel => 'bar', :href => 'baz'}
       ]
    }
  end
  it 'should build json' do
    json = Jsonify::Generate
    result = json.value links
    expected = '{"links":[{"rel":"foo","href":"goo"},{"rel":"bar","href":"baz"}]}'
    MultiJson.load(result.encode_as_json).should == MultiJson.load(expected)
  end

  describe 'complex example' do
    let(:jsonifier) { Jsonify::Generate }
    
    it 'should work' do
      json = jsonifier.object_value( 
        {"links" =>
          jsonifier.array_value([
            jsonifier.object_value( {"rel" => "foo", "href" => "goo"} ),
            jsonifier.object_value( {"rel" => "bar", "href" => "baz"} )
          ])
        }
      )
      expected = "{\"links\":[{\"rel\":\"foo\",\"href\":\"goo\"},{\"rel\":\"bar\",\"href\":\"baz\"}]}"
      MultiJson.load(json.encode_as_json).should == MultiJson.load(expected)
    end
  end
end