Sha256: d6a734290b2fdf72f43bcf6709077781a6ebf6c7a1f26aca6cb9c91da1387401

Contents?: true

Size: 1.51 KB

Versions: 35

Compression:

Stored size: 1.51 KB

Contents

require 'spec_helper'

describe Aptible::CLI::Renderer::Json do
  subject { described_class.new }

  let(:root) { Aptible::CLI::Formatter::Root.new }

  it 'renders an object' do
    root.object { |n| n.value('foo', 'bar') }
    expect(JSON.parse(subject.render(root))).to eq('foo' => 'bar')
  end

  it 'renders a list' do
    root.list do |l|
      l.value('foo')
      l.value('bar')
    end
    expect(JSON.parse(subject.render(root))).to eq(%w(foo bar))
  end

  it 'ignores keyed_list' do
    root.keyed_list('foo') do |l|
      l.object do |n|
        n.value('foo', 'bar')
        n.value('qux', 'baz')
      end
    end

    expect(JSON.parse(subject.render(root)))
      .to eq([{ 'foo' => 'bar', 'qux' => 'baz' }])
  end

  it 'ignores grouped_keyed_list' do
    root.grouped_keyed_list('foo', 'qux') do |l|
      l.object do |n|
        n.value('foo', 'bar')
        n.value('qux', 'baz')
      end
    end

    expect(JSON.parse(subject.render(root)))
      .to eq([{ 'foo' => 'bar', 'qux' => 'baz' }])
  end

  it 'ignores keyed_object' do
    root.keyed_object('foo') { |n| n.value('foo', 'bar') }
    expect(JSON.parse(subject.render(root))).to eq('foo' => 'bar')
  end

  it 'nests objects' do
    root.object do |n|
      n.object('foo') { |nn| nn.value('bar', 'qux') }
    end
    expect(JSON.parse(subject.render(root))).to eq('foo' => { 'bar' => 'qux' })
  end

  it 'nests lists' do
    root.list do |n|
      n.list { |nn| nn.value('bar') }
    end
    expect(JSON.parse(subject.render(root))).to eq([%w(bar)])
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
aptible-cli-0.24.2 spec/aptible/cli/renderer/json_spec.rb
aptible-cli-0.24.1 spec/aptible/cli/renderer/json_spec.rb
aptible-cli-0.24.0 spec/aptible/cli/renderer/json_spec.rb
aptible-cli-0.23.0 spec/aptible/cli/renderer/json_spec.rb
aptible-cli-0.22.0 spec/aptible/cli/renderer/json_spec.rb
aptible-cli-0.21.0 spec/aptible/cli/renderer/json_spec.rb
aptible-cli-0.20.0 spec/aptible/cli/renderer/json_spec.rb
aptible-cli-0.19.9 spec/aptible/cli/renderer/json_spec.rb
aptible-cli-0.19.7 spec/aptible/cli/renderer/json_spec.rb
aptible-cli-0.19.6 spec/aptible/cli/renderer/json_spec.rb
aptible-cli-0.19.4 spec/aptible/cli/renderer/json_spec.rb
aptible-cli-0.19.3 spec/aptible/cli/renderer/json_spec.rb
aptible-cli-0.19.2 spec/aptible/cli/renderer/json_spec.rb
aptible-cli-0.19.1 spec/aptible/cli/renderer/json_spec.rb
aptible-cli-0.19.0 spec/aptible/cli/renderer/json_spec.rb
aptible-cli-0.18.3 spec/aptible/cli/renderer/json_spec.rb
aptible-cli-0.18.2 spec/aptible/cli/renderer/json_spec.rb
aptible-cli-0.18.1 spec/aptible/cli/renderer/json_spec.rb
aptible-cli-0.18.0 spec/aptible/cli/renderer/json_spec.rb
aptible-cli-0.17.2 spec/aptible/cli/renderer/json_spec.rb