assert 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/.gitignore +5 -0
  2. data/Gemfile +6 -0
  3. data/Gemfile.lock +17 -0
  4. data/README.rdoc +77 -0
  5. data/Rakefile +7 -0
  6. data/assert.gemspec +21 -0
  7. data/examples/empty_test.rb +5 -0
  8. data/examples/results_test.rb +25 -0
  9. data/examples/single_test.rb +9 -0
  10. data/lib/assert.rb +8 -0
  11. data/lib/assert/assertions.rb +253 -0
  12. data/lib/assert/context.rb +196 -0
  13. data/lib/assert/options.rb +43 -0
  14. data/lib/assert/rake_tasks.rb +95 -0
  15. data/lib/assert/result.rb +164 -0
  16. data/lib/assert/result_set.rb +14 -0
  17. data/lib/assert/runner.rb +60 -0
  18. data/lib/assert/setup/autorun.rb +34 -0
  19. data/lib/assert/setup/helpers.rb +62 -0
  20. data/lib/assert/setup/suite.rb +12 -0
  21. data/lib/assert/setup/view.rb +11 -0
  22. data/lib/assert/suite.rb +128 -0
  23. data/lib/assert/test.rb +90 -0
  24. data/lib/assert/version.rb +3 -0
  25. data/lib/assert/view/base.rb +54 -0
  26. data/lib/assert/view/terminal.rb +138 -0
  27. data/test/assertions/assert_block_test.rb +39 -0
  28. data/test/assertions/assert_instance_of_test.rb +43 -0
  29. data/test/assertions/assert_kind_of_test.rb +43 -0
  30. data/test/assertions/assert_not_block_test.rb +39 -0
  31. data/test/assertions/assert_not_instance_of_test.rb +43 -0
  32. data/test/assertions/assert_not_kind_of_test.rb +43 -0
  33. data/test/assertions/assert_not_respond_to_test.rb +43 -0
  34. data/test/assertions/assert_nothing_raised_test.rb +46 -0
  35. data/test/assertions/assert_raises_test.rb +49 -0
  36. data/test/assertions/assert_respond_to_test.rb +43 -0
  37. data/test/assertions_test.rb +334 -0
  38. data/test/context/class_methods_test.rb +314 -0
  39. data/test/context_test.rb +288 -0
  40. data/test/fixtures/inherited_stuff.rb +36 -0
  41. data/test/fixtures/sample_context.rb +13 -0
  42. data/test/helper.rb +52 -0
  43. data/test/irb.rb +10 -0
  44. data/test/options_test.rb +78 -0
  45. data/test/result_set_test.rb +89 -0
  46. data/test/result_test.rb +255 -0
  47. data/test/runner_test.rb +33 -0
  48. data/test/suite_test.rb +200 -0
  49. data/test/test/running_test.rb +327 -0
  50. data/test/test_test.rb +184 -0
  51. data/test/view_test.rb +35 -0
  52. metadata +155 -0
@@ -0,0 +1,288 @@
1
+ require 'assert'
2
+
3
+ class Assert::Context::BasicTest < Assert::Context
4
+ desc "Assert context"
5
+ setup do
6
+ @test = Factory.test
7
+ @context_class = @test.context_class
8
+ @context = @context_class.new(@test)
9
+ end
10
+ subject{ @context }
11
+
12
+ INSTANCE_METHODS = [
13
+ :assert, :assert_not, :refute,
14
+ :skip, :pass, :fail, :flunk, :ignore,
15
+ :subject
16
+ ]
17
+ INSTANCE_METHODS.each do |method|
18
+ should "respond to the instance method ##{method}" do
19
+ assert_respond_to subject, method
20
+ end
21
+ end
22
+
23
+ teardown do
24
+ TEST_ASSERT_SUITE.clear
25
+ end
26
+
27
+
28
+
29
+ class SkipTest < BasicTest
30
+ desc "skip method"
31
+ setup do
32
+ @skip_msg = "I need to implement this in the future."
33
+ begin
34
+ @context.skip(@skip_msg)
35
+ rescue Exception => @exception
36
+ end
37
+ @result = Factory.skip_result("something", @exception)
38
+ end
39
+ subject{ @result }
40
+
41
+ should "raise a test skipped exception when called" do
42
+ assert_kind_of Assert::Result::TestSkipped, @exception
43
+ end
44
+ should "raise the exception with the message passed to it" do
45
+ assert_equal @skip_msg, @exception.message
46
+ end
47
+ should "set the message passed to it on the result" do
48
+ assert_equal @skip_msg, subject.message
49
+ end
50
+
51
+ end
52
+
53
+
54
+
55
+ class IgnoreTest < BasicTest
56
+ desc "ignore method"
57
+ setup do
58
+ @ignore_msg = "Ignore this for now, will do later."
59
+ @result = @context.ignore(@ignore_msg)
60
+ end
61
+ subject{ @result }
62
+
63
+ should "create an ignore result" do
64
+ assert_kind_of Assert::Result::Ignore, subject
65
+ end
66
+ should "set the messaged passed to it on the result" do
67
+ assert_equal @ignore_msg, subject.message
68
+ end
69
+
70
+ end
71
+
72
+
73
+
74
+ class PassTest < BasicTest
75
+ desc "pass method"
76
+ setup do
77
+ @pass_msg = "That's right, it works."
78
+ @result = @context.pass(@pass_msg)
79
+ end
80
+ subject{ @result }
81
+
82
+ should "create a pass result" do
83
+ assert_kind_of Assert::Result::Pass, subject
84
+ end
85
+ should "set the messaged passed to it on the result" do
86
+ assert_equal @pass_msg, subject.message
87
+ end
88
+
89
+ end
90
+
91
+
92
+
93
+ class FailTest < BasicTest
94
+ desc "fail method"
95
+ setup do
96
+ @result = @context.fail
97
+ end
98
+ subject{ @result }
99
+
100
+ should "create a fail result" do
101
+ assert_kind_of Assert::Result::Fail, subject
102
+ end
103
+ should "set the calling backtrace on the result" do
104
+ assert_kind_of Array, subject.backtrace
105
+ assert_match /assert\/test\/context_test\.rb/, subject.trace
106
+ end
107
+
108
+ class StringMessageTest < FailTest
109
+ desc "with a string message"
110
+ setup do
111
+ @fail_msg = "Didn't work"
112
+ @result = @context.fail(@fail_msg)
113
+ end
114
+
115
+ should "set the message passed to it on the result" do
116
+ assert_equal @fail_msg, subject.message
117
+ end
118
+
119
+ end
120
+
121
+ class ProcMessageTest < FailTest
122
+ desc "with a proc message"
123
+ setup do
124
+ @fail_msg = lambda{ "Still didn't work" }
125
+ @result = @context.fail(@fail_msg)
126
+ end
127
+
128
+ should "set the message passed to it on the result" do
129
+ assert_equal @fail_msg.call, subject.message
130
+ end
131
+
132
+ end
133
+
134
+ end
135
+
136
+
137
+
138
+ class FlunkTest < BasicTest
139
+ desc "flunk method"
140
+ setup do
141
+ @flunk_msg = "It flunked."
142
+ @result = @context.flunk(@flunk_msg)
143
+ end
144
+ subject{ @result }
145
+
146
+ should "create a fail result" do
147
+ assert_kind_of Assert::Result::Fail, subject
148
+ end
149
+ should "set the message passed to it on the result" do
150
+ assert_equal @flunk_msg, subject.message
151
+ end
152
+
153
+ end
154
+
155
+
156
+
157
+ class AssertTest < BasicTest
158
+ desc "assert method"
159
+ setup do
160
+ @fail_desc = "my fail desc"
161
+ @what_failed = "what failed"
162
+ end
163
+
164
+ class WithTruthyAssertionTest < AssertTest
165
+ desc "with a truthy assertion"
166
+ setup do
167
+ @result = @context.assert(true, @fail_desc, @what_failed)
168
+ end
169
+ subject{ @result }
170
+
171
+ should "return a pass result" do
172
+ assert_kind_of Assert::Result::Pass, subject
173
+ assert_nil subject.message
174
+ end
175
+
176
+ end
177
+
178
+ class WithFalseAssertionTest < AssertTest
179
+ desc "with a false assertion"
180
+ setup do
181
+ @result = @context.assert(false, @fail_desc, @what_failed)
182
+ end
183
+ subject{ @result }
184
+
185
+ should "return a fail result" do
186
+ assert_kind_of Assert::Result::Fail, subject
187
+ assert_equal "#{@what_failed}\n#{@fail_desc}", subject.message
188
+ end
189
+
190
+ end
191
+
192
+ # extras
193
+
194
+ should "return a pass result with a truthy (34) assertion" do
195
+ assert_kind_of Assert::Result::Pass, subject.assert(34)
196
+ end
197
+
198
+ should "return a fail result with a nil assertion" do
199
+ assert_kind_of Assert::Result::Fail, subject.assert(nil)
200
+ end
201
+
202
+ end
203
+
204
+
205
+
206
+ class AssertNotTest < BasicTest
207
+ desc "assert_not method"
208
+ setup do
209
+ @fail_desc = "my fail desc"
210
+ end
211
+
212
+ class WithTruthyAssertionTest < AssertNotTest
213
+ desc "with a truthy assertion"
214
+ setup do
215
+ @what_failed = "Failed assert_not: assertion was <true>."
216
+ @result = @context.assert_not(true, @fail_desc)
217
+ end
218
+ subject{ @result }
219
+
220
+ should "return a fail result" do
221
+ assert_kind_of Assert::Result::Fail, subject
222
+ assert_equal "#{@what_failed}\n#{@fail_desc}", subject.message
223
+ end
224
+
225
+ end
226
+
227
+ class WithFalseAssertionTest < AssertNotTest
228
+ desc "with a false assertion"
229
+ setup do
230
+ @result = @context.assert_not(false, @fail_desc)
231
+ end
232
+ subject{ @result }
233
+
234
+ should "return a pass result" do
235
+ assert_kind_of Assert::Result::Pass, subject
236
+ assert_nil subject.message
237
+ end
238
+
239
+ end
240
+
241
+ # extras
242
+
243
+ should "return a fail result with a truthy (34) assertion" do
244
+ assert_kind_of Assert::Result::Fail, subject.assert_not(34)
245
+ end
246
+
247
+ should "return a pass result with a nil assertion" do
248
+ assert_kind_of Assert::Result::Pass, subject.assert_not(nil)
249
+ end
250
+
251
+ end
252
+
253
+
254
+
255
+ class SubjectTest < BasicTest
256
+ desc "subject method"
257
+ setup do
258
+ expected = @expected = "amazing"
259
+ @context_class = Factory.context_class do
260
+ subject{ @something = expected }
261
+ end
262
+ @context = @context_class.new
263
+ @subject = @context.subject
264
+ end
265
+ subject{ @subject }
266
+
267
+ should "instance evaluate the block set with the class setup method" do
268
+ assert_equal @expected, subject
269
+ end
270
+
271
+ end
272
+
273
+
274
+
275
+ class InspectTest < BasicTest
276
+ desc "inspect method"
277
+ setup do
278
+ @expected = "#<#{@context.class}>"
279
+ @inspect = @context.inspect
280
+ end
281
+ subject{ @inspect }
282
+
283
+ should "just show the name of the class" do
284
+ assert_equal @expected, subject
285
+ end
286
+ end
287
+
288
+ end
@@ -0,0 +1,36 @@
1
+ module MixinStuff
2
+ def test_mixin_stuff
3
+ "from mixin"
4
+ end
5
+
6
+ def mixednottestmeth
7
+ "mixed in not test meth"
8
+ end
9
+ end
10
+
11
+ class SuperStuff
12
+ def superclass_stuff
13
+ "from superclass"
14
+ end
15
+
16
+ def other_stuff
17
+ "super not test meth"
18
+ end
19
+
20
+ end
21
+
22
+ class SubStuff
23
+ include MixinStuff
24
+
25
+ def test_subclass_stuff
26
+ "from subclass"
27
+ end
28
+
29
+ def nottestmeth
30
+ "not test meth"
31
+ end
32
+
33
+ def more_other_stuff
34
+ "more other stuff"
35
+ end
36
+ end
@@ -0,0 +1,13 @@
1
+ class SampleContext < Assert::Context
2
+
3
+ end
4
+
5
+ class TwoTests < SampleContext
6
+
7
+ def test_something
8
+ end
9
+
10
+ def test_something_else
11
+ end
12
+
13
+ end
@@ -0,0 +1,52 @@
1
+ # this file is automatically required in when you require 'test_belt'
2
+ # put test helpers here
3
+
4
+ require 'stringio'
5
+
6
+ # This is the suite intended to be used in the tests, this is seperate from Assert.suite which is
7
+ # the actual suite being used to run the tests, confused? Don't use Assert.suite in your tests,
8
+ # use TEST_ASSERT_SUITE
9
+ TEST_ASSERT_SUITE = Assert::Suite.new
10
+
11
+ # This is the test context intended to be used in the tests, and is also used in the context_class
12
+ # factory by default. This will ensure any contexts you define in your tests will not be shoved
13
+ # onto the the suite running the tests.
14
+ class TestContext < Assert::Context
15
+ def self.inherited(klass)
16
+ TEST_ASSERT_SUITE << klass
17
+ end
18
+ end
19
+
20
+ module Factory
21
+ class << self
22
+
23
+ # Generates an anonymous class inherited from whatever you pass or TextContext by default. This
24
+ # provides a common interface for all context classes to be generated in the tests.
25
+ def context_class(inherit_from = nil, &block)
26
+ inherit_from ||= TestContext
27
+ klass = Class.new(inherit_from, &block)
28
+ default = (const_name = "FactoryAssertContext").dup
29
+ while(Object.const_defined?(const_name)) do
30
+ const_name = "FactoryAssertContext#{rand(Time.now.to_i)}"
31
+ end
32
+ Object.const_set(const_name, klass)
33
+ klass
34
+ end
35
+
36
+ # Common interface for generating a new test, takes args and a block, will default everything
37
+ # if you need a no-op test.
38
+ def test(*args, &block)
39
+ name = (args[0] || "a test").to_s
40
+ context_class = args[1] || self.context_class
41
+ block ||= (args[2] || lambda{ })
42
+
43
+ Assert::Test.new(name, context_class, &block)
44
+ end
45
+
46
+ # Common interface for generating a new skip result
47
+ def skip_result(name, exception)
48
+ Assert::Result::Skip.new(name, exception)
49
+ end
50
+
51
+ end
52
+ end
@@ -0,0 +1,10 @@
1
+ require 'test_belt'
2
+
3
+ # this file is required in when the 'irb' rake test is run.
4
+ # b/c 'test_belt' is required above, lib and test dirs will
5
+ # be added to the LOAD_PATH and the test helper will be
6
+ # required in.
7
+
8
+ # put any IRB setup code here
9
+
10
+ require 'assert'
@@ -0,0 +1,78 @@
1
+ require 'assert'
2
+
3
+ require 'assert/options'
4
+
5
+ module Assert::Options
6
+
7
+ class BaseTest < Assert::Context
8
+ desc "user options class"
9
+ setup { @base = Assert::Options::Base.new }
10
+ subject { @base }
11
+
12
+ should "write single values by making a method call w/ a single arg" do
13
+ subject.a_value 1
14
+ assert_equal 1, subject.a_value
15
+ end
16
+
17
+ should "read values by making a method call w/ no args" do
18
+ assert_equal nil, subject.a_value
19
+ subject.a_value "blah"
20
+ assert_equal "blah", subject.a_value
21
+ end
22
+
23
+ should "write an array of values by making a method call w/ multiple args" do
24
+ subject.a_value [1,2,3]
25
+ subject.values 1,2,3
26
+ assert_equal subject.a_value, subject.values
27
+ end
28
+
29
+ should "write default values using the 'default_' prefix" do
30
+ assert_equal nil, subject.a_value
31
+ subject.default_a_value "def"
32
+ assert_equal "def", subject.default_a_value
33
+ assert_equal "def", subject.a_value
34
+ subject.a_value "changed"
35
+ assert_equal "def", subject.default_a_value
36
+ assert_equal "changed", subject.a_value
37
+ end
38
+
39
+ should "be provided for the terminal view" do
40
+ assert_respond_to Assert::View::Terminal, :options
41
+ assert_respond_to Assert::View::Terminal.new("suite", "io"), :options
42
+ end
43
+
44
+ end
45
+
46
+ class TerminalTest < BaseTest
47
+ desc "for the terminal view"
48
+ subject do
49
+ Assert::View::Terminal.options
50
+ end
51
+
52
+ should "be an Options::Base object" do
53
+ assert_kind_of Assert::Options::Base, Assert::View::Terminal.options
54
+ end
55
+
56
+ should "default the styled option" do
57
+ assert_equal false, subject.default_styled
58
+ end
59
+
60
+ should "default its result abbreviations" do
61
+ assert_equal '.', subject.default_passed_abbrev
62
+ assert_equal 'F', subject.default_failed_abbrev
63
+ assert_equal 'I', subject.default_ignored_abbrev
64
+ assert_equal 'S', subject.default_skipped_abbrev
65
+ assert_equal 'E', subject.default_errored_abbrev
66
+ end
67
+
68
+ should "default its result styles" do
69
+ assert_equal :green, subject.default_passed_styles
70
+ assert_equal [:red, :bold], subject.default_failed_styles
71
+ assert_equal :magenta, subject.default_ignored_styles
72
+ assert_equal :cyan, subject.default_skipped_styles
73
+ assert_equal [:yellow, :bold], subject.default_errored_styles
74
+ end
75
+
76
+ end
77
+
78
+ end