Sha256: 9422db08269dd3ff2d6e36d15b92f5c6d7301e95594d4c76ced24f84ae6dbe1b

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

require 'spec_helper'

module Esendex
  class DummyHashSerialisation
    include HashSerialisation

    attr_accessor :name, :time, :notes

  end

  describe HashSerialisation do
    let(:name) { random_string }
    let(:time) { random_time }
    let(:notes) { random_string }

    before(:each) do
      @attrs = { name: name, time: time, notes: notes } 
    end

    describe "#initialize" do

      subject { DummyHashSerialisation.new @attrs }

      it "sets the name" do
        expect(subject.name).to eq(name)
      end
      it "sets the time" do
        expect(subject.time).to eq(time)
      end
      it "sets the notes" do
        expect(subject.notes).to eq(notes)
      end

      context "when invalid attribute passed" do
        before(:each) do
          @attrs[random_string] = random_string
        end
        it "should raise and argument error" do
          expect { subject }.to raise_error(ArgumentError)
        end
      end
    end

    describe "#to_hash" do
      subject { DummyHashSerialisation.new(@attrs).to_hash }

      it "should match the init hash" do
        expect(subject).to eq(@attrs)
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
esendex-0.6.0 spec/hash_serialisation_spec.rb