Class: MustAssertions
Constant Summary
ExtraBlankSlate::CUSTOM_UNDEFINE
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of MustAssertions.
6
7
8
|
# File 'lib/ruby_ext/must.rb', line 6
def initialize obj
@obj = obj
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &b) ⇒ Object
124
125
126
|
# File 'lib/ruby_ext/must.rb', line 124
def method_missing m, *args, &b
raise RuntimeError, "Assertion '#{m}' is unknown!", caller[1..-1]
end
|
Instance Attribute Details
Returns the value of attribute obj.
4
5
6
|
# File 'lib/ruby_ext/must.rb', line 4
def obj
@obj
end
|
Class Method Details
.assertions ⇒ Object
118
119
120
121
|
# File 'lib/ruby_ext/must.rb', line 118
def self.assertions
special = %w{be have}
instance_methods.select{|m| m !~ /^__/ and m != 'be'}
end
|
Instance Method Details
92
93
94
|
# File 'lib/ruby_ext/must.rb', line 92
def < o
@obj < o
end
|
100
101
102
|
# File 'lib/ruby_ext/must.rb', line 100
def <= o
@obj <= o
end
|
10
11
12
|
# File 'lib/ruby_ext/must.rb', line 10
def == o
@obj == o
end
|
14
15
16
|
# File 'lib/ruby_ext/must.rb', line 14
def =~ o
@obj =~ o
end
|
88
89
90
|
# File 'lib/ruby_ext/must.rb', line 88
def > o
@obj > o
end
|
96
97
98
|
# File 'lib/ruby_ext/must.rb', line 96
def >= o
@obj >= o
end
|
#a(klass) ⇒ Object
Also known as:
an
34
35
36
37
38
39
40
|
# File 'lib/ruby_ext/must.rb', line 34
def a klass
if klass.class == Array
klass.any?{|k| @obj.is_a? k}
else
@obj.is_a? klass
end
end
|
108
109
110
111
|
# File 'lib/ruby_ext/must.rb', line 108
def be
@prefix = 'be'
self
end
|
80
81
82
|
# File 'lib/ruby_ext/must.rb', line 80
def blank
@obj.blank?
end
|
26
27
28
|
# File 'lib/ruby_ext/must.rb', line 26
def defined
!nil
end
|
76
77
78
|
# File 'lib/ruby_ext/must.rb', line 76
def empty
@obj.empty?
end
|
#exist(arg) ⇒ Object
104
105
106
|
# File 'lib/ruby_ext/must.rb', line 104
def exist arg
@obj.exist? arg
end
|
72
73
74
|
# File 'lib/ruby_ext/must.rb', line 72
def false
!@obj
end
|
113
114
115
116
|
# File 'lib/ruby_ext/must.rb', line 113
def have
@prefix = 'have'
self
end
|
#in(*args) ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/ruby_ext/must.rb', line 55
def in *args
if args.size == 1
obj = args.first
if obj.is_a?(Array) or obj.is_a?(Range)
obj.include? @obj
else
args.include? @obj
end
else
args.include? @obj
end
end
|
#include(o) ⇒ Object
def be klass = nil
if klass.class == Array
klass.any?{|k| @obj.respond_to :is?, k}
else
@obj.respond_to :is?, klass
end
end
51
52
53
|
# File 'lib/ruby_ext/must.rb', line 51
def include o
@obj.include? o
end
|
#never_called ⇒ Object
18
19
20
|
# File 'lib/ruby_ext/must.rb', line 18
def never_called
false
end
|
22
23
24
|
# File 'lib/ruby_ext/must.rb', line 22
def nil
@obj.equal? nil
end
|
84
85
86
|
# File 'lib/ruby_ext/must.rb', line 84
def present
!@obj.blank?
end
|
#respond_to(method) ⇒ Object
30
31
32
|
# File 'lib/ruby_ext/must.rb', line 30
def respond_to method
@obj.respond_to? method
end
|
68
69
70
|
# File 'lib/ruby_ext/must.rb', line 68
def true
!!@obj
end
|