Sha256: b5ea81d81ad295298def8109fa0761b6ff83c636f84e3ec2bbb592efe90a6c26

Contents?: true

Size: 901 Bytes

Versions: 8

Compression:

Stored size: 901 Bytes

Contents

require 'spec_helper'

describe Unparser::Emitter, '.visit' do
  subject { object.visit(node, buffer) }
  let(:object) { described_class }

  let(:node)   { double('Node', :type => type, :source_map => nil) }
  let(:buffer) { Unparser::Buffer.new        }

  before do
    stub_const('Unparser::Emitter::REGISTRY', { :dummy => Dummy })
  end

  class Dummy < Unparser::Emitter
    def self.emit(node, buffer, parent)
      buffer.append('foo')
    end
  end

  context 'when handler for type is registred' do
    let(:type) { :dummy }
    it_should_behave_like 'a command method'

    it 'should call emitter' do
      subject
      buffer.content.should eql('foo')
    end
  end

  context 'when handler for type is NOT registred' do
    let(:type) { :unknown }

    it 'should raise error' do
      expect { subject }.to raise_error(ArgumentError, 'No emitter for node: :unknown')
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
unparser-0.0.18 spec/unit/unparser/emitter/class_methods/visit_spec.rb
unparser-0.0.16 spec/unit/unparser/emitter/class_methods/visit_spec.rb
unparser-0.0.15 spec/unit/unparser/emitter/class_methods/visit_spec.rb
unparser-0.0.14 spec/unit/unparser/emitter/class_methods/visit_spec.rb
unparser-0.0.13 spec/unit/unparser/emitter/class_methods/visit_spec.rb
unparser-0.0.12 spec/unit/unparser/emitter/class_methods/visit_spec.rb
unparser-0.0.11 spec/unit/unparser/emitter/class_methods/visit_spec.rb
unparser-0.0.10 spec/unit/unparser/emitter/class_methods/visit_spec.rb