require 'rspectacular'
require 'human_error'

describe HumanError do
  it 'can create an instance of HumanError' do
    expect(HumanError.new).to be_a HumanError
  end

  it 'can configure each instance' do
    human_error = HumanError.new do |config|
                    config.api_version = 'foo'
                  end

    expect(human_error.configuration.api_version).to eql 'foo'
  end

  it 'can lookup errors' do
    human_error = HumanError.new

    expect(human_error.fetch('RequestError')).to be_a HumanError::Errors::RequestError
  end
end

require 'rspectacular'
require 'human_error'

describe HumanError do
  it 'can create an instance of HumanError' do
    expect(HumanError.new).to be_a HumanError
  end

  it 'can configure each instance' do
    human_error = HumanError.new do |config|
                    config.api_version = 'foo'
                  end

    expect(human_error.configuration.api_version).to eql 'foo'
  end

  it 'can lookup errors' do
    human_error = HumanError.new

    expect(human_error.fetch('RequestError')).to be_a HumanError::Errors::RequestError
  end

  it 'can lookup errors based on the local configuration' do
    human_error = HumanError.new do |config|
      config.api_version = 'foo'
    end

    fetched_error = human_error.fetch('RequestError')

    expect(fetched_error.api_version).to eql 'foo'
  end
end

Allow local configuration to be passed to looked up errors
Feature: Allow local configuration to be passed to looked up errors

This uses `Configuration#to_h` to generate a set of initialization values that
are passed into each error that is looked up via `HumanError#fetch`.

This allows each instance of `HumanError` to create errors with different
information, even if they are of the same type.

Example:

  error = HumanError.new do |config|
            config.api_version = 1
          end

  error.fetch('RequestError').api_version # => 1

but if we created a new `HumanError` instance with an `api_version` of `2` then
calling `fetch('RequestError').api_version` on that instance would yield `2`.

--------------------------------------------------------------------------------
Change-Id:     I0c26b3f59af2588dbd52384bdadd8bce0ee5180d
Signed-off-by: Jeff Felchner <8a84c204e2d4c387d61d20f7892a2bbbf0bc8ae8@thekompanee.com>
