Sha256: 2c26bd6c057a06973a1aba6b52e7730a96f502c4bf1a085e9e1c581ad279eb80

Contents?: true

Size: 1.56 KB

Versions: 1

Compression:

Stored size: 1.56 KB

Contents

require "spec_helper"

module Hexx
  describe Coercible do

    # ==========================================================================
    # Prepare environment
    # ==========================================================================

    before { class  TestModel; extend Coercible; end }
    before { module TestModule;  end }
    before { class  TestCoersion < Struct.new(:string); end }

    let(:test_model)    { TestModel   }
    let(:test_module)   { TestModule  }
    let(:test_coersion) { TestCoersion }

    after { Hexx.send :remove_const, :TestCoersion }
    after { Hexx.send :remove_const, :TestModule  }
    after { Hexx.send :remove_const, :TestModel   }

    # ==========================================================================
    # Run tests
    # ==========================================================================

    describe ".coersion" do

      it "is defined" do
        expect(test_model).to respond_to :coersion
      end

      it "is set by default" do
        expect(test_model.coersion).to be_kind_of Module
      end
    end

    describe ".coersion=" do

      it "sets the .coersion" do
        expect { test_model.coersion = test_module }
          .to change { test_model.coersion }.to test_module
      end
    end

    describe ".attr_coerced" do

      before  { test_model.send :attr_coerced, :name, type: test_coersion }
      subject { test_model.new }

      it "coerces an attribute with given type" do
        subject.name = "some name"
        expect(subject.name).to be_kind_of test_coersion
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hexx-6.0.0 spec/hexx/coercible_spec.rb