Sha256: e7677076ca34c60b11e95c0c7bce0a4ba7b8cfaa54d5b44d02124d228d39cb73

Contents?: true

Size: 1.75 KB

Versions: 31

Compression:

Stored size: 1.75 KB

Contents

require 'spec_helper'

describe Krikri::MappingDSL::ParserMethods do
  before do
    # dummy class
    class DummyParserImpl
      include Krikri::MappingDSL::ParserMethods
    end
  end

  after do
    Object.send(:remove_const, 'DummyParserImpl')
  end

  subject { DummyParserImpl.new }

  it 'raises an error without parser' do
    expect { subject.record }
      .to raise_error 'No parser selected; set a parser with #parser(class)'
  end

  context 'with parser' do
    before do
      subject.parser parser
      allow_any_instance_of(parser).to receive(:root).and_return()
    end

    let(:parser) { class_double("Krikri::XmlParser") }

    describe '#record' do
      it 'returns a parsed value instance' do
        expect(subject.record)
          .to be_a Krikri::MappingDSL::ParserMethods::ParsedValue
      end

      it 'initializes parsed value with args and parser' do
        expect(Krikri::MappingDSL::ParserMethods::ParsedValue).to receive(:new)
          .with(parser, :arg_1, :arg_2, :arg_3)
        subject.record(:arg_1, :arg_2, :arg_3)
      end
    end
  end
end

describe Krikri::MappingDSL::ParserMethods::ParsedValue do
  subject { described_class.new(parser) }
  let(:record) { double() }
  let(:parser) { class_double("Krikri::XmlParser") }
  let(:root) { instance_double("Krikri::XmlParser") }
  let(:value) { instance_double("Krikri::XmlParser::Value") }

  describe '#to_proc' do
    # before do
    #   expect(parser).to receive(:new).with(record).and_return(:value)
    # end

    it 'resolves to a parser root' do
      expect(parser).to receive(:new).with(record).and_return(root)
      expect(root).to receive(:root).and_return(value)
      expect(value).to receive(values).and_return(:my_value)
      require 'pry'
      binding.pry
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
krikri-0.13.2 spec/lib/krikri/mapping_dsl/parser_methods_spec.rb~
krikri-0.13.1 spec/lib/krikri/mapping_dsl/parser_methods_spec.rb~
krikri-0.13.0 spec/lib/krikri/mapping_dsl/parser_methods_spec.rb~
krikri-0.12.4 spec/lib/krikri/mapping_dsl/parser_methods_spec.rb~
krikri-0.11.2 spec/lib/krikri/mapping_dsl/parser_methods_spec.rb~
krikri-0.11.1 spec/lib/krikri/mapping_dsl/parser_methods_spec.rb~
krikri-0.11.0 spec/lib/krikri/mapping_dsl/parser_methods_spec.rb~
krikri-0.10.1 spec/lib/krikri/mapping_dsl/parser_methods_spec.rb~
krikri-0.8.9 spec/lib/krikri/mapping_dsl/parser_methods_spec.rb~
krikri-0.8.8 spec/lib/krikri/mapping_dsl/parser_methods_spec.rb~
krikri-0.8.7 spec/lib/krikri/mapping_dsl/parser_methods_spec.rb~
krikri-0.8.6 spec/lib/krikri/mapping_dsl/parser_methods_spec.rb~
krikri-0.8.5 spec/lib/krikri/mapping_dsl/parser_methods_spec.rb~
krikri-0.8.4 spec/lib/krikri/mapping_dsl/parser_methods_spec.rb~
krikri-0.8.2 spec/lib/krikri/mapping_dsl/parser_methods_spec.rb~
krikri-0.8.0 spec/lib/krikri/mapping_dsl/parser_methods_spec.rb~
krikri-0.7.3 spec/lib/krikri/mapping_dsl/parser_methods_spec.rb~
krikri-0.7.2 spec/lib/krikri/mapping_dsl/parser_methods_spec.rb~
krikri-0.7.1 spec/lib/krikri/mapping_dsl/parser_methods_spec.rb~
krikri-0.6.0 spec/lib/krikri/mapping_dsl/parser_methods_spec.rb~