Sha256: 42a2977da8181591d571dd439055fe39cf87f903cfc4e9c40f5a4c2f8e5d0f88

Contents?: true

Size: 1013 Bytes

Versions: 18

Compression:

Stored size: 1013 Bytes

Contents

module Berkshelf
  # Because aruba runs in a sub-process, there's no easy way to share mocks and
  # stubs across a run (See RiotGames/berkshelf#208). As a work-around, we pass
  # "special" mocks and stubs into the TEST environment variable. This class
  # parses and then requires the appropriate mocks during the run.
  class Mocks
    require 'rspec/mocks/standalone'

    class << self
      def env_keys
        self.instance_methods(false).map { |key| key.to_s.upcase }
      end
    end

    def initialize(keys)
      keys.each do |key|
        self.send(key.downcase.to_sym, ENV[key.to_s])
      end
    end

    # Trick bundler into thinking gems are missing.
    #
    # @param [String] gems
    #   a CSV list of gems to be missing
    def missing_gems(gems)
      gems.split(',').each do |gem|
        Gem::Specification.stub(:find_by_name).with(gem).and_raise(Gem::LoadError)
      end
    end
  end
end

unless (keys = Berkshelf::Mocks.env_keys & ENV.keys).empty?
  Berkshelf::Mocks.new(keys)
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
berkshelf-2.0.18 lib/berkshelf/test.rb
berkshelf-2.0.17 lib/berkshelf/test.rb
berkshelf-2.0.16 lib/berkshelf/test.rb
berkshelf-2.0.15 lib/berkshelf/test.rb
berkshelf-2.0.14 lib/berkshelf/test.rb
berkshelf-2.0.13 lib/berkshelf/test.rb
berkshelf-2.0.12 lib/berkshelf/test.rb
berkshelf-2.0.11 lib/berkshelf/test.rb
berkshelf-2.0.10 lib/berkshelf/test.rb
berkshelf-2.0.9 lib/berkshelf/test.rb
berkshelf-2.0.8 lib/berkshelf/test.rb
berkshelf-2.0.7 lib/berkshelf/test.rb
berkshelf-2.0.6 lib/berkshelf/test.rb
berkshelf-2.0.5 lib/berkshelf/test.rb
berkshelf-2.0.4 lib/berkshelf/test.rb
berkshelf-2.0.3 lib/berkshelf/test.rb
berkshelf-2.0.1 lib/berkshelf/test.rb
berkshelf-2.0.0 lib/berkshelf/test.rb