Sha256: 0bba8f6329ffa2755f5c61ffba1655f919ac26d8e73a404d6f997d2bfbc713f4

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

module CommonSpecHelpers

  def fixture_path(path)
    File.expand_path("../../fixtures/#{path}", __FILE__)
  end

  def with_constants(constants, &block)
    saved_constants = {}
    constants.each do |constant, value|
      saved_constants[constant] = Object.const_get(constant)
      silence_all_warnings do
        Object.const_set(constant, value)
      end
    end

    begin
      block.call
    ensure
      constants.each do |constant, value|
        silence_all_warnings do
          Object.const_set(constant, saved_constants[constant])
        end
      end
    end
  end

  def with_values(object, new_values)
    old_values = {}
    new_values.each do |key, value|
      old_values[key] = object.send key
      object.send :"#{key}=", value
    end
    yield
  ensure
    old_values.each do |key, value|
      object.send :"#{key}=", value
    end
  end

  def silence_all_warnings
    # Ruby 1.8: Kernel.silence_warnings { yield }
    old_verbose = $VERBOSE
    $VERBOSE = nil
    yield
    $VERBOSE = old_verbose
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
packr-rails-0.0.1 spec/support/common_spec_helpers.rb