Sha256: fa0e289378a7c163ca70dc15bdd06d59eb54b58696840cac9e2f7e9a24815153

Contents?: true

Size: 1.9 KB

Versions: 3

Compression:

Stored size: 1.9 KB

Contents

# frozen_string_literal: true

RSpec.shared_examples 'has property readers' do
  subject(:instance) { described_class.new(**args) }

  describe "#properties" do
    subject(:properties) { instance.properties }

    let(:args) do
      {
        properties: { flammable: true }
      }
    end

    it { is_expected.to eq({ flammable: true }) }
  end

  describe "properties methods" do
    context "if method is a property" do
      let(:args) do
        {
          properties: { already_packaged: true }
        }
      end

      it "returns its value" do
        expect(instance.already_packaged).to be(true)
      end

      it { is_expected.to respond_to(:already_packaged?) }
    end

    context "if method is a string property" do
      let(:args) do
        {
          properties: { "already_packaged" => true }
        }
      end

      it "returns its value" do
        expect(instance.already_packaged).to be(true)
      end

      it { is_expected.to respond_to(:already_packaged?) }
    end

    context "if method is a boolean property" do
      let(:args) do
        {
          properties: { already_packaged: true }
        }
      end

      it "it is also accessible by its predicate method" do
        expect(instance.already_packaged?).to be(true)
      end

      it { is_expected.to respond_to(:already_packaged?) }

      context "with a falsey value" do
        let(:args) do
          {
            properties: { already_packaged: false }
          }
        end

        it "returns its value" do
          expect(instance.already_packaged).to be(false)
        end
      end
    end

    context "if method is not a property" do
      let(:args) do
        {
          properties: {}
        }
      end

      it "raises method missing" do
        expect { instance.already_packaged? }.to raise_error(NoMethodError)
      end

      it { is_expected.not_to respond_to(:already_packaged?) }
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
physical-0.5.1 lib/physical/spec_support/shared_examples/has_property_readers.rb
physical-0.5.0 lib/physical/spec_support/shared_examples/has_property_readers.rb
physical-0.4.9 lib/physical/spec_support/shared_examples/has_property_readers.rb