Module: Greenbar::TimeSetup

Includes:
ClassMethodSetup, TestSetup
Defined in:
lib/greenbar/TimeSetup.rb

Overview

:include: doc/examples/TimeSetup.rb

Instance Method Summary collapse

Methods included from ClassMethodSetup

#define_class_method, #replace_class_method, #replace_new

Methods included from TestSetup

included, #setup, #setup_mixins, #teardown, #teardown_mixins

Instance Method Details

#make_Time_now_return(time) ⇒ Object

Must be called before Time.new or Time.now if TimeSetup is being used.



54
55
56
# File 'lib/greenbar/TimeSetup.rb', line 54

def make_Time_now_return time
  Time.instance_variable_set '@now', time
end

#setup_mixinObject

:startdoc:



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/greenbar/TimeSetup.rb', line 39

def setup_mixin #:nodoc:
  replace_class_method(Time, :now) {
    raise "Must use make_Time_now_return() when using TimeSetup." unless @now
    @now
  }

  replace_class_method(Time, :new) {
    Time.now
  }

end

#teardown_mixinObject

:nodoc:



58
59
60
# File 'lib/greenbar/TimeSetup.rb', line 58

def teardown_mixin #:nodoc:
  Time.instance_eval {remove_instance_variable '@now'} if Time.instance_variables.include?('@now')
end