Class: Attest::TestDoubleConfigurator

Inherits:
Object
  • Object
show all
Defined in:
lib/attest/interface/test_double_configurator.rb

Class Method Summary collapse

Class Method Details

.configure(test_double_identifier) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/attest/interface/test_double_configurator.rb', line 6

def configure(test_double_identifier)
  test_double_identifier = test_double_identifier || default_test_double_identifier 
  raise "You have specified an unsupported test double framework" unless test_double_identifiers.include? test_double_identifier
  self.send(:"configure_#{test_double_identifier}")
  #Attest.config.testdouble = test_double_identifier
  test_double_identifier
end

.configure_mochaObject



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/attest/interface/test_double_configurator.rb', line 14

def configure_mocha
  begin
    #how would this work when bundler is in play
    require "mocha_standalone"
  rescue LoadError => e
    puts "Trying to use mocha for test double functionality, but can't find it!"
    puts "Perhaps you forgot to install the mocha gem."
    exit
  end
  Attest::ExecutionContext.class_eval do
    include Mocha::API # need this so that methods like stub() and mock() can be accessed directly from the execution context
  end
end

.configure_noneObject



28
29
# File 'lib/attest/interface/test_double_configurator.rb', line 28

def configure_none
end

.default_test_double_identifierObject



31
32
33
# File 'lib/attest/interface/test_double_configurator.rb', line 31

def default_test_double_identifier
  "mocha"
end

.test_double_identifiersObject



35
36
37
# File 'lib/attest/interface/test_double_configurator.rb', line 35

def test_double_identifiers
  [default_test_double_identifier, "none"]
end