Sha256: d80fbc38c628522365863613e4aba1e2cc8eec5ce2bfb7f3ccb2bef3200f67a7

Contents?: true

Size: 1.48 KB

Versions: 26

Compression:

Stored size: 1.48 KB

Contents

require "spec_helper"

module Omnibus
  describe Cleanroom do
    let(:klass) do
      Class.new do
        include Cleanroom

        def exposed_method
          @called = true
        end
        expose :exposed_method

        def unexposed_method; end
      end
    end

    let(:instance) { klass.new }

    describe "#evaluate" do
      it "exposes public methods" do
        expect do
          instance.evaluate("exposed_method")
        end.to_not raise_error
      end

      it "calls exposed methods on the instance" do
        instance.evaluate("exposed_method")
        expect(instance.instance_variable_get(:@called)).to be_truthy
      end

      it "does not expose unexposed methods" do
        expect do
          instance.evaluate("unexposed_method")
        end.to raise_error(NameError)
      end
    end

    describe "#evaluate_file" do
      let(:contents) do
        <<-EOH.gsub(/^ {10}/, "")
          exposed_method
        EOH
      end

      let(:filepath) { File.join(tmp_path, "/file/path") }

      before do
        allow(IO).to receive(:read).and_call_original
        allow(IO).to receive(:read).with(filepath).and_return(contents)
      end

      it "evaluates the file and exposes public methods" do
        expect { instance.evaluate_file(filepath) }.to_not raise_error
      end

      it "calls exposed methods on the instance" do
        instance.evaluate_file(filepath)
        expect(instance.instance_variable_get(:@called)).to be_truthy
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
omnibus-9.0.24 spec/unit/cleanroom_spec.rb
omnibus-9.0.23 spec/unit/cleanroom_spec.rb
omnibus-9.0.22 spec/unit/cleanroom_spec.rb
omnibus-9.0.17 spec/unit/cleanroom_spec.rb
omnibus-9.0.12 spec/unit/cleanroom_spec.rb
omnibus-9.0.11 spec/unit/cleanroom_spec.rb
omnibus-9.0.8 spec/unit/cleanroom_spec.rb
omnibus-8.3.2 spec/unit/cleanroom_spec.rb
omnibus-8.2.2 spec/unit/cleanroom_spec.rb
omnibus-8.1.15 spec/unit/cleanroom_spec.rb
omnibus-8.0.15 spec/unit/cleanroom_spec.rb
omnibus-8.0.9 spec/unit/cleanroom_spec.rb
omnibus-7.0.34 spec/unit/cleanroom_spec.rb
omnibus-7.0.13 spec/unit/cleanroom_spec.rb
omnibus-7.0.12 spec/unit/cleanroom_spec.rb
omnibus-6.1.9 spec/unit/cleanroom_spec.rb
omnibus-6.1.7 spec/unit/cleanroom_spec.rb
omnibus-6.1.4 spec/unit/cleanroom_spec.rb
omnibus-6.0.30 spec/unit/cleanroom_spec.rb
omnibus-6.0.25 spec/unit/cleanroom_spec.rb