Class: ConstMocker
- Defined in:
- lib/six-updater-web/vendor/plugins/active_scaffold/test/const_mocker.rb
Class Method Summary collapse
Instance Method Summary collapse
- #declare ⇒ Object
-
#initialize(*const_names) ⇒ ConstMocker
constructor
A new instance of ConstMocker.
- #remove ⇒ Object
- #restore ⇒ Object
Constructor Details
#initialize(*const_names) ⇒ ConstMocker
Returns a new instance of ConstMocker.
2 3 4 5 6 7 8 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/test/const_mocker.rb', line 2 def initialize(*const_names) @const_names = const_names @const_states = {} @const_names.each{|const_name| @const_states[const_name] = Object.const_defined?(const_name) ? Object.const_get(const_name) : nil } end |
Class Method Details
.mock(*const_names) {|cm| ... } ⇒ Object
30 31 32 33 34 35 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/test/const_mocker.rb', line 30 def self.mock(*const_names, &block) cm = new(*const_names) yield(cm) cm.restore true end |
Instance Method Details
#declare ⇒ Object
16 17 18 19 20 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/test/const_mocker.rb', line 16 def declare @const_names.each{|const_name| Object.class_eval "class #{const_name}; end;" unless Object.const_defined?(const_name) } end |
#remove ⇒ Object
10 11 12 13 14 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/test/const_mocker.rb', line 10 def remove @const_names.each{|const_name| Object.send :remove_const, const_name if Object.const_defined?(const_name) } end |
#restore ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/test/const_mocker.rb', line 22 def restore remove @const_states.each_pair{|const_name, const| Object.const_set const_name, const if const } end |