Class: OpenStruct
- Defined in:
- lib/spectre/helpers.rb,
lib/spectre/assertion.rb
Instance Method Summary collapse
- #default_to!(defaults) ⇒ Object (also: #defaults_to!)
- #pick(path) ⇒ Object
- #should_be_empty ⇒ Object
- #should_not_be_empty ⇒ Object
- #to_json(*args, **kwargs) ⇒ Object
Instance Method Details
#default_to!(defaults) ⇒ Object Also known as: defaults_to!
94 95 96 97 98 99 100 |
# File 'lib/spectre/helpers.rb', line 94 def default_to! defaults defaults.each_key do |key| unless self[key] != nil self[key] = defaults[key] end end end |
#pick(path) ⇒ Object
88 89 90 91 92 |
# File 'lib/spectre/helpers.rb', line 88 def pick path raise ArgumentError.new("`path' must not be nil or empty") if path.nil? or path.empty? JsonPath.on(self, path) end |
#should_be_empty ⇒ Object
86 87 88 |
# File 'lib/spectre/assertion.rb', line 86 def should_be_empty raise AssertionFailure.new('Object should be empty', nil, self) unless self.to_h.empty? end |
#should_not_be_empty ⇒ Object
90 91 92 |
# File 'lib/spectre/assertion.rb', line 90 def should_not_be_empty raise AssertionFailure.new('Object should not be empty', nil, self) if self.to_h.empty? end |
#to_json(*args, **kwargs) ⇒ Object
84 85 86 |
# File 'lib/spectre/helpers.rb', line 84 def to_json *args, **kwargs self.to_h.inject({}) { |memo, (k,v)| memo[k] = v.is_a?(OpenStruct) ? v.to_h : v; memo }.to_json(*args, **kwargs) end |