Sha256: 9267cfe2a570179eb219d38a49cdaba03430442e7b5fdcf27ab0e679ff197dfb

Contents?: true

Size: 1.05 KB

Versions: 2

Compression:

Stored size: 1.05 KB

Contents

require 'spec_helper'

describe Minitel::StrictArgs, '.enforce' do
  describe 'arguments' do
    before do
      @hash = {one: 1, two: 2, uuid: SecureRandom.uuid}
      @keys = @hash.keys
    end

    it 'works when all listed args are present' do
      expect { Minitel::StrictArgs.enforce(@hash, @keys, :uuid)  }.to_not raise_error
    end

    it "fails when a key is missing from the arg hash" do
      @hash.delete(:one)
      expect { Minitel::StrictArgs.enforce(@hash, @keys, :uuid) }.to raise_error(ArgumentError)
    end

    it "fails when a key is nil" do
      @hash[:one] = nil
      expect { Minitel::StrictArgs.enforce(@hash, @keys, :uuid) }.to raise_error(ArgumentError)
    end

    it 'fails if the uuid column uuid is not a uuid' do
      @hash[:uuid] = "not a uuid"
      expect { Minitel::StrictArgs.enforce(@hash, @keys, :uuid) }.to raise_error(ArgumentError)
    end

    it 'fails if there is an extra key' do
      @hash.merge!( {foo: 3} )
      expect { Minitel::StrictArgs.enforce(@hash, @keys, :uuid) }.to raise_error(ArgumentError)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
minitel-0.3.0 spec/minitel/strict_args_spec.rb
minitel-0.2.0 spec/minitel/strict_args_spec.rb