Module: TestDsl::ClassMethods

Includes:
Shared
Defined in:
lib/debugger/test/test_dsl.rb

Instance Method Summary collapse

Methods included from Shared

#fullpath

Instance Method Details

#temporary_change_hash_value(item, key, value) ⇒ Object



198
199
200
201
202
203
204
205
206
207
# File 'lib/debugger/test/test_dsl.rb', line 198

def temporary_change_hash_value(item, key, value)
  old_value = nil
  before do
    old_value = item[key]
    item[key] = value
  end
  after do
    item[key] = old_value
  end
end

#temporary_change_method_value(item, method, value) ⇒ Object



187
188
189
190
191
192
193
194
195
196
# File 'lib/debugger/test/test_dsl.rb', line 187

def temporary_change_method_value(item, method, value)
  old_value = nil
  before do
    old_value = item.send(method)
    item.send("#{method}=", value)
  end
  after do
    item.send("#{method}=", old_value)
  end
end

#temporary_set_const(klass, const, value) ⇒ Object



209
210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/debugger/test/test_dsl.rb', line 209

def temporary_set_const(klass, const, value)
  old_value = nil
  before do
    old_value = klass.const_defined?(const) ? klass.const_get(const) : :__undefined__
    force_set_const(klass, const, value)
  end
  after do
    if old_value == :__undefined__
      klass.send(:remove_const, const)
    else
      force_set_const(klass, const, old_value)
    end
  end
end