Module: Defekt::Assertions

Included in:
Base
Defined in:
lib/defekt/assertions.rb

Instance Method Summary collapse

Instance Method Details

#equal_to!(expected, actual) ⇒ Object



27
28
29
30
31
# File 'lib/defekt/assertions.rb', line 27

def equal_to!(expected, actual)
  unless actual == expected
    raise Errors::EqualToError, message(actual, 'is not equal to', expected)
  end
end

#identical_to!(expected, actual) ⇒ Object



39
40
41
42
43
# File 'lib/defekt/assertions.rb', line 39

def identical_to!(expected, actual)
  unless actual.equal?(expected)
    raise Errors::IdenticalToError, message(actual, 'is not identical to', expected)
  end
end

#included_in!(collection, member) ⇒ Object



51
52
53
54
55
# File 'lib/defekt/assertions.rb', line 51

def included_in!(collection, member)
  unless collection.include?(member)
    raise Errors::IncludedInError, message(member, 'is not included in', collection)
  end
end

#instance_of!(klass, instance) ⇒ Object



63
64
65
66
67
# File 'lib/defekt/assertions.rb', line 63

def instance_of!(klass, instance)
  unless instance.instance_of?(klass)
    raise Errors::InstanceOfError, message(instance, 'is not an instance of', klass)
  end
end

#kind_of!(klass, instance) ⇒ Object



75
76
77
78
79
# File 'lib/defekt/assertions.rb', line 75

def kind_of!(klass, instance)
  unless instance.kind_of?(klass)
    raise Errors::KindOfError, message(instance, 'is not a kind of', klass)
  end
end

#nil!(value) ⇒ Object



15
16
17
18
19
# File 'lib/defekt/assertions.rb', line 15

def nil!(value)
  unless value.nil?
    raise Errors::NilError, message(value, 'is not', nil)
  end
end

#not_equal_to!(expected, actual) ⇒ Object



33
34
35
36
37
# File 'lib/defekt/assertions.rb', line 33

def not_equal_to!(expected, actual)
  if actual == expected
    raise Errors::NotEqualToError, message(actual, 'is equal to', expected)
  end
end

#not_identical_to!(expected, actual) ⇒ Object



45
46
47
48
49
# File 'lib/defekt/assertions.rb', line 45

def not_identical_to!(expected, actual)
  if actual.equal?(expected)
    raise Errors::NotIdenticalToError, message(actual, 'is identical to', expected)
  end
end

#not_included_in!(collection, member) ⇒ Object



57
58
59
60
61
# File 'lib/defekt/assertions.rb', line 57

def not_included_in!(collection, member)
  if collection.include?(member)
    raise Errors::NotIncludedInError, message(member, 'is included in', collection)
  end
end

#not_instance_of!(klass, instance) ⇒ Object



69
70
71
72
73
# File 'lib/defekt/assertions.rb', line 69

def not_instance_of!(klass, instance)
  if instance.instance_of?(klass)
    raise Errors::NotInstanceOfError, message(instance, 'is an instance of', klass)
  end
end

#not_kind_of!(klass, instance) ⇒ Object



81
82
83
84
85
# File 'lib/defekt/assertions.rb', line 81

def not_kind_of!(klass, instance)
  if instance.kind_of?(klass)
    raise Errors::NotKindOfError, message(instance, 'is a kind of', klass)
  end
end

#not_nil!(value) ⇒ Object



21
22
23
24
25
# File 'lib/defekt/assertions.rb', line 21

def not_nil!(value)
  if value.nil?
    raise Errors::NotNilError, message(value, 'is', nil)
  end
end

#not_respond_to!(object, methot) ⇒ Object



93
94
95
96
97
# File 'lib/defekt/assertions.rb', line 93

def not_respond_to!(object, methot)
  if object.respond_to?(methot)
    raise Errors::NotRespondToError, message(object, 'does respond to', methot)
  end
end

#not_true!(value) ⇒ Object



9
10
11
12
13
# File 'lib/defekt/assertions.rb', line 9

def not_true!(value)
  if value
    raise Errors::NotTrueError, message(value, 'is', true)
  end
end

#respond_to!(object, methot) ⇒ Object



87
88
89
90
91
# File 'lib/defekt/assertions.rb', line 87

def respond_to!(object, methot)
  unless object.respond_to?(methot)
    raise Errors::RespondToError, message(object, 'does not respond to', methot)
  end
end

#true!(value) ⇒ Object



3
4
5
6
7
# File 'lib/defekt/assertions.rb', line 3

def true!(value)
  unless value
    raise Errors::TrueError, message(value, 'is not', true)
  end
end

#verify!(mock) ⇒ Object



99
100
101
102
103
# File 'lib/defekt/assertions.rb', line 99

def verify!(mock)
  unless mock.verify
    raise Errors::MockExpectationError, 'mock expectation not met'
  end
end