Sha256: e0506141b3fff4baa47daaff5719cd2662c72b5ae8a3ed580883337d138981d4

Contents?: true

Size: 1.16 KB

Versions: 3

Compression:

Stored size: 1.16 KB

Contents

require 'rspec'

require 'viking'

RSpec.configure do |config|
  config.mock_with :rspec
end

# See http://blog.jayfields.com/2007/11/ruby-testing-private-methods.html
class Class
  def publicize_methods(instance=nil)
    saved_private_instance_methods = self.private_instance_methods
    self.class_eval { public *saved_private_instance_methods }
    yield(instance)
  ensure
    self.class_eval { private *saved_private_instance_methods }
  end
end

##
# rSpec Hash additions.
#
# From
#   * http://wincent.com/knowledge-base/Fixtures_considered_harmful%3F
#   * Neil Rahilly
class Hash
  ##
  # Filter keys out of a Hash.
  #
  #   { :a => 1, :b => 2, :c => 3 }.except(:a)
  #   => { :b => 2, :c => 3 }
  def except(*keys)
    self.reject { |k,v| keys.include?(k || k.to_sym) }
  end

  ##
  # Override some keys.
  #
  #   { :a => 1, :b => 2, :c => 3 }.with(:a => 4)
  #   => { :a => 4, :b => 2, :c => 3 }
  def with(overrides = {})
    self.merge overrides
  end

  ##
  # Returns a Hash with only the pairs identified by +keys+.
  #
  #   { :a => 1, :b => 2, :c => 3 }.only(:a)
  #   => { :a => 1 }
  def only(*keys)
    self.reject { |k,v| !keys.include?(k || k.to_sym) }
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
the_viking-1.0.0 spec/spec_helper.rb
viking-1.0.1 spec/spec_helper.rb
viking-1.0.0 spec/spec_helper.rb