Sha256: 130ea94971bba85f7a1c35a87666bff822e7f7661cb5a84ca95ed695b479b9cb

Contents?: true

Size: 1.94 KB

Versions: 1

Compression:

Stored size: 1.94 KB

Contents

# frozen_string_literal: true

require_relative '../spec_helper' # Use the RSpec framework
require 'ostruct'

# Load the class under test
require_relative '../../lib/mini_kraken/atomic/k_symbol'

module MiniKraken
  module Atomic
    describe KSymbol do
      let(:a_value) { :pea }
      subject { KSymbol.new(a_value) }

      context 'Initialization:' do
        it 'should be created with a Ruby symbol' do
          expect { KSymbol.new(a_value) }.not_to raise_error
        end

        it 'should know its value' do
          expect(subject.value).to eq(a_value)
        end

        it 'should know that it is a ground term' do
          env = double('mock-env')
          expect(subject.ground?(env)).to be_truthy
        end
      end # context

      context 'Provided services:' do
        it 'should know whether it is equal to another instance' do
          # Same type, same value
          other = KSymbol.new(a_value)
          expect(subject).to be_eql(other)

          # Same type, other value
          another = KSymbol.new(:pod)
          expect(subject).not_to be_eql(another)

          # Different duck type, same value
          yet_another = OpenStruct.new(value: :pea)
          expect(subject).not_to be_eql(yet_another)
        end

        it 'should know whether it has same value than other object' do
          # Same type, same value
          other = KSymbol.new(a_value)
          expect(subject == other).to be_truthy

          # Same type, other value
          another = KSymbol.new(:pod)
          expect(subject == another).to be_falsy

          # Default Ruby representation, same value
          expect(subject == :pea).to be_truthy

          # Default Ruby representation, different value
          expect(subject == :pod).to be_falsy
        end

        it 'should provide a string representation of itself' do
          expect(subject.to_s).to eq(':pea')
        end
      end # context
    end # describe
  end # module
end # module

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mini_kraken-0.2.04 spec/atomic/k_symbol_spec.rb