Class: MustAssertions

Inherits:
BasicObject
Defined in:
lib/ruby_ext/core/must.rb

Direct Known Subclasses

Must, MustNot

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj) ⇒ MustAssertions

Returns a new instance of MustAssertions.



6
7
8
# File 'lib/ruby_ext/core/must.rb', line 6

def initialize obj    
  @obj = obj
end

Instance Attribute Details

#objObject (readonly)

Returns the value of attribute obj.



4
5
6
# File 'lib/ruby_ext/core/must.rb', line 4

def obj
  @obj
end

Class Method Details

.assertionsObject



118
119
120
121
# File 'lib/ruby_ext/core/must.rb', line 118

def self.assertions
  special = [:be, :have]
  public_instance_methods.select{|m| m !~ /^__/ and !special.include?(m)}    
end

Instance Method Details

#<(o) ⇒ Object



92
93
94
# File 'lib/ruby_ext/core/must.rb', line 92

def < o
  @obj < o
end

#<=(o) ⇒ Object



100
101
102
# File 'lib/ruby_ext/core/must.rb', line 100

def <= o
  @obj <= o
end

#==(o) ⇒ Object



10
11
12
# File 'lib/ruby_ext/core/must.rb', line 10

def == o
  @obj == o
end

#=~(o) ⇒ Object



14
15
16
# File 'lib/ruby_ext/core/must.rb', line 14

def =~ o
  @obj =~ o
end

#>(o) ⇒ Object



88
89
90
# File 'lib/ruby_ext/core/must.rb', line 88

def > o
  @obj > o
end

#>=(o) ⇒ Object



96
97
98
# File 'lib/ruby_ext/core/must.rb', line 96

def >= o
  @obj >= o
end

#a(*args) ⇒ Object Also known as: an



34
35
36
37
38
39
40
# File 'lib/ruby_ext/core/must.rb', line 34

def a *args    
  if args.class == ::Array
    args.any?{|k| @obj.is_a? k}
  else
    @obj.is_a? args
  end
end

#beObject



108
109
110
111
# File 'lib/ruby_ext/core/must.rb', line 108

def be    
  @prefix = 'be'
  self
end

#blankObject



80
81
82
# File 'lib/ruby_ext/core/must.rb', line 80

def blank
  @obj.blank?
end

#definedObject



26
27
28
# File 'lib/ruby_ext/core/must.rb', line 26

def defined
  @obj != nil
end

#emptyObject



76
77
78
# File 'lib/ruby_ext/core/must.rb', line 76

def empty    
  @obj.empty?
end

#exist(*args) ⇒ Object



104
105
106
# File 'lib/ruby_ext/core/must.rb', line 104

def exist *args
  @obj.exist? *args
end

#falseObject



72
73
74
# File 'lib/ruby_ext/core/must.rb', line 72

def false
  !@obj
end

#haveObject



113
114
115
116
# File 'lib/ruby_ext/core/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/core/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/core/must.rb', line 51

def include o
  @obj.include? o
end

#never_calledObject



18
19
20
# File 'lib/ruby_ext/core/must.rb', line 18

def never_called
  false
end

#nilObject



22
23
24
# File 'lib/ruby_ext/core/must.rb', line 22

def nil
  @obj.equal? nil
end

#presentObject



84
85
86
# File 'lib/ruby_ext/core/must.rb', line 84

def present
  !@obj.blank?
end

#respond_to(method) ⇒ Object



30
31
32
# File 'lib/ruby_ext/core/must.rb', line 30

def respond_to method
  @obj.respond_to? method
end

#trueObject



68
69
70
# File 'lib/ruby_ext/core/must.rb', line 68

def true
  !!@obj
end