Class: Hash
- Defined in:
- lib/spectre.rb,
lib/spectre/helpers.rb,
lib/spectre/assertion.rb
Instance Method Summary collapse
- #deep_merge!(second) ⇒ Object
- #default_to!(defaults) ⇒ Object (also: #defaults_to!)
- #should_be_empty ⇒ Object
- #should_contain(other) ⇒ Object
- #should_not_be_empty ⇒ Object
- #should_not_contain(other) ⇒ Object
- #symbolize_keys ⇒ Object
Instance Method Details
#deep_merge!(second) ⇒ Object
12 13 14 15 |
# File 'lib/spectre.rb', line 12 def deep_merge!(second) merger = proc { |_key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge!(v2, &merger) : v2 } self.merge!(second, &merger) end |
#default_to!(defaults) ⇒ Object Also known as: defaults_to!
110 111 112 113 114 115 116 |
# File 'lib/spectre/helpers.rb', line 110 def default_to! defaults defaults.each_key do |key| unless self[key] != nil self[key] = defaults[key] end end end |
#should_be_empty ⇒ Object
76 77 78 |
# File 'lib/spectre/assertion.rb', line 76 def should_be_empty raise AssertionFailure.new('Object should be empty', nil, self) unless self.empty? end |
#should_contain(other) ⇒ Object
68 69 70 |
# File 'lib/spectre/assertion.rb', line 68 def should_contain(other) raise AssertionFailure.new(other, self) unless self.merge(other) == self end |
#should_not_be_empty ⇒ Object
80 81 82 |
# File 'lib/spectre/assertion.rb', line 80 def should_not_be_empty raise AssertionFailure.new('Object should not be empty', nil, self) if self.empty? end |
#should_not_contain(other) ⇒ Object
72 73 74 |
# File 'lib/spectre/assertion.rb', line 72 def should_not_contain(other) raise AssertionFailure.new(other, self) unless self.merge(other) != self end |
#symbolize_keys ⇒ Object
106 107 108 |
# File 'lib/spectre/helpers.rb', line 106 def symbolize_keys self.inject({}) { |memo, (k,v)| memo[k.to_sym] = v; memo } end |