test-belt 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/test_belt/matchers.rb +1 -1
- data/lib/test_belt/matchers/base.rb +12 -7
- data/lib/test_belt/matchers/have_class_methods.rb +4 -7
- data/lib/test_belt/matchers/have_files.rb +4 -6
- data/lib/test_belt/matchers/have_instance_methods.rb +6 -9
- data/lib/test_belt/version.rb +1 -1
- data/test/matchers_test.rb +29 -44
- metadata +4 -4
data/Gemfile.lock
CHANGED
data/lib/test_belt/matchers.rb
CHANGED
@@ -1,20 +1,25 @@
|
|
1
1
|
module TestBelt::Matchers
|
2
2
|
|
3
3
|
# Test Belt provides matchers to test common scenarios. Use these matchers
|
4
|
-
# in combination with the 'should' method to run common
|
5
|
-
#
|
4
|
+
# in combination with the 'should' method to run common tests. All matchers
|
5
|
+
# should subclass this base class.
|
6
6
|
|
7
7
|
class Base
|
8
|
+
attr_accessor :args
|
9
|
+
|
8
10
|
def desc
|
9
|
-
raise NotImplementedError, "
|
11
|
+
raise NotImplementedError, "provide a 'desc' method"
|
10
12
|
end
|
11
13
|
|
12
|
-
def
|
13
|
-
raise NotImplementedError, "
|
14
|
+
def test
|
15
|
+
raise NotImplementedError, "provide a 'test' method that returns a Proc that runs the matcher test"
|
14
16
|
end
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
+
protected
|
19
|
+
|
20
|
+
def using(*args, &block)
|
21
|
+
self.args = args
|
22
|
+
block
|
18
23
|
end
|
19
24
|
end
|
20
25
|
|
@@ -26,13 +26,10 @@ module TestBelt::Matchers
|
|
26
26
|
"respond to class method ##{@method}"
|
27
27
|
end
|
28
28
|
|
29
|
-
def
|
30
|
-
@
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
def fail_message
|
35
|
-
"#{@subject.class.name} does not have the class method ##{@method}"
|
29
|
+
def test
|
30
|
+
using(@method) do |method|
|
31
|
+
assert subject.class.respond_to?(method), "#{subject.class.name} does not have the class method ##{method}"
|
32
|
+
end
|
36
33
|
end
|
37
34
|
end
|
38
35
|
|
@@ -25,12 +25,10 @@ module TestBelt::Matchers
|
|
25
25
|
"have the file path '#{@file_path}'"
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
def fail_message
|
33
|
-
"'#{@file}' does not exist"
|
28
|
+
def test
|
29
|
+
using(@file_path) do |path|
|
30
|
+
assert File.exists?(path), "'#{path}' does not exist"
|
31
|
+
end
|
34
32
|
end
|
35
33
|
end
|
36
34
|
|
@@ -22,21 +22,18 @@ module TestBelt::Matchers
|
|
22
22
|
@method = method
|
23
23
|
end
|
24
24
|
|
25
|
-
def method_type
|
26
|
-
"instance method"
|
27
|
-
end
|
28
|
-
|
29
25
|
def desc
|
30
26
|
"respond to #{method_type} ##{@method}"
|
31
27
|
end
|
32
28
|
|
33
|
-
def
|
34
|
-
@
|
35
|
-
|
29
|
+
def test
|
30
|
+
using(@method) do |method|
|
31
|
+
assert subject.respond_to?(method), "#{subject.class.name} does not have instance method ##{method}"
|
32
|
+
end
|
36
33
|
end
|
37
34
|
|
38
|
-
def
|
39
|
-
"
|
35
|
+
def method_type
|
36
|
+
"instance method"
|
40
37
|
end
|
41
38
|
end
|
42
39
|
|
data/lib/test_belt/version.rb
CHANGED
data/test/matchers_test.rb
CHANGED
@@ -34,6 +34,16 @@ module TestBelt::Matchers
|
|
34
34
|
include TestBelt
|
35
35
|
|
36
36
|
context "the HaveInstanceMethods matcher"
|
37
|
+
subject {
|
38
|
+
class InstanceMethodsTest
|
39
|
+
def meth1
|
40
|
+
'meth1'
|
41
|
+
end
|
42
|
+
|
43
|
+
attr_reader :meth2
|
44
|
+
end
|
45
|
+
InstanceMethodsTest.new
|
46
|
+
}
|
37
47
|
|
38
48
|
should "take one string/symbol method argument" do
|
39
49
|
[nil, 12, Object, [], {}].each do |arg|
|
@@ -48,21 +58,9 @@ module TestBelt::Matchers
|
|
48
58
|
end
|
49
59
|
end
|
50
60
|
|
51
|
-
should "
|
52
|
-
|
53
|
-
|
54
|
-
'meth2' => (class Test2; attr_reader :meth2; end; Test2.new)
|
55
|
-
}.each do |meth, subject|
|
56
|
-
assert HaveInstanceMethods::Matcher.new(meth).matches?(subject)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
should "not match things without the expected instance methods" do
|
61
|
-
{
|
62
|
-
:meth3 => (class Test3; def meth1; 'meth1'; end; end; Test3.new),
|
63
|
-
'meth1' => (class Test4; attr_reader :meth2; end; Test4.new)
|
64
|
-
}.each do |meth, subject|
|
65
|
-
assert !HaveInstanceMethods::Matcher.new(meth).matches?(subject)
|
61
|
+
should "assert an expected instance method is present on the subject" do
|
62
|
+
[:meth1, 'meth2'].each do |meth|
|
63
|
+
assert_matcher HaveInstanceMethods::Matcher.new(meth)
|
66
64
|
end
|
67
65
|
end
|
68
66
|
end
|
@@ -73,6 +71,16 @@ module TestBelt::Matchers
|
|
73
71
|
include TestBelt
|
74
72
|
|
75
73
|
context "the HaveClassMethods matcher"
|
74
|
+
subject {
|
75
|
+
class ClassMethodsTest
|
76
|
+
def self.meth1
|
77
|
+
'meth1'
|
78
|
+
end
|
79
|
+
|
80
|
+
attr_reader :meth2
|
81
|
+
end
|
82
|
+
ClassMethodsTest.new
|
83
|
+
}
|
76
84
|
|
77
85
|
should "take one string/symbol method argument" do
|
78
86
|
[nil, 12, Object, [], {}].each do |arg|
|
@@ -87,19 +95,9 @@ module TestBelt::Matchers
|
|
87
95
|
end
|
88
96
|
end
|
89
97
|
|
90
|
-
should "
|
91
|
-
|
92
|
-
|
93
|
-
assert HaveClassMethods::Matcher.new(meth).matches?(subject)
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
should "not match things without the expected class methods" do
|
98
|
-
{ :meth3 => (class Test3; def self.meth1; 'meth1'; end; end; Test3.new),
|
99
|
-
:meth2 => (class Test2; def meth2; 'meth2'; end; end; Test2.new),
|
100
|
-
'meth1' => (class Test4; attr_reader :meth2; end; Test4.new)
|
101
|
-
}.each do |meth, subject|
|
102
|
-
assert !HaveClassMethods::Matcher.new(meth).matches?(subject)
|
98
|
+
should "assert an expected class method is present on the subject" do
|
99
|
+
[:meth1].each do |meth, subject|
|
100
|
+
assert_matcher HaveClassMethods::Matcher.new(meth)
|
103
101
|
end
|
104
102
|
end
|
105
103
|
end
|
@@ -111,22 +109,9 @@ module TestBelt::Matchers
|
|
111
109
|
|
112
110
|
context "the HaveFiles matcher"
|
113
111
|
|
114
|
-
should "
|
115
|
-
|
116
|
-
|
117
|
-
end
|
118
|
-
|
119
|
-
should "not match on file paths that do not exist" do
|
120
|
-
assert !HaveFiles::Matcher.new('./test/no_exist').matches?(subject)
|
121
|
-
assert !HaveFiles::Matcher.new('test/fixtures/no_exist.file').matches?(subject)
|
122
|
-
end
|
123
|
-
|
124
|
-
# should provide these macros
|
125
|
-
should "provide a set of macros" do
|
126
|
-
assert self.class.respond_to?(:have_directories), "no :should_have_directories macro"
|
127
|
-
assert self.class.respond_to?(:have_directory), "no :should_have_directory macro"
|
128
|
-
assert self.class.respond_to?(:have_files), "no :should_have_files macro"
|
129
|
-
assert self.class.respond_to?(:have_file), "no :should_have_file macro"
|
112
|
+
should "assert an existing file path actually exists" do
|
113
|
+
assert_matcher HaveFiles::Matcher.new('./test/fixtures/')
|
114
|
+
assert_matcher HaveFiles::Matcher.new('test/fixtures/thing.rb')
|
130
115
|
end
|
131
116
|
end
|
132
117
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: test-belt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
- 0
|
9
8
|
- 1
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 1.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kelly D. Redding
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-05-
|
18
|
+
date: 2011-05-20 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: bundler
|