Sha256: c37da33627279999870bcf53793f1b02e831ef7817d391f1f33cb5975040505a

Contents?: true

Size: 1.32 KB

Versions: 3

Compression:

Stored size: 1.32 KB

Contents

require "spec_helper"

# explicitly require the right file since
# Context() is not an autoloaded constant
require "arrthorizer/context"

describe Arrthorizer do
  describe 'Context()' do
    let(:key) { 'key' }
    let(:value) { 'value' }
    let(:arg) { Object.new }

    context "when an object that does not support #to_hash is provided" do
      it "raises an Arrthorizer::ContextConversionError" do
        expect {
          Arrthorizer::Context(arg)
        }.to raise_error(Arrthorizer::Context::ConversionError)
      end
    end

    context "when an object responding to #to_hash is provided" do
      before :each do
        allow(arg).to receive(:to_hash).and_return({ key => value })
      end

      it "returns an Arrthorizer::Context" do
        result = Arrthorizer::Context(arg)

        expect(result).to be_an Arrthorizer::Context
      end

      describe "the returned Arrthorizer::Context" do
        let(:result) { Arrthorizer::Context(arg) }

        specify "it contains the same key-value pairs" do
          expect(result.send(key)).to eql(value)
        end
      end
    end

    context "when an Arrthorizer::Context is provided" do
      let(:param) { Arrthorizer::Context.new }

      specify "that context is returned unmodified" do
        expect(Arrthorizer::Context(param)).to be(param)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
arrthorizer-0.4.2 spec/context_spec.rb
arrthorizer-0.4.1 spec/context_spec.rb
arrthorizer-0.3.2 spec/context_spec.rb