Sha256: 7622db1ce26d1f898a7c19348b43769664ce434eab961d01e825c164a4b969e6

Contents?: true

Size: 1.45 KB

Versions: 10

Compression:

Stored size: 1.45 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/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

10 entries across 10 versions & 1 rubygems

Version Path
omnibus-4.0.0 spec/unit/cleanroom_spec.rb
omnibus-4.0.0.rc.2 spec/unit/cleanroom_spec.rb
omnibus-4.0.0.rc.1 spec/unit/cleanroom_spec.rb
omnibus-3.2.2 spec/unit/cleanroom_spec.rb
omnibus-4.0.0.beta.1 spec/unit/cleanroom_spec.rb
omnibus-3.2.1 spec/unit/cleanroom_spec.rb
omnibus-3.2.0 spec/unit/cleanroom_spec.rb
omnibus-3.2.0.rc.3 spec/unit/cleanroom_spec.rb
omnibus-3.2.0.rc.2 spec/unit/cleanroom_spec.rb
omnibus-3.2.0.rc.1 spec/unit/cleanroom_spec.rb