Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/spectre.rb,
lib/spectre/assertion.rb
Instance Method Summary collapse
- #and(other) ⇒ Object
- #deep_clone ⇒ Object
- #evaluate(val, message, &block) ⇒ Object
- #or(other) ⇒ Object
- #should_be(value) ⇒ Object
- #should_be_empty ⇒ Object
- #should_not_be(val) ⇒ Object
- #should_not_be_empty ⇒ Object
- #should_not_exist ⇒ Object
- #to_h ⇒ Object
Instance Method Details
#and(other) ⇒ Object
42 43 44 |
# File 'lib/spectre/assertion.rb', line 42 def and other AndEvaluation.new(self, other) end |
#deep_clone ⇒ Object
25 26 27 |
# File 'lib/spectre.rb', line 25 def deep_clone Marshal.load(Marshal.dump(self)) end |
#evaluate(val, message, &block) ⇒ Object
33 34 35 36 |
# File 'lib/spectre/assertion.rb', line 33 def evaluate val, , &block val = Evaluation.new(val) unless val.is_a? Evaluation raise AssertionFailure.new(, val, self) unless val.run &block end |
#or(other) ⇒ Object
38 39 40 |
# File 'lib/spectre/assertion.rb', line 38 def or other OrEvaluation.new(self, other) end |
#should_be(value) ⇒ Object
11 12 13 14 15 |
# File 'lib/spectre/assertion.rb', line 11 def should_be(value) evaluate(value, "#{self} should be #{value}") do |x| self.to_s == x.to_s end end |
#should_be_empty ⇒ Object
17 18 19 |
# File 'lib/spectre/assertion.rb', line 17 def should_be_empty raise AssertionFailure.new("#{self.to_s.trim} should be empty", nil, self) unless self.nil? end |
#should_not_be(val) ⇒ Object
21 22 23 |
# File 'lib/spectre/assertion.rb', line 21 def should_not_be(val) raise AssertionFailure.new("#{self.to_s.trim} should not be #{val.to_s.trim}", val, self) unless self.to_s != val.to_s end |
#should_not_be_empty ⇒ Object
29 30 31 |
# File 'lib/spectre/assertion.rb', line 29 def should_not_be_empty raise AssertionFailure.new('empty value', 'nothing', self) unless self != nil end |
#should_not_exist ⇒ Object
25 26 27 |
# File 'lib/spectre/assertion.rb', line 25 def should_not_exist raise AssertionFailure.new("#{self.to_s.trim} should not exist, but it does", val, self) unless self.to_s != nil end |
#to_h ⇒ Object
19 20 21 22 23 |
# File 'lib/spectre.rb', line 19 def to_h self.instance_variables.each_with_object({}) do |var, hash| hash[var.to_s.delete("@")] = self.instance_variable_get(var) end end |