Sha256: fff4d9c93d18f2863b62630d83b3796b16668b4f1d99d1293812e924d8198da8

Contents?: true

Size: 1.6 KB

Versions: 1

Compression:

Stored size: 1.6 KB

Contents

require "spec_helper"

require "terrestrial/inspection_string"

RSpec.describe Terrestrial::InspectionString do
  class SomeClass
  end

  describe "#inspect" do
    let(:test_class) { Class.new }
    let(:object) { test_class.new }

    context "when #inspectable_properties is not implemented or returns `[]`" do
      it "returns the regular inspection string" do
        original_inspection_string = object.inspect

        object.extend(Terrestrial::InspectionString)

        expect(object.inspect).to eq(original_inspection_string)
      end

      context "when class is not anonymous" do
        class TestClass; end
        let(:object) { TestClass.new }

        it "returns the regular inspection string" do
          original_inspection_string = object.inspect

          object.extend(Terrestrial::InspectionString)

          expect(object.inspect).to eq(original_inspection_string)
        end
      end
    end

    context "when #inspectable_properties returns an array of present instance variables" do
      class TestClass2
        include Terrestrial::InspectionString

        def initialize
          @one = "one value"
          @two = "two value"
          @three = "three value"
        end

        def inspectable_properties
          [:one, :two]
        end
      end
      let(:object) { TestClass2.new }

      it "contains the specified instance variable names and values" do
        expect(object.inspect).to include('one="one value" two="two value"')
      end

      it "does not contain other instance variable values" do
        expect(object.inspect).not_to include("three")
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
terrestrial-0.5.0 spec/terrestrial/inspection_string_spec.rb