Sha256: 28883f8709256a32c01045100c9fce79a5bdafc1fbe6473ec62f6da7cc9f354f

Contents?: true

Size: 1.25 KB

Versions: 4

Compression:

Stored size: 1.25 KB

Contents

require 'spec_helper'

describe Parslet::Context do
  def context(*args)
    described_class.new(*args)
  end
  
  it "binds hash keys as variable like things" do
    context(:a => 'value').instance_eval { a }.
      should == 'value'
  end
  it "one contexts variables aren't the next ones" do
    ca = context(:a => 'b')
    cb = context(:b => 'c')

    ca.methods.should_not include(:b)
    cb.methods.should_not include(:a)
  end

  describe 'works as a Ruby object should' do
    let(:obj) { context(a: 1) }

    it 'responds_to? :a' do
      assert obj.respond_to?(:a)
    end
    it 'includes :a in #methods' do
      obj.methods.assert.include?(:a)
    end
    it 'allows inspection' do
      obj.inspect.assert.match(/@a=1/)
    end
    it 'allows conversion to string' do
      obj.to_s.assert.match(/Parslet::Context:0x/)
    end

    context 'when the context is enhanced' do
      before(:each) do
        class << obj
          def foo
            'foo'
          end
        end
      end

      it 'responds_to correctly' do
        assert obj.respond_to?(:foo)
      end
      it 'includes :foo also in methods' do
        obj.methods.assert.include?(:foo)
      end
      it 'allows calling #foo' do
        obj.foo.assert == 'foo'
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
parslet-2.0.0 spec/parslet/transform/context_spec.rb
parslet-1.8.2 spec/parslet/transform/context_spec.rb
parslet-1.8.1 spec/parslet/transform/context_spec.rb
parslet-1.8.0 spec/parslet/transform/context_spec.rb