Sha256: 642248d64b462dfcab3e9e4c2c81ed22113e6bf98e0b5f4970e82bf71753e66c

Contents?: true

Size: 899 Bytes

Versions: 8

Compression:

Stored size: 899 Bytes

Contents

require 'spec_helper'

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

  let(:node)   { mock('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.8 spec/unit/unparser/emitter/class_methods/visit_spec.rb
unparser-0.0.7 spec/unit/unparser/emitter/class_methods/visit_spec.rb
unparser-0.0.6 spec/unit/unparser/emitter/class_methods/visit_spec.rb
unparser-0.0.5 spec/unit/unparser/emitter/class_methods/visit_spec.rb
unparser-0.0.4 spec/unit/unparser/emitter/class_methods/visit_spec.rb
unparser-0.0.3 spec/unit/unparser/emitter/class_methods/visit_spec.rb
unparser-0.0.2 spec/unit/unparser/emitter/class_methods/visit_spec.rb
unparser-0.0.1 spec/unit/unparser/emitter/class_methods/visit_spec.rb