test-belt 0.2.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/.gitignore +2 -1
  2. data/Gemfile.lock +23 -0
  3. data/lib/test_belt/callbacks.rb +22 -0
  4. data/lib/test_belt/callbacks/case.rb +86 -0
  5. data/lib/test_belt/callbacks/suite.rb +106 -0
  6. data/lib/test_belt/callbacks/test.rb +58 -0
  7. data/lib/test_belt/context.rb +40 -0
  8. data/lib/test_belt/default_test.rb +18 -0
  9. data/lib/test_belt/helper.rb +24 -3
  10. data/lib/test_belt/matchers.rb +29 -0
  11. data/lib/test_belt/matchers/base.rb +21 -0
  12. data/lib/test_belt/matchers/have_accessors.rb +23 -0
  13. data/lib/test_belt/matchers/have_class_methods.rb +40 -0
  14. data/lib/test_belt/matchers/have_files.rb +38 -0
  15. data/lib/test_belt/matchers/have_instance_methods.rb +44 -0
  16. data/lib/test_belt/matchers/have_readers.rb +26 -0
  17. data/lib/test_belt/matchers/have_writers.rb +30 -0
  18. data/lib/test_belt/should.rb +76 -0
  19. data/lib/test_belt/skip.rb +41 -0
  20. data/lib/test_belt/subject.rb +47 -0
  21. data/lib/test_belt/version.rb +1 -1
  22. data/test/callbacks_test.rb +172 -0
  23. data/test/fixtures/{shoulda_macros/thing.rb → thing.rb} +0 -0
  24. data/test/helpers_test.rb +175 -0
  25. data/test/matchers_test.rb +135 -0
  26. data/test/rake_tasks_test.rb +8 -17
  27. metadata +33 -31
  28. data/lib/test_belt/shoulda_macros.rb +0 -9
  29. data/lib/test_belt/shoulda_macros/classes.rb +0 -105
  30. data/lib/test_belt/shoulda_macros/context.rb +0 -25
  31. data/lib/test_belt/shoulda_macros/files.rb +0 -49
  32. data/lib/test_belt/test_unit.rb +0 -8
  33. data/lib/test_belt/test_unit/context.rb +0 -71
  34. data/lib/test_belt/test_unit/runner.rb +0 -48
  35. data/lib/test_belt/test_unit/test_case.rb +0 -26
  36. data/test/shoulda_macros/classes_test.rb +0 -58
  37. data/test/shoulda_macros/context_test.rb +0 -28
  38. data/test/shoulda_macros/files_test.rb +0 -36
  39. data/test/test_unit/context_test.rb +0 -65
  40. data/test/test_unit/runner_test.rb +0 -31
  41. data/test/test_unit/test_case_test.rb +0 -30
File without changes
@@ -0,0 +1,175 @@
1
+ require "test/helper"
2
+
3
+ module TestBelt
4
+
5
+ class ShouldMethodTest < Test::Unit::TestCase
6
+ include TestBelt
7
+
8
+ define_method "test: should provide a 'should' method. ".to_sym do
9
+ assert self.class.respond_to?(:should), "no #should method"
10
+ end
11
+
12
+ define_method "test: should provide a 'should_eventually' method for skipping tests. ".to_sym do
13
+ assert self.class.respond_to?(:should_eventually), "no #should_eventually method"
14
+ end
15
+
16
+ define_method "test: should require a description and test block. ".to_sym do
17
+ assert_raises ArgumentError do
18
+ self.class.send(:should)
19
+ end
20
+ assert_raises ArgumentError do
21
+ self.class.send(:should, 'test_something')
22
+ end
23
+ end
24
+
25
+ should "run this assertion" do
26
+ assert true
27
+ end
28
+ end
29
+
30
+
31
+
32
+ class SkipTest < Test::Unit::TestCase
33
+ include TestBelt
34
+
35
+ context "Test Belt"
36
+
37
+ should "provide a skip assertion that uses LeftRight's skipping logic" do
38
+ assert_respond_to self, :skip, 'no skip method for the test case'
39
+ prev_skipped_count = ::LeftRight.state.skipped_count if defined? ::LeftRight
40
+ skip(false)
41
+ if defined? ::LeftRight
42
+ assert ::LeftRight.state.skip, 'left right is not in skip state for this case'
43
+ assert_equal prev_skipped_count+1, ::LeftRight.state.skipped_count, 'LeftRight\'s skip count was not incremented'
44
+ ::LeftRight.state.skip = false
45
+ ::LeftRight.state.skipped_count -= 1
46
+ end
47
+ end
48
+ end
49
+
50
+
51
+
52
+ class ClassWithNoTestsTest < Test::Unit::TestCase
53
+ include TestBelt
54
+
55
+ # the test here is that having a TestCase with
56
+ # no 'test_*' methods should not flunk
57
+
58
+ end
59
+
60
+
61
+
62
+ class ContextTest < Test::Unit::TestCase
63
+ include TestBelt
64
+
65
+ should "provide a 'context' class method" do
66
+ assert self.class.respond_to?(:context), "no :context class method"
67
+ end
68
+
69
+ should "provide a 'context' instance method" do
70
+ assert self.respond_to?(:context), "no :context instance method"
71
+ end
72
+
73
+ should "require a description" do
74
+ assert_raises ArgumentError do
75
+ self.class.send(:context, nil)
76
+ end
77
+ end
78
+
79
+ should "have an empty context by default" do
80
+ assert_equal "", self.send(:context)
81
+ end
82
+ end
83
+
84
+ class UsingContextTest < Test::Unit::TestCase
85
+ include TestBelt
86
+
87
+ context "using context test"
88
+
89
+ should "use the context string" do
90
+ assert_equal "using context test", self.send(:context)
91
+ end
92
+ end
93
+
94
+ class RootNestedTest < Test::Unit::TestCase
95
+ include TestBelt
96
+
97
+ context 'root'
98
+ end
99
+ class OneNestedTest < RootNestedTest
100
+ include TestBelt
101
+
102
+ context 'one'
103
+ end
104
+ class TwoNestedTest < OneNestedTest
105
+ include TestBelt
106
+
107
+ context 'two'
108
+
109
+ should "have a nested context string" do
110
+ assert_equal "root one two", self.send(:context)
111
+ end
112
+ end
113
+
114
+
115
+
116
+ class SubjectTest < Test::Unit::TestCase
117
+ include TestBelt
118
+
119
+ context "a test defining it's subject"
120
+ subject {
121
+ 'my subject'
122
+ }
123
+
124
+ should "know it's subject" do
125
+ assert_equal 'my subject', subject
126
+ end
127
+ end
128
+ class RootSubjectTest < Test::Unit::TestCase
129
+ include TestBelt
130
+
131
+ subject {
132
+ 'root subject'
133
+ }
134
+
135
+ end
136
+ class SubclassOrigSubjectTest < RootSubjectTest
137
+ include TestBelt
138
+
139
+ context "a test subclassing a test with a root subject"
140
+
141
+ should "recognize the super class subject" do
142
+ assert_equal 'root subject', subject
143
+ end
144
+ end
145
+ class SubclassNewSubjectTest < RootSubjectTest
146
+ include TestBelt
147
+
148
+ context "a test subclassing a test with a root subject but defining it's own subject"
149
+ subject {
150
+ 'new sub class subject'
151
+ }
152
+
153
+ should "recognize use it's subject over the super class subject" do
154
+ assert_equal 'new sub class subject', subject
155
+ end
156
+ end
157
+ class ScopedSubjectTest < Test::Unit::TestCase
158
+ include TestBelt
159
+
160
+ context "a test defining a before callback data that is used in it's subject"
161
+ before {
162
+ @setup_info = "my setup'd"
163
+ }
164
+ subject {
165
+ @setup_info + ' subject'
166
+ }
167
+
168
+ should "know it's subject" do
169
+ assert_equal "my setup'd subject", subject
170
+ end
171
+ end
172
+
173
+
174
+
175
+ end
@@ -0,0 +1,135 @@
1
+ require "test/helper"
2
+ require 'test/fixtures/thing'
3
+
4
+ module TestBelt::Matchers
5
+
6
+
7
+ class ThingMatcherTest < Test::Unit::TestCase
8
+ include TestBelt
9
+
10
+ context "a dummy class"
11
+ subject { Thing.new }
12
+
13
+ should have_instance_method :an_instance_meth
14
+ should have_instance_methods :instance1, :instance2
15
+ should have_class_method :a_class_meth
16
+ should have_class_methods :class1, :class2
17
+
18
+ should have_readers :reader1, :reader2
19
+ should have_reader :reader3
20
+ should have_writers :writer1, :writer2
21
+ should have_writer :writer3
22
+ should have_accessors :accessor1, :accessor2
23
+ should have_accessor :accessor3
24
+
25
+ should have_directory 'test'
26
+ should have_directories './test/fixtures'
27
+ should have_file 'test/fixtures/thing.rb'
28
+ should have_files './test/env.rb', './test/helper.rb'
29
+ end
30
+
31
+
32
+
33
+ class InstanceMethodsMatcherTest < Test::Unit::TestCase
34
+ include TestBelt
35
+
36
+ context "the HaveInstanceMethods matcher"
37
+
38
+ should "take one string/symbol method argument" do
39
+ [nil, 12, Object, [], {}].each do |arg|
40
+ assert_raises ArgumentError do
41
+ HaveInstanceMethods::Matcher.new(arg)
42
+ end
43
+ end
44
+ ['name', :name].each do |arg|
45
+ assert_nothing_raised do
46
+ HaveInstanceMethods::Matcher.new(arg)
47
+ end
48
+ end
49
+ end
50
+
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)
66
+ end
67
+ end
68
+ end
69
+
70
+
71
+
72
+ class ClassMethodsMatcherTest < Test::Unit::TestCase
73
+ include TestBelt
74
+
75
+ context "the HaveClassMethods matcher"
76
+
77
+ should "take one string/symbol method argument" do
78
+ [nil, 12, Object, [], {}].each do |arg|
79
+ assert_raises ArgumentError do
80
+ HaveClassMethods::Matcher.new(arg)
81
+ end
82
+ end
83
+ ['name', :name].each do |arg|
84
+ assert_nothing_raised do
85
+ HaveClassMethods::Matcher.new(arg)
86
+ end
87
+ end
88
+ end
89
+
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)
103
+ end
104
+ end
105
+ end
106
+
107
+
108
+
109
+ class HaveFilesMatcherTest < Test::Unit::TestCase
110
+ include TestBelt
111
+
112
+ context "the HaveFiles matcher"
113
+
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"
130
+ end
131
+ end
132
+
133
+
134
+
135
+ end
@@ -3,26 +3,17 @@ require 'lib/test_belt/rake_tasks'
3
3
 
4
4
  module TestBelt
5
5
  class RakeTasksTest < Test::Unit::TestCase
6
+ include TestBelt
6
7
 
7
- context "TestBelt Rake Tasks" do
8
+ context "TestBelt Rake Tasks"
9
+ subject { RakeTasks::TestTask.new }
8
10
 
9
- context "TestTask" do
10
- subject { RakeTasks::TestTask.new }
11
-
12
- should_have_accessors :name, :description, :test_files
13
- should_have_instance_method :to_task
14
-
15
- context "with test files" do
16
- setup do
17
- subject.test_files = ["file1.rb", "file2.rb"]
18
- end
19
-
20
- should "return a list of it's test_files" do
21
- assert_equal "\"file1.rb\" \"file2.rb\"", subject.file_list
22
- end
23
- end
24
- end
11
+ should have_accessors :name, :description, :test_files
12
+ should have_instance_method :to_task
25
13
 
14
+ should "return a list of it's test_files" do
15
+ subject.test_files = ["file1.rb", "file2.rb"]
16
+ assert_equal "\"file1.rb\" \"file2.rb\"", subject.file_list
26
17
  end
27
18
 
28
19
  end
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
5
- prerelease: false
4
+ hash: 23
5
+ prerelease:
6
6
  segments:
7
- - 0
8
- - 2
9
7
  - 1
10
- version: 0.2.1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kelly D. Redding
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-02 00:00:00 -06:00
19
- default_executable:
18
+ date: 2011-05-13 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: bundler
@@ -92,32 +91,38 @@ extra_rdoc_files: []
92
91
  files:
93
92
  - .gitignore
94
93
  - Gemfile
94
+ - Gemfile.lock
95
95
  - README.rdoc
96
96
  - Rakefile
97
97
  - lib/test_belt.rb
98
+ - lib/test_belt/callbacks.rb
99
+ - lib/test_belt/callbacks/case.rb
100
+ - lib/test_belt/callbacks/suite.rb
101
+ - lib/test_belt/callbacks/test.rb
102
+ - lib/test_belt/context.rb
103
+ - lib/test_belt/default_test.rb
98
104
  - lib/test_belt/helper.rb
105
+ - lib/test_belt/matchers.rb
106
+ - lib/test_belt/matchers/base.rb
107
+ - lib/test_belt/matchers/have_accessors.rb
108
+ - lib/test_belt/matchers/have_class_methods.rb
109
+ - lib/test_belt/matchers/have_files.rb
110
+ - lib/test_belt/matchers/have_instance_methods.rb
111
+ - lib/test_belt/matchers/have_readers.rb
112
+ - lib/test_belt/matchers/have_writers.rb
99
113
  - lib/test_belt/rake_tasks.rb
100
- - lib/test_belt/shoulda_macros.rb
101
- - lib/test_belt/shoulda_macros/classes.rb
102
- - lib/test_belt/shoulda_macros/context.rb
103
- - lib/test_belt/shoulda_macros/files.rb
104
- - lib/test_belt/test_unit.rb
105
- - lib/test_belt/test_unit/context.rb
106
- - lib/test_belt/test_unit/runner.rb
107
- - lib/test_belt/test_unit/test_case.rb
114
+ - lib/test_belt/should.rb
115
+ - lib/test_belt/skip.rb
116
+ - lib/test_belt/subject.rb
108
117
  - lib/test_belt/version.rb
109
118
  - test-belt.gemspec
119
+ - test/callbacks_test.rb
110
120
  - test/env.rb
111
- - test/fixtures/shoulda_macros/thing.rb
121
+ - test/fixtures/thing.rb
112
122
  - test/helper.rb
123
+ - test/helpers_test.rb
124
+ - test/matchers_test.rb
113
125
  - test/rake_tasks_test.rb
114
- - test/shoulda_macros/classes_test.rb
115
- - test/shoulda_macros/context_test.rb
116
- - test/shoulda_macros/files_test.rb
117
- - test/test_unit/context_test.rb
118
- - test/test_unit/runner_test.rb
119
- - test/test_unit/test_case_test.rb
120
- has_rdoc: true
121
126
  homepage: http://github.com/kelredd/test-belt
122
127
  licenses: []
123
128
 
@@ -147,18 +152,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
152
  requirements: []
148
153
 
149
154
  rubyforge_project:
150
- rubygems_version: 1.3.7
155
+ rubygems_version: 1.7.2
151
156
  signing_key:
152
157
  specification_version: 3
153
158
  summary: A gem for using testing tools I like - my Ruby testing toolbelt.
154
159
  test_files:
160
+ - test/callbacks_test.rb
155
161
  - test/env.rb
156
- - test/fixtures/shoulda_macros/thing.rb
162
+ - test/fixtures/thing.rb
157
163
  - test/helper.rb
164
+ - test/helpers_test.rb
165
+ - test/matchers_test.rb
158
166
  - test/rake_tasks_test.rb
159
- - test/shoulda_macros/classes_test.rb
160
- - test/shoulda_macros/context_test.rb
161
- - test/shoulda_macros/files_test.rb
162
- - test/test_unit/context_test.rb
163
- - test/test_unit/runner_test.rb
164
- - test/test_unit/test_case_test.rb