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.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- test-belt (1.0.1)
4
+ test-belt (1.1.0)
5
5
  leftright (~> 0.9.0)
6
6
 
7
7
  GEM
@@ -23,7 +23,7 @@ module TestBelt::Matchers
23
23
  end
24
24
 
25
25
  def assert_matcher(matcher)
26
- assert_block(matcher.fail_message) { matcher.matches?(subject) }
26
+ instance_exec(*matcher.args, &matcher.test)
27
27
  end
28
28
 
29
29
  end
@@ -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 test cases. All
5
- # matchers should subclass this base class.
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, "no description provided for the matcher"
11
+ raise NotImplementedError, "provide a 'desc' method"
10
12
  end
11
13
 
12
- def matches?(*args)
13
- raise NotImplementedError, "no matches? test logic provided for the matcher"
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
- def fail_message
17
- raise NotImplementedError, "no fail message provided for the matcher"
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 matches?(subject)
30
- @subject = subject
31
- subject.class.respond_to?(@method)
32
- end
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 matches?(subject)
29
- File.exists?(@file_path)
30
- end
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 matches?(subject)
34
- @subject = subject
35
- subject.respond_to?(@method)
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 fail_message
39
- "#{@subject.class.name} does not have instance method ##{@method}"
35
+ def method_type
36
+ "instance method"
40
37
  end
41
38
  end
42
39
 
@@ -1,3 +1,3 @@
1
1
  module TestBelt
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -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 "match things with the expected instance method" do
52
- {
53
- :meth1 => (class Test1; def meth1; 'meth1'; end; end; Test1.new),
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 "match things with the expected class method" do
91
- { :meth1 => (class Test1; def self.meth1; 'meth1'; end; end; Test1.new)
92
- }.each do |meth, subject|
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 "match on file paths that exist" do
115
- assert HaveFiles::Matcher.new('./test/fixtures/').matches?(subject)
116
- assert HaveFiles::Matcher.new('test/fixtures/thing.rb').matches?(subject)
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: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 0
9
8
  - 1
10
- version: 1.0.1
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-14 00:00:00 Z
18
+ date: 2011-05-20 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: bundler