Class: Minitest::ShouldJustWork::Should
- Inherits:
-
Object
- Object
- Minitest::ShouldJustWork::Should
show all
- Defined in:
- lib/minitest/should_just_work.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(left) ⇒ Should
Returns a new instance of Should.
52
53
54
55
56
57
58
59
|
# File 'lib/minitest/should_just_work.rb', line 52
def initialize(left)
@left = left
return unless test.msg
blaming test.msg
test.msg = nil
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &blk) ⇒ Object
131
132
133
134
135
136
137
138
139
|
# File 'lib/minitest/should_just_work.rb', line 131
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.
41
42
43
|
# File 'lib/minitest/should_just_work.rb', line 41
def left
@left
end
|
Returns the value of attribute msg.
41
42
43
|
# File 'lib/minitest/should_just_work.rb', line 41
def msg
@msg
end
|
Class Method Details
.add(extension) ⇒ Object
Includes a module to extend .should with more matchers.
48
49
50
|
# File 'lib/minitest/should_just_work.rb', line 48
def self.add(extension)
send :include, extension
end
|
.init(test) ⇒ Object
43
44
45
|
# File 'lib/minitest/should_just_work.rb', line 43
def self.init(test) @@test = test
end
|
Instance Method Details
#!=(right) ⇒ Object
85
|
# File 'lib/minitest/should_just_work.rb', line 85
def !=(right) refute_or_assert :equal, right, left; end
|
87
|
# File 'lib/minitest/should_just_work.rb', line 87
def <(right) assert_or_refute :operator, left, :<, right; end
|
#<=(right) ⇒ Object
89
|
# File 'lib/minitest/should_just_work.rb', line 89
def <=(right) assert_or_refute :operator, left, :<=, right; end
|
#==(right) ⇒ Object
83
|
# File 'lib/minitest/should_just_work.rb', line 83
def ==(right) assert_or_refute :equal, right, left; end
|
#=~(right) ⇒ Object
84
|
# File 'lib/minitest/should_just_work.rb', line 84
def =~(right) assert_or_refute :match, right, left; end
|
86
|
# File 'lib/minitest/should_just_work.rb', line 86
def >(right) assert_or_refute :operator, left, :>, right; end
|
#>=(right) ⇒ Object
88
|
# File 'lib/minitest/should_just_work.rb', line 88
def >=(right) assert_or_refute :operator, left, :>=, right; end
|
62
|
# File 'lib/minitest/should_just_work.rb', line 62
def a() self; end
|
63
|
# File 'lib/minitest/should_just_work.rb', line 63
def an() self; end
|
#assert_or_refute(what, *args, &blk) ⇒ Object
105
106
107
108
|
# File 'lib/minitest/should_just_work.rb', line 105
def assert_or_refute(what, *args, &blk)
args << msg
test.send((positive? ? :"assert_#{what}" : :"refute_#{what}"), *args, &blk)
end
|
#be(right = nil) ⇒ Object
61
|
# File 'lib/minitest/should_just_work.rb', line 61
def be(right=nil) self.same(right) if right; self; end
|
#blaming(msg) ⇒ Object
80
|
# File 'lib/minitest/should_just_work.rb', line 80
def blaming(msg); @msg = msg; self; end
|
#close(right, d = 0.001) ⇒ Object
102
|
# File 'lib/minitest/should_just_work.rb', line 102
def close(right, d=0.001) assert_or_refute :in_delta, right, left, d; end
|
96
|
# File 'lib/minitest/should_just_work.rb', line 96
def empty() assert_or_refute :empty, left; end
|
#equal(right) ⇒ Object
100
|
# File 'lib/minitest/should_just_work.rb', line 100
def equal(right) self == right; end
|
71
|
# File 'lib/minitest/should_just_work.rb', line 71
def false() true_or_false(false); end
|
#in_epsilon(right, d = 0.001) ⇒ Object
103
|
# File 'lib/minitest/should_just_work.rb', line 103
def in_epsilon(right, d=0.001) assert_or_refute :in_epsilon, right, left, d; end
|
#include(right) ⇒ Object
90
|
# File 'lib/minitest/should_just_work.rb', line 90
def include(right) assert_or_refute :includes, left, right; end
|
#instance_of(right) ⇒ Object
91
|
# File 'lib/minitest/should_just_work.rb', line 91
def instance_of(right) assert_or_refute :instance_of, right, left; end
|
#kind_of(right) ⇒ Object
92
|
# File 'lib/minitest/should_just_work.rb', line 92
def kind_of(right) assert_or_refute :kind_of, right, left; end
|
#match(right) ⇒ Object
99
|
# File 'lib/minitest/should_just_work.rb', line 99
def match(right) self =~ right; end
|
#messaging(msg) ⇒ Object
81
|
# File 'lib/minitest/should_just_work.rb', line 81
def messaging(msg); @msg = msg; self; end
|
#negative? ⇒ Boolean
65
|
# File 'lib/minitest/should_just_work.rb', line 65
def negative?() @neg; end
|
93
|
# File 'lib/minitest/should_just_work.rb', line 93
def nil() assert_or_refute :nil, left; end
|
68
|
# File 'lib/minitest/should_just_work.rb', line 68
def not() @neg = true; self; end
|
#positive? ⇒ Boolean
66
|
# File 'lib/minitest/should_just_work.rb', line 66
def positive?() !@neg; end
|
#raise(ex = StandardError, &blk) ⇒ Object
123
124
125
126
127
128
129
|
# File 'lib/minitest/should_just_work.rb', line 123
def raise(ex=StandardError, &blk)
if positive?
test.send :assert_raises, ex, msg, &blk
else
warn "ShouldJustWork: should.not.raise is not supported"
end
end
|
#refute_or_assert(what, *args) ⇒ Object
110
111
112
113
|
# File 'lib/minitest/should_just_work.rb', line 110
def refute_or_assert(what, *args)
args << msg
test.send((negative? ? :"assert_#{what}" : :"refute_#{what}"), *args)
end
|
#respond_to(right) ⇒ Object
95
|
# File 'lib/minitest/should_just_work.rb', line 95
def respond_to(right) assert_or_refute :respond_to, left, right; end
|
#same(right) ⇒ Object
94
|
# File 'lib/minitest/should_just_work.rb', line 94
def same(right) assert_or_refute :same, right, left; end
|
#satisfy(&blk) ⇒ Object
97
|
# File 'lib/minitest/should_just_work.rb', line 97
def satisfy(&blk) assert_or_refute :block, &blk; end
|
67
|
# File 'lib/minitest/should_just_work.rb', line 67
def test() @@test; end
|
#throw(what = nil, &blk) ⇒ Object
115
116
117
118
119
120
121
|
# File 'lib/minitest/should_just_work.rb', line 115
def throw(what=nil, &blk)
if positive?
test.send :assert_throws, what, msg, &blk
else
warn "ShouldJustWork: should.not.throw is not supported"
end
end
|
70
|
# File 'lib/minitest/should_just_work.rb', line 70
def true() true_or_false(true); end
|
#true_or_false(bool) ⇒ Object
73
74
75
76
77
78
|
# File 'lib/minitest/should_just_work.rb', line 73
def true_or_false(bool)
val = !! left
val = !val if bool == false
method = (positive? ? :"assert" : :"refute")
test.send method, val, [msg, 'Expected to be falsy'].compact.join("\n")
end
|