Sha256: e82c1c328c7098a83df507792142f44243e9478ad825152dfc3fcdccf87a1783

Contents?: true

Size: 1.63 KB

Versions: 15

Compression:

Stored size: 1.63 KB

Contents

require 'test_helper'

module Vedeu

  module Renderers

    describe JSON do

      let(:described) { Vedeu::Renderers::JSON }
      let(:instance)  { described.new(options) }
      let(:options)   { {} }
      let(:output)    {}

      before do
        ::File.stubs(:write)
      end

      describe '#initialize' do
        it { instance.must_be_instance_of(described) }
        it { instance.instance_variable_get('@options').must_equal(options) }
      end

      describe '#render' do
        subject { instance.render(output) }

        it { subject.must_be_instance_of(String) }

        context 'when the output is empty' do
          it { subject.must_equal('') }
        end

        context 'when the output is not empty' do
          let(:colour) {
            Vedeu::Colour.new(foreground: '#ff0000', background: '#ffffff')
          }
          let(:output) {
            [
              [
                Vedeu::Char.new(value: 'a',
                                colour: colour,
                                position: Vedeu::Position[5, 3])
              ]
            ]
          }
          let(:expected) {
            <<-eos
[
  {
    \"border\": \"\",
    \"colour\": {
      \"background\": \"\\u001b[48;2;255;255;255m\",
      \"foreground\": \"\\u001b[38;2;255;0;0m\"
    },
    \"parent\": {
      \"background\": \"\",
      \"foreground\": \"\",
      \"style\": \"\"
    },
    \"position\": {
      \"y\": 5,
      \"x\": 3
    },
    \"style\": \"\",
    \"value\": \"a\"
  }
]
            eos
          }

          it { subject.must_equal(expected.chomp) }
        end
      end

    end # JSON

  end # Renderers

end # Vedeu

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
vedeu-0.5.0 test/lib/vedeu/output/renderers/json_test.rb
vedeu-0.4.65 test/lib/vedeu/output/renderers/json_test.rb
vedeu-0.4.64 test/lib/vedeu/output/renderers/json_test.rb
vedeu-0.4.63 test/lib/vedeu/output/renderers/json_test.rb
vedeu-0.4.62 test/lib/vedeu/output/renderers/json_test.rb
vedeu-0.4.61 test/lib/vedeu/output/renderers/json_test.rb
vedeu-0.4.60 test/lib/vedeu/output/renderers/json_test.rb
vedeu-0.4.59 test/lib/vedeu/output/renderers/json_test.rb
vedeu-0.4.58 test/lib/vedeu/output/renderers/json_test.rb
vedeu-0.4.57 test/lib/vedeu/output/renderers/json_test.rb
vedeu-0.4.56 test/lib/vedeu/output/renderers/json_test.rb
vedeu-0.4.55 test/lib/vedeu/output/renderers/json_test.rb
vedeu-0.4.54 test/lib/vedeu/output/renderers/json_test.rb
vedeu-0.4.53 test/lib/vedeu/output/renderers/json_test.rb
vedeu-0.4.52 test/lib/vedeu/output/renderers/json_test.rb