Class: Berkshelf::Mocks

Inherits:
Object
  • Object
show all
Defined in:
lib/berkshelf/test.rb

Overview

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 Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(keys) ⇒ Mocks

Returns a new instance of Mocks.



15
16
17
18
19
# File 'lib/berkshelf/test.rb', line 15

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

Class Method Details

.env_keysObject



10
11
12
# File 'lib/berkshelf/test.rb', line 10

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

Instance Method Details

#missing_gems(gems) ⇒ Object

Trick bundler into thinking gems are missing.

Parameters:

  • gems (String)

    a CSV list of gems to be missing



25
26
27
28
29
# File 'lib/berkshelf/test.rb', line 25

def missing_gems(gems)
  gems.split(',').each do |gem|
    Gem::Specification.stub(:find_by_name).with(gem).and_raise(Gem::LoadError)
  end
end