Sha256: 06bf610a89f0b329273bd148c321286a95efecc2c9653d06b3fba2deaaedbc9a

Contents?: true

Size: 1.47 KB

Versions: 6

Compression:

Stored size: 1.47 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 {
          instance.evaluate('exposed_method')
        }.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 {
          instance.evaluate('unexposed_method')
        }.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

6 entries across 6 versions & 1 rubygems

Version Path
omnibus-5.4.0 spec/unit/cleanroom_spec.rb
omnibus-5.3.0 spec/unit/cleanroom_spec.rb
omnibus-5.2.0 spec/unit/cleanroom_spec.rb
omnibus-5.1.0 spec/unit/cleanroom_spec.rb
omnibus-5.0.0 spec/unit/cleanroom_spec.rb
omnibus-4.1.0 spec/unit/cleanroom_spec.rb