Sha256: 36b2f368350414bc26f324b25e645c3823bea2bf5064729d2ba2647f1dbc0235

Contents?: true

Size: 1.31 KB

Versions: 5

Compression:

Stored size: 1.31 KB

Contents

module Hexx
  describe Models do

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

    around do |example|
      class TestModel; include Models; end
      class TestAttribute; end
      example.run
      Hexx.send :remove_const, :TestAttribute
      Hexx.send :remove_const, :TestModel
    end

    let!(:coerced_attribute) { double "coerced attribute" }
    before do
      allow(TestAttribute).to receive(:new) { |val| coerced_attribute if val }
    end

    # ==========================================================================
    # Prepare variables
    # ==========================================================================

    subject      { TestModel }
    let(:object) { subject.new }

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

    describe ".attr_coerced" do

      before { subject.send :attr_coerced, :name, type: TestAttribute }

      it "coerces an attribute with given type" do
        expect { object.name = "some name" }
          .to change { object.name }
          .from(nil).to coerced_attribute
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
hexx-1.1.1 spec/hexx/models_spec.rb
hexx-1.1.0 spec/hexx/models_spec.rb
hexx-1.0.2 spec/hexx/models_spec.rb
hexx-1.0.1 spec/hexx/models_spec.rb
hexx-1.0.0 spec/hexx/models_spec.rb