Module: Invar::TestExtension::ScopeMethods

Included in:
Scope
Defined in:
lib/invar/test.rb

Overview

Methods mixin for the Invar::Scope class

Instance Method Summary collapse

Instance Method Details

#fetch(key) ⇒ Object Also known as: /, []



60
61
62
63
64
65
66
# File 'lib/invar/test.rb', line 60

def fetch(key)
   @pretend_data.fetch(key.downcase.to_sym) do
      super
   end
rescue KeyError => e
   raise KeyError, "#{ e.message }. Pretend keys are: #{ pretend_keys }."
end

#initialize(data) ⇒ Object



47
48
49
50
# File 'lib/invar/test.rb', line 47

def initialize(data)
   @pretend_data = {}
   super
end

#pretend(pairs) ⇒ Object

Overrides the given set of key-value pairs. This is intended to only be used in testing environments, where you may need contextual adjustments to suit the test situation.

Parameters:

  • pairs (Hash)

    the hash of pairs to override.



56
57
58
# File 'lib/invar/test.rb', line 56

def pretend(pairs)
   @pretend_data.merge! convert(pairs)
end

#to_hHash

Returns a hash representation of this scope and subscopes.

Returns:

  • (Hash)

    a hash representation of this scope



75
76
77
# File 'lib/invar/test.rb', line 75

def to_h
   super.merge(@pretend_data).to_h
end