Class: Object

Inherits:
BasicObject
Defined in:
lib/spectre.rb,
lib/spectre/assertion.rb

Instance Method Summary collapse

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_cloneObject



25
26
27
# File 'lib/spectre.rb', line 25

def deep_clone
  Marshal.load(Marshal.dump(self))
end

#evaluate(val, message, &block) ⇒ Object

Raises:

  • (AssertionFailure)


33
34
35
36
# File 'lib/spectre/assertion.rb', line 33

def evaluate val, message, &block
  val = Evaluation.new(val) unless val.is_a? Evaluation
  raise AssertionFailure.new(message, 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_emptyObject

Raises:

  • (AssertionFailure)


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

Raises:

  • (AssertionFailure)


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_emptyObject

Raises:

  • (AssertionFailure)


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_existObject

Raises:

  • (AssertionFailure)


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_hObject



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