Sha256: bd06876577c451a68729ebfe1655b5988d205945072af47899f16c20b0ca3e9e

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

require "spec_helper"

describe Warp::ModelMatchers::AttributeMatcher, type: :model do
  build_model do
    column :foo
  end

  with_contexts do
    context "with model" do
      let(:model_or_instance) { model }
    end

    context "with model instance" do
      let(:model_or_instance) { model.new }
    end

    behaviour do
      let(:matcher) { have_attribute(attr_name) }

      subject { matcher.tap {|m| m.matches?(model_or_instance) } }

      context "and the attribute exists" do
        let(:attr_name) { :foo }

        specify { expect(subject).to match(model_or_instance) }
      
        describe_failure_message_when_negated do
          specify { expect(subject).to eq "expected TestModel to not have attribute :#{attr_name}" }
        end
      end

      context "and the attribute does not exist" do
        let(:attr_name) { :bar }

        specify { expect(subject).to_not match(model_or_instance) }
      
        describe_failure_message do
          specify { expect(subject).to eq "expected TestModel to have attribute :#{attr_name}" }
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
warp-1.3.1 spec/warp/model_helpers/attribute_matcher_spec.rb
warp-1.3.0 spec/warp/model_helpers/attribute_matcher_spec.rb