Sha256: 02f9af8ef2d256072248cebbf825a411aa37a4da683891f462e7db9dfef1a2f1

Contents?: true

Size: 1.43 KB

Versions: 3

Compression:

Stored size: 1.43 KB

Contents

require 'spec_helper'
require 'derketo/event_trace'

describe Derketo::EventTrace do
  let(:trace) { Derketo::EventTrace.new }
  let(:node) { Node.new }

  describe '#push' do
    it 'adds the first event to the trace' do
      trace.push(node)
      expect(trace.first).to eq(node)
    end

    it 'adds two events to the trace' do
      trace.push(node)
      new_node = Node.new
      trace.push(new_node)
      expect(trace.first).to_not eq(new_node)
    end

    it 'sets the event\'s previous link' do
      trace.push(node)
      new_node = Node.new
      trace.push(new_node)
      expect(new_node.previous).to eq(node)
    end
  end

  describe '#last' do
    it 'returns the first event if there is only one' do
      trace.push(node)
      expect(trace.last).to eq(node)
    end

    it 'returns the last event if there is more than one' do
      trace.push(node)
      new_node = Node.new
      trace.push(new_node)
      expect(trace.last).to eq(new_node)
    end
  end

  describe '#all' do
    it 'returns an empty array if there are no events' do
      expect(trace.all).to eq([])
    end

    it 'returns an array with one element if there is one event' do
      trace.push(node)
      expect(trace.all).to eq([node])
    end

    it 'returns an array with multiple elements when there are multiple events' do
      trace.push(node)
      new_node = Node.new
      trace.push(new_node)
      expect(trace.all.count).to eq(2)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
derketo-0.1.2 spec/derketo/event_trace_spec.rb
derketo-0.1.1 spec/derketo/event_trace_spec.rb
derketo-0.1.0 spec/derketo/event_trace_spec.rb