Class: REnvy::Should
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#!=(right) ⇒ Object
-
#<(right) ⇒ Object
-
#<=(right) ⇒ Object
-
#==(right) ⇒ Object
-
#=~(right) ⇒ Object
-
#>(right) ⇒ Object
-
#>=(right) ⇒ Object
-
#a ⇒ Object
-
#an ⇒ Object
-
#assert_or_refute(what, *args, &blk) ⇒ Object
-
#assert_or_refute_not(what, *args) ⇒ Object
-
#be(right = nil) ⇒ Object
-
#blaming(msg) ⇒ Object
-
#close(right, d = 0.001) ⇒ Object
-
#empty ⇒ Object
-
#equal(right) ⇒ Object
-
#in_epsilon(right, d = 0.001) ⇒ Object
-
#include(right) ⇒ Object
-
#initialize(left, neg = false) ⇒ Should
constructor
A new instance of Should.
-
#instance_of(right) ⇒ Object
-
#kind_of(right) ⇒ Object
-
#match(right) ⇒ Object
-
#messaging(msg) ⇒ Object
-
#method_missing(meth, *args, &blk) ⇒ Object
-
#negative? ⇒ Boolean
-
#nil ⇒ Object
-
#not ⇒ Object
-
#positive? ⇒ Boolean
-
#raise(ex = StandardError, &blk) ⇒ Object
-
#respond_to(right) ⇒ Object
-
#same(right) ⇒ Object
-
#satisfy(&blk) ⇒ Object
-
#test ⇒ Object
-
#throw(what = nil, &blk) ⇒ Object
Constructor Details
#initialize(left, neg = false) ⇒ Should
Returns a new instance of Should.
41
42
43
44
|
# File 'lib/renvy.rb', line 41
def initialize(left, neg=false)
@left = left
@neg = neg
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &blk) ⇒ Object
104
105
106
107
108
109
110
111
112
|
# File 'lib/renvy.rb', line 104
def method_missing(meth, *args, &blk)
result = left.send(:"#{meth}?", *args, &blk)
method = positive? ? :assert : :refute
args = [result]
args << msg if msg
test.send method, *args
end
|
Instance Attribute Details
Returns the value of attribute left.
29
30
31
|
# File 'lib/renvy.rb', line 29
def left
@left
end
|
Returns the value of attribute msg.
30
31
32
|
# File 'lib/renvy.rb', line 30
def msg
@msg
end
|
Class Method Details
.add(extension) ⇒ Object
Includes a module to extend .should with more matchers.
37
38
39
|
# File 'lib/renvy.rb', line 37
def self.add(extension)
self.send :include, extension
end
|
.init(test) ⇒ Object
32
33
34
|
# File 'lib/renvy.rb', line 32
def self.init(test) @@test = test
end
|
Instance Method Details
#!=(right) ⇒ Object
59
|
# File 'lib/renvy.rb', line 59
def !=(right) assert_or_refute_not :equal, right, left; end
|
62
|
# File 'lib/renvy.rb', line 62
def <(right) assert_or_refute :operator, left, :<, right; end
|
#<=(right) ⇒ Object
64
|
# File 'lib/renvy.rb', line 64
def <=(right) assert_or_refute :operator, left, :<=, right; end
|
#==(right) ⇒ Object
58
|
# File 'lib/renvy.rb', line 58
def ==(right) assert_or_refute :equal, right, left; end
|
#=~(right) ⇒ Object
60
|
# File 'lib/renvy.rb', line 60
def =~(right) assert_or_refute :match, right, left; end
|
61
|
# File 'lib/renvy.rb', line 61
def >(right) assert_or_refute :operator, left, :>, right; end
|
#>=(right) ⇒ Object
63
|
# File 'lib/renvy.rb', line 63
def >=(right) assert_or_refute :operator, left, :>=, right; end
|
47
|
# File 'lib/renvy.rb', line 47
def a() self; end
|
48
|
# File 'lib/renvy.rb', line 48
def an() self; end
|
#assert_or_refute(what, *args, &blk) ⇒ Object
80
81
82
|
# File 'lib/renvy.rb', line 80
def assert_or_refute(what, *args, &blk)
test.send (positive? ? :"assert_#{what}" : :"refute_#{what}"), *args, msg, &blk
end
|
#assert_or_refute_not(what, *args) ⇒ Object
84
85
86
|
# File 'lib/renvy.rb', line 84
def assert_or_refute_not(what, *args)
test.send (negative? ? :"assert_#{what}" : :"refute_#{what}"), *args, msg
end
|
#be(right = nil) ⇒ Object
46
|
# File 'lib/renvy.rb', line 46
def be(right=nil) self.same(right) if right; self; end
|
#blaming(msg) ⇒ Object
55
|
# File 'lib/renvy.rb', line 55
def blaming(msg); @msg = msg; self; end
|
#close(right, d = 0.001) ⇒ Object
77
|
# File 'lib/renvy.rb', line 77
def close(right, d=0.001) assert_or_refute :in_delta, right, left, d; end
|
71
|
# File 'lib/renvy.rb', line 71
def empty() assert_or_refute :empty, left; end
|
#equal(right) ⇒ Object
75
|
# File 'lib/renvy.rb', line 75
def equal(right) self == right; end
|
#in_epsilon(right, d = 0.001) ⇒ Object
78
|
# File 'lib/renvy.rb', line 78
def in_epsilon(right, d=0.001) assert_or_refute :in_epsilon, right, left, d; end
|
#include(right) ⇒ Object
65
|
# File 'lib/renvy.rb', line 65
def include(right) assert_or_refute :includes, left, right; end
|
#instance_of(right) ⇒ Object
66
|
# File 'lib/renvy.rb', line 66
def instance_of(right) assert_or_refute :instance_of, right, left; end
|
#kind_of(right) ⇒ Object
67
|
# File 'lib/renvy.rb', line 67
def kind_of(right) assert_or_refute :kind_of, right, left; end
|
#match(right) ⇒ Object
74
|
# File 'lib/renvy.rb', line 74
def match(right) self =~ right; end
|
#messaging(msg) ⇒ Object
56
|
# File 'lib/renvy.rb', line 56
def messaging(msg); @msg = msg; self; end
|
#negative? ⇒ Boolean
50
|
# File 'lib/renvy.rb', line 50
def negative?() @neg; end
|
68
|
# File 'lib/renvy.rb', line 68
def nil() assert_or_refute :nil, left; end
|
53
|
# File 'lib/renvy.rb', line 53
def not() @neg = true; self; end
|
#positive? ⇒ Boolean
51
|
# File 'lib/renvy.rb', line 51
def positive?() !@neg; end
|
#raise(ex = StandardError, &blk) ⇒ Object
96
97
98
99
100
101
102
|
# File 'lib/renvy.rb', line 96
def raise(ex=StandardError, &blk)
if positive?
test.send :assert_raises, ex, msg, &blk
else
test.send :assert_nothing_raised, msg, &blk
end
end
|
#respond_to(right) ⇒ Object
70
|
# File 'lib/renvy.rb', line 70
def respond_to(right) assert_or_refute :respond_to, left, right; end
|
#same(right) ⇒ Object
69
|
# File 'lib/renvy.rb', line 69
def same(right) assert_or_refute :same, right, left; end
|
#satisfy(&blk) ⇒ Object
72
|
# File 'lib/renvy.rb', line 72
def satisfy(&blk) assert_or_refute :block, &blk; end
|
52
|
# File 'lib/renvy.rb', line 52
def test() @@test; end
|
#throw(what = nil, &blk) ⇒ Object
88
89
90
91
92
93
94
|
# File 'lib/renvy.rb', line 88
def throw(what=nil, &blk)
if positive?
test.send :assert_throws, what, msg, &blk
else
test.send :assert_nothing_thrown, msg, &blk
end
end
|