Sha256: 01c8b5350944e4cae8da2ee0a104c9f92c327a7919d26859f7f900b6ae938b6c

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

require "spec_helper"

module Hexx
  describe RuntimeError do

    let!(:subject) { RuntimeError }
    let!(:object)  { double "object" }
    let!(:errors)  { double "errors" }
    before { allow(object).to receive(:errors) { errors } }

    let!(:error)  { subject.new object }

    it "inherits core RuntimeError" do
      expect(subject.ancestors).to be_include ::RuntimeError
    end

    describe ".new" do

      it "initializes the object attribute" do
        expect(subject).to respond_to(:new).with(1).argument
      end
    end

    describe "#object" do

      it "is public" do
        expect(error).to respond_to :object
      end

      it "initializes the #object attribute" do
        expect(error.object).to eq object
      end
    end

    describe "#errors" do

      it "is public" do
        expect(error).to respond_to :errors
      end

      it "delegated to object" do
        expect(error.errors).to eq errors
      end

      it "set to nil unless object is set" do
        expect(subject.new(nil).errors).to be_nil
      end
    end

    describe "#message" do

      it "customized" do
        begin
          fail error
        rescue => e
          expect(e.message).to eq "Runtime error: #{ errors.inspect }"
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hexx-0.0.1 spec/hexx/exceptions/runtime_error_spec.rb