Sha256: bff5de99f509c9a0da43d062717a5c6a235a0eec323134558ead4f8dea4d5ac5

Contents?: true

Size: 1.29 KB

Versions: 1

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

require 'tataru'

describe Tataru::Instructions::CheckDeleteInstruction do
  it 'reverses program counter if not completed' do
    mem = Tataru::Memory.new
    instr = Tataru::Instructions::CheckDeleteInstruction.new

    expect(mem.program_counter).to eq 0

    mem.hash[:temp] = {
      resource_name: 'thing',
      resource_desc: 'Tataru::BaseResourceDesc'
    }
    mem.hash[:remote_ids] = { 'thing' => 'hello' }
    instr.memory = mem

    allow_any_instance_of(Tataru::BaseResource).to receive(:delete_complete?) { false }
    instr.run

    expect(mem.program_counter).to eq -1
  end

  it 'sets deleted' do
    mem = Tataru::Memory.new
    instr = Tataru::Instructions::CheckDeleteInstruction.new

    expect(mem.program_counter).to eq 0

    mem.hash[:temp] = {
      resource_name: 'thing',
      resource_desc: 'Tataru::BaseResourceDesc'
    }
    mem.hash[:remote_ids] = { 'thing' => 'hello' }
    mem.hash[:deleted] = []
    instr.memory = mem

    allow_any_instance_of(Tataru::BaseResource).to receive(:delete_complete?) { true }
    allow_any_instance_of(Tataru::BaseResourceDesc).to receive(:needs_remote_id?) { true }
    instr.run

    expect(mem.hash[:deleted]).to eq ['thing']
    expect(mem.hash[:remote_ids]).to eq({})
    expect(mem.program_counter).to eq 0
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tataru-0.2.0 spec/instructions/check_delete_instruction_spec.rb