Sha256: 3e48ee5b001a8cf15927b51eef5fc19f36cef4c1c2fd95f78b26d31ffb246b81

Contents?: true

Size: 1.3 KB

Versions: 4

Compression:

Stored size: 1.3 KB

Contents

class Harness
  include Shoes::Swt::DisposedProtection

  def initialize(real)
    @real = real
  end
end

describe Shoes::Swt::DisposedProtection do
  let(:width) { 234 }
  let(:real_with_disposed_protection) { Harness.new(bare_real).real }

  context "when real object is NOT disposed" do
    let(:bare_real) { double("delegation object", width: width, dispose: nil, disposed?: false) }

    it "delegates method" do
      real_with_disposed_protection.width
      expect(bare_real).to have_received(:width)
    end

    it "returns the same result as the bare real object" do
      expect(real_with_disposed_protection.width).to eq(width)
    end

    it "disposes real object" do
      real_with_disposed_protection.dispose
      expect(bare_real).to have_received(:dispose)
    end
  end

  context "when real object IS disposed" do
    let(:bare_real) { double("delegation object", width: width, dispose: nil, disposed?: true) }

    it "does NOT delegate method" do
      real_with_disposed_protection.width
      expect(bare_real).not_to have_received(:width)
    end

    it "returns nil" do
      expect(real_with_disposed_protection.width).to eq(nil)
    end

    it "does NOT dispose real object" do
      real_with_disposed_protection.dispose
      expect(bare_real).not_to have_received(:dispose)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
shoes-swt-4.0.0.pre7 spec/shoes/swt/disposed_protection_spec.rb
shoes-swt-4.0.0.pre6 spec/shoes/swt/disposed_protection_spec.rb
shoes-swt-4.0.0.pre5 spec/shoes/swt/disposed_protection_spec.rb
shoes-swt-4.0.0.pre4 spec/shoes/swt/disposed_protection_spec.rb