minitest-chain 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/minitest-chain.rb +14 -6
- data/test/test_chain.rb +16 -0
- metadata +2 -2
data/lib/minitest-chain.rb
CHANGED
@@ -2,9 +2,11 @@ require 'minitest/unit'
|
|
2
2
|
|
3
3
|
module MiniTest::Chain
|
4
4
|
class AssertionChain
|
5
|
-
|
5
|
+
attr_reader :scope, :subject
|
6
|
+
|
7
|
+
def initialize(scope, subject)
|
6
8
|
@scope = scope
|
7
|
-
@
|
9
|
+
@subject = subject
|
8
10
|
end
|
9
11
|
|
10
12
|
# Flippers:
|
@@ -14,16 +16,17 @@ module MiniTest::Chain
|
|
14
16
|
[:close_to, :in_delta],
|
15
17
|
[:within_epsilon, :in_epsilon],
|
16
18
|
[:instance_of, :instance_of],
|
19
|
+
[:kind_of, :kind_of],
|
17
20
|
[:same, :same],
|
18
21
|
].each do |name, assertion|
|
19
22
|
class_eval <<-RUBY, __FILE__, __LINE__+1
|
20
23
|
def #{name}(other, *args)
|
21
|
-
|
24
|
+
scope.assert_#{assertion}(other, subject, *args)
|
22
25
|
self
|
23
26
|
end
|
24
27
|
|
25
28
|
def not_#{name}(other, *args)
|
26
|
-
|
29
|
+
scope.refute_#{assertion}(other, subject, *args)
|
27
30
|
self
|
28
31
|
end
|
29
32
|
RUBY
|
@@ -32,18 +35,19 @@ module MiniTest::Chain
|
|
32
35
|
# Unaries and reversers:
|
33
36
|
[
|
34
37
|
[:empty, :empty],
|
38
|
+
[:nil, :nil],
|
35
39
|
[:include, :includes],
|
36
40
|
[:is, :operator],
|
37
41
|
[:respond_to, :respond_to],
|
38
42
|
].each do |name, assertion|
|
39
43
|
class_eval <<-RUBY, __FILE__, __LINE__+1
|
40
44
|
def #{name}(*args)
|
41
|
-
|
45
|
+
scope.assert_#{assertion}(subject, *args)
|
42
46
|
self
|
43
47
|
end
|
44
48
|
|
45
49
|
def not_#{name}(*args)
|
46
|
-
|
50
|
+
scope.refute_#{assertion}(subject, *args)
|
47
51
|
self
|
48
52
|
end
|
49
53
|
RUBY
|
@@ -57,5 +61,9 @@ module MiniTest::Chain
|
|
57
61
|
super
|
58
62
|
AssertionChain.new(self, obj)
|
59
63
|
end
|
64
|
+
|
65
|
+
def expect(obj)
|
66
|
+
AssertionChain.new(self, obj)
|
67
|
+
end
|
60
68
|
end
|
61
69
|
|
data/test/test_chain.rb
CHANGED
@@ -65,6 +65,14 @@ class TestChain < MiniTest::Unit::TestCase
|
|
65
65
|
assert_refutes { assert(1 ).not_instance_of(Fixnum) }
|
66
66
|
end
|
67
67
|
|
68
|
+
def test_kind_of
|
69
|
+
assert(1).kind_of(Numeric)
|
70
|
+
assert("").not_kind_of(Numeric)
|
71
|
+
|
72
|
+
assert_refutes { assert("").kind_of(Numeric) }
|
73
|
+
assert_refutes { assert(1).not_kind_of(Numeric) }
|
74
|
+
end
|
75
|
+
|
68
76
|
def test_is
|
69
77
|
assert(1).is(:<, 2)
|
70
78
|
assert(3).is_not(:<, 2)
|
@@ -112,5 +120,13 @@ class TestChain < MiniTest::Unit::TestCase
|
|
112
120
|
.equal(1)
|
113
121
|
.instance_of(Fixnum)
|
114
122
|
end
|
123
|
+
|
124
|
+
def test_nil
|
125
|
+
expect(nil).nil
|
126
|
+
expect(1).not_nil
|
127
|
+
|
128
|
+
assert_refutes { expect(1).nil }
|
129
|
+
assert_refutes { expect(nil).not_nil }
|
130
|
+
end
|
115
131
|
end
|
116
132
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minitest-chain
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: minitest
|