Sha256: 7285e62b09ae88742ebecbca068aaccb76fc8b4f7af002a8f2b873f5680fdf4a

Contents?: true

Size: 1.75 KB

Versions: 1

Compression:

Stored size: 1.75 KB

Contents

# frozen_string_literal: true

require 'tataru'

describe Tataru::InstructionHash do
  it 'can be made' do
    im = Tataru::InstructionHash.new(init: {})

    expect(im.instruction_list).to be_empty
  end

  it 'makes init properly' do
    im = Tataru::InstructionHash.new(init: {
      remote_ids: {
        'thing' => 'abc'
      }
    }, instructions: [:init])

    expect(im.instruction_list[0]).to be_a(Tataru::Instructions::InitInstruction)
    expect(im.instruction_list[0].remote_ids).to eq('thing' => 'abc')
  end

  it 'adds instructions' do
    im = Tataru::InstructionHash.new(instructions:[
      :create
    ])

    expect(Tataru::Instructions::CreateInstruction).to receive(:new).and_call_original

    expect(im.instruction_list[0]).to be_a(Tataru::Instructions::CreateInstruction)
  end

  it 'add more instructions' do
    im = Tataru::InstructionHash.new(instructions:[
      :create,
      :delete
    ])

    expect(Tataru::Instructions::CreateInstruction).to receive(:new).and_call_original
    expect(Tataru::Instructions::DeleteInstruction).to receive(:new).and_call_original

    expect(im.instruction_list[0]).to be_a(Tataru::Instructions::CreateInstruction)
    expect(im.instruction_list[1]).to be_a(Tataru::Instructions::DeleteInstruction)
  end

  it 'adds immediate mode instructions' do
    im = Tataru::InstructionHash.new(instructions:[
      { key: 'name' }
    ])

    expect(Tataru::Instructions::KeyInstruction).to receive(:new).with('name').and_call_original

    expect(im.instruction_list[0]).to be_a(Tataru::Instructions::KeyInstruction)
  end

  it 'errors on unknown instruction' do
    im = Tataru::InstructionHash.new(instructions:[
      :unknown
    ])

    expect { im.instruction_list[0] }.to raise_error "Unknown instruction 'unknown'"
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tataru-0.2.0 spec/instruction_hash_spec.rb