baretest 0.1.0 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. data/LICENSE.txt +52 -0
  2. data/MANIFEST.txt +50 -31
  3. data/README.rdoc +260 -0
  4. data/bin/baretest +82 -24
  5. data/doc/baretest.rdoc +98 -0
  6. data/doc/mocking_stubbing_test_doubles.rdoc +5 -0
  7. data/doc/quickref.rdoc +261 -0
  8. data/doc/writing_tests.rdoc +148 -0
  9. data/examples/test.rake +58 -30
  10. data/examples/tests/irb_mode/failures.rb +26 -0
  11. data/examples/tests/mock_developer/test/helper/mocks.rb +0 -0
  12. data/examples/tests/mock_developer/test/setup.rb +57 -0
  13. data/examples/tests/mock_developer/test/suite/mock_demo.rb +19 -0
  14. data/examples/tests/overview/test.rb +89 -0
  15. data/examples/tests/variations/variations_01.rb +14 -0
  16. data/examples/tests/variations/variations_02.rb +19 -0
  17. data/examples/tests/variations/variations_03.rb +19 -0
  18. data/lib/baretest/assertion/context.rb +20 -0
  19. data/lib/baretest/assertion/failure.rb +22 -0
  20. data/lib/baretest/assertion/skip.rb +21 -0
  21. data/lib/{test → baretest}/assertion/support.rb +174 -39
  22. data/lib/baretest/assertion.rb +182 -0
  23. data/lib/baretest/irb_mode.rb +263 -0
  24. data/lib/{test/assertion/failure.rb → baretest/layout.rb} +6 -5
  25. data/lib/baretest/mocha.rb +18 -0
  26. data/lib/baretest/run/cli.rb +104 -0
  27. data/lib/{test → baretest}/run/errors.rb +12 -7
  28. data/lib/{test → baretest}/run/minimal.rb +8 -3
  29. data/lib/baretest/run/profile.rb +151 -0
  30. data/lib/{test → baretest}/run/spec.rb +10 -4
  31. data/lib/baretest/run/tap.rb +44 -0
  32. data/lib/baretest/run/xml.rb +80 -0
  33. data/lib/{test → baretest}/run.rb +31 -18
  34. data/lib/baretest/setup.rb +15 -0
  35. data/lib/baretest/skipped/assertion.rb +20 -0
  36. data/lib/baretest/skipped/suite.rb +49 -0
  37. data/lib/baretest/skipped.rb +15 -0
  38. data/lib/baretest/suite.rb +234 -0
  39. data/lib/baretest/utilities.rb +43 -0
  40. data/lib/{test → baretest}/version.rb +12 -3
  41. data/lib/baretest.rb +112 -0
  42. data/test/external/bootstraptest.rb +1 -1
  43. data/test/setup.rb +1 -1
  44. data/test/{lib/test → suite/lib/baretest}/assertion/support.rb +78 -24
  45. data/test/suite/lib/baretest/assertion.rb +192 -0
  46. data/test/{lib/test → suite/lib/baretest}/irb_mode.rb +0 -0
  47. data/test/{lib/test → suite/lib/baretest}/run/cli.rb +0 -0
  48. data/test/{lib/test → suite/lib/baretest}/run/errors.rb +0 -0
  49. data/test/{lib/test → suite/lib/baretest}/run/interactive.rb +0 -0
  50. data/test/{lib/test → suite/lib/baretest}/run/spec.rb +0 -0
  51. data/test/{lib/test → suite/lib/baretest}/run/tap.rb +0 -0
  52. data/test/{lib/test → suite/lib/baretest}/run/xml.rb +0 -0
  53. data/test/{lib/test → suite/lib/baretest}/run.rb +63 -61
  54. data/test/{lib/test → suite/lib/baretest}/suite.rb +77 -54
  55. data/test/{lib/test.rb → suite/lib/baretest.rb} +37 -37
  56. metadata +61 -40
  57. data/README.markdown +0 -229
  58. data/examples/test.rb +0 -93
  59. data/lib/test/assertion.rb +0 -117
  60. data/lib/test/debug.rb +0 -34
  61. data/lib/test/irb_mode.rb +0 -104
  62. data/lib/test/run/cli.rb +0 -79
  63. data/lib/test/run/interactive.rb +0 -60
  64. data/lib/test/run/tap.rb +0 -32
  65. data/lib/test/run/xml.rb +0 -56
  66. data/lib/test/suite.rb +0 -95
  67. data/lib/test.rb +0 -118
  68. data/test/lib/test/assertion.rb +0 -142
  69. data/test/lib/test/debug.rb +0 -63
@@ -6,36 +6,36 @@
6
6
 
7
7
 
8
8
 
9
- Test.define "Test" do
9
+ BareTest.suite "BareTest" do
10
10
  suite "::extender" do
11
11
  assert "Should return an Array" do
12
- kind_of(Array, Test.extender)
12
+ kind_of(Array, ::BareTest.extender)
13
13
  end
14
14
  end
15
15
 
16
16
  suite "::format" do
17
17
  assert "Should return a Hash" do
18
- kind_of(Hash, Test.format)
18
+ kind_of(Hash, ::BareTest.format)
19
19
  end
20
20
  end
21
21
 
22
22
  suite "::toplevel_suite" do
23
- assert "Should return an instance of Test::Suite" do
24
- kind_of(::Test::Suite, ::Test.toplevel_suite)
23
+ assert "Should return an instance of BareTest::Suite" do
24
+ kind_of(::BareTest::Suite, ::BareTest.toplevel_suite)
25
25
  end
26
26
 
27
- assert "Should be used by Test::define" do
28
- test = ::Test.clone # avoid interfering with the current run
27
+ assert "Should be used by BareTest::suite" do
28
+ test = ::BareTest.clone # avoid interfering with the current run
29
29
  test.init
30
30
  suites_before = test.toplevel_suite.suites.size
31
- test.define "A new suite" do end
31
+ test.suite "A new suite" do end
32
32
  suites_after = test.toplevel_suite.suites.size
33
33
 
34
34
  equal(suites_before+1, suites_after)
35
35
  end
36
36
 
37
- assert "Should be used by Test::run_if_mainfile" do
38
- test = ::Test.clone # avoid interfering with the current run
37
+ assert "Should be used by BareTest::run_if_mainfile" do
38
+ test = ::BareTest.clone # avoid interfering with the current run
39
39
  test.init
40
40
  suites_before = test.toplevel_suite.suites.size
41
41
  test.run_if_mainfile "A new suite" do end
@@ -44,23 +44,23 @@ Test.define "Test" do
44
44
  equal(suites_before+1, suites_after)
45
45
  end
46
46
 
47
- assert "Should be run by Test::run" do
47
+ assert "Should be run by BareTest::run" do
48
48
  this = self # needed because touch is called in the block of another assertion, so otherwise it'd be local to that assertion
49
- test = ::Test.clone # avoid interfering with the current run
49
+ test = ::BareTest.clone # avoid interfering with the current run
50
50
  test.init
51
- test.define "A new suite" do assert do this.touch(:assertion_executed) end end
51
+ test.suite "A new suite" do assert do this.touch(:assertion_executed) end end
52
52
  test.run
53
53
 
54
54
  touched(:assertion_executed)
55
55
  end
56
56
  end
57
57
 
58
- suite "::define" do
59
- assert "Should add the contained suites and asserts to Test::toplevel_suite" do
60
- test = ::Test.clone # avoid interfering with the current run
58
+ suite "::suite" do
59
+ assert "Should add the contained suites and asserts to BareTest::toplevel_suite" do
60
+ test = ::BareTest.clone # avoid interfering with the current run
61
61
  test.init
62
62
  suites_before = test.toplevel_suite.suites.size
63
- test.define "A new suite" do end
63
+ test.suite "A new suite" do end
64
64
  suites_after = test.toplevel_suite.suites.size
65
65
 
66
66
  equal(suites_before+1, suites_after)
@@ -71,14 +71,14 @@ Test.define "Test" do
71
71
  setup do
72
72
  ENV['FORMAT'] = 'minimal'
73
73
  @ruby = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
74
- @test_path = Shellwords.escape(File.expand_path("#{__FILE__}/../../external/bootstraptest.rb"))
75
- @wrap_path = Shellwords.escape(File.expand_path("#{__FILE__}/../../external/bootstrapwrap.rb"))
76
- @inc_path = Shellwords.escape(File.dirname(Test.required_file))
74
+ @test_path = Shellwords.escape(File.expand_path("#{__FILE__}/../../../external/bootstraptest.rb"))
75
+ @wrap_path = Shellwords.escape(File.expand_path("#{__FILE__}/../../../external/bootstrapwrap.rb"))
76
+ @inc_path = Shellwords.escape(File.dirname(BareTest.required_file))
77
77
  end
78
78
 
79
79
  suite "File is the program" do
80
80
  assert "Should run the suite" do
81
- IO.popen("#{@ruby} -I#{@inc_path} -rtest #{@test_path}") { |sio|
81
+ IO.popen("#{@ruby} -I#{@inc_path} -rbaretest #{@test_path}") { |sio|
82
82
  sio.read
83
83
  } =~ /\ATests: 1\nSuccess: 1\nPending: 0\nFailures: 0\nErrors: 0\nTime: [^\n]+\nStatus: success\n\z/
84
84
  end
@@ -86,7 +86,7 @@ Test.define "Test" do
86
86
 
87
87
  suite "File is not the program" do
88
88
  assert "Should not run the suite if the file is not the program" do
89
- IO.popen("#{@ruby} -I#{@inc_path} -rtest #{@wrap_path}") { |sio|
89
+ IO.popen("#{@ruby} -I#{@inc_path} -rbaretest #{@wrap_path}") { |sio|
90
90
  sio.read
91
91
  } =~ /\ADone\n\z/
92
92
  end
@@ -94,11 +94,11 @@ Test.define "Test" do
94
94
  end
95
95
 
96
96
  suite "::run" do
97
- assert "Should run Test's toplevel suite" do
97
+ assert "Should run BareTest's toplevel suite" do
98
98
  this = self # needed because touch is called in the block of another assertion, so otherwise it'd be local to that assertion
99
- test = ::Test.clone # avoid interfering with the current run
99
+ test = ::BareTest.clone # avoid interfering with the current run
100
100
  test.init
101
- test.define "A new suite" do assert do this.touch(:assertion_executed) end end
101
+ test.suite "A new suite" do assert do this.touch(:assertion_executed) end end
102
102
  test.run
103
103
 
104
104
  touched(:assertion_executed)
@@ -108,10 +108,10 @@ Test.define "Test" do
108
108
  suite "Skipped" do
109
109
  suite "Suite" do
110
110
  setup do
111
- parent = ::Test::Suite.new
111
+ parent = ::BareTest::Suite.new
112
112
  parent.setup do end
113
113
  parent.teardown do end
114
- @suite = ::Test::Skipped::Suite.new("None", parent)
114
+ @suite = ::BareTest::Skipped::Suite.new("None", parent)
115
115
  @suite.setup do end
116
116
  @suite.teardown do end
117
117
  end
@@ -144,36 +144,36 @@ Test.define "Test" do
144
144
  assert "Should add new skipped assertions to a suite." do
145
145
  equal(
146
146
  :expected => 0,
147
- :actual => @suite.tests.size,
147
+ :actual => @suite.assertions.size,
148
148
  :message => "number of defined tests before adding any"
149
149
  )
150
150
 
151
151
  @suite.assert "a"
152
152
  equal(
153
153
  :expected => 1,
154
- :actual => @suite.tests.size,
154
+ :actual => @suite.skipped.size,
155
155
  :message => "number of defined tests after adding one"
156
156
  )
157
157
 
158
158
  @suite.assert "b"
159
159
  equal(
160
160
  :expected => 2,
161
- :actual => @suite.tests.size,
161
+ :actual => @suite.skipped.size,
162
162
  :message => "number of defined tests after adding two"
163
163
  )
164
164
 
165
165
  equal_unordered(
166
166
  :expected => ['a', 'b'],
167
- :actual => @suite.tests.map { |child| child.description },
167
+ :actual => @suite.skipped.map { |child| child.description },
168
168
  :message => "the descriptions"
169
169
  )
170
170
 
171
- @suite.tests.all? { |test| kind_of(::Test::Skipped::Assertion, test) }
171
+ @suite.skipped.all? { |test| kind_of(::BareTest::Skipped::Assertion, test) }
172
172
  end
173
173
 
174
174
  assert "Added tests should have the receiving suite as suite." do
175
175
  @suite.assert "a"
176
- assertion = @suite.tests.first
176
+ assertion = @suite.skipped.first
177
177
 
178
178
  same(
179
179
  :expected => @suite,
@@ -188,7 +188,7 @@ Test.define "Test" do
188
188
  suite "#execute" do
189
189
  suite "Given a test that succeeds" do
190
190
  assert "Should have status :skipped" do
191
- assertion = ::Test::Skipped::Assertion.new(nil, "") do true end
191
+ assertion = ::BareTest::Skipped::Assertion.new(nil, "") do true end
192
192
  assertion.execute
193
193
 
194
194
  equal(:skipped, assertion.status)
@@ -197,7 +197,7 @@ Test.define "Test" do
197
197
 
198
198
  suite "Given a test that is pending" do
199
199
  assert "Should have status :skipped" do
200
- assertion = ::Test::Skipped::Assertion.new(nil, "")
200
+ assertion = ::BareTest::Skipped::Assertion.new(nil, "")
201
201
  assertion.execute
202
202
 
203
203
  equal(:skipped, assertion.status)
@@ -206,7 +206,7 @@ Test.define "Test" do
206
206
 
207
207
  suite "Given a test that fails" do
208
208
  assert "Should have status :skipped" do
209
- assertion = ::Test::Skipped::Assertion.new(nil, "") do false end
209
+ assertion = ::BareTest::Skipped::Assertion.new(nil, "") do false end
210
210
  assertion.execute
211
211
 
212
212
  equal(:skipped, assertion.status)
@@ -215,7 +215,7 @@ Test.define "Test" do
215
215
 
216
216
  suite "Given a test that errors" do
217
217
  assert "Should have status :skipped" do
218
- assertion = ::Test::Skipped::Assertion.new(nil, "") do raise end
218
+ assertion = ::BareTest::Skipped::Assertion.new(nil, "") do raise end
219
219
  assertion.execute
220
220
 
221
221
  equal(:skipped, assertion.status)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baretest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Rusterholz
@@ -9,59 +9,80 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-16 00:00:00 +02:00
12
+ date: 2009-11-27 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
- description: "Baretest is a Testframework that tries to stay out of your way, but support you when you want it. In order to do so it has a load of features:"
16
+ description: |-
17
+ Baretest is a Testframework that tries to stay out of your way, but support
18
+ you when you want it. In order to do so it has a load of features:
17
19
  email: stefan.rusterholz@gmail.com
18
- executables: []
19
-
20
+ executables:
21
+ - baretest
20
22
  extensions: []
21
23
 
22
24
  extra_rdoc_files: []
23
25
 
24
26
  files:
27
+ - LICENSE.txt
25
28
  - MANIFEST.txt
26
- - README.markdown
29
+ - README.rdoc
27
30
  - bin/baretest
31
+ - doc/baretest.rdoc
32
+ - doc/mocking_stubbing_test_doubles.rdoc
33
+ - doc/quickref.rdoc
34
+ - doc/writing_tests.rdoc
35
+ - examples/tests/irb_mode/failures.rb
36
+ - examples/tests/mock_developer/test/helper/mocks.rb
37
+ - examples/tests/mock_developer/test/setup.rb
38
+ - examples/tests/mock_developer/test/suite/mock_demo.rb
39
+ - examples/tests/overview/test.rb
40
+ - examples/tests/variations/variations_01.rb
41
+ - examples/tests/variations/variations_02.rb
42
+ - examples/tests/variations/variations_03.rb
28
43
  - examples/test.rake
29
- - examples/test.rb
30
- - lib/test.rb
31
- - lib/test/assertion.rb
32
- - lib/test/assertion/failure.rb
33
- - lib/test/assertion/support.rb
34
- - lib/test/debug.rb
35
- - lib/test/irb_mode.rb
36
- - lib/test/run.rb
37
- - lib/test/run/cli.rb
38
- - lib/test/run/errors.rb
39
- - lib/test/run/interactive.rb
40
- - lib/test/run/minimal.rb
41
- - lib/test/run/spec.rb
42
- - lib/test/run/tap.rb
43
- - lib/test/run/xml.rb
44
- - lib/test/suite.rb
45
- - lib/test/version.rb
44
+ - lib/baretest.rb
45
+ - lib/baretest/assertion.rb
46
+ - lib/baretest/assertion/context.rb
47
+ - lib/baretest/assertion/failure.rb
48
+ - lib/baretest/assertion/skip.rb
49
+ - lib/baretest/assertion/support.rb
50
+ - lib/baretest/irb_mode.rb
51
+ - lib/baretest/layout.rb
52
+ - lib/baretest/mocha.rb
53
+ - lib/baretest/run.rb
54
+ - lib/baretest/run/cli.rb
55
+ - lib/baretest/run/errors.rb
56
+ - lib/baretest/run/minimal.rb
57
+ - lib/baretest/run/profile.rb
58
+ - lib/baretest/run/spec.rb
59
+ - lib/baretest/run/tap.rb
60
+ - lib/baretest/run/xml.rb
61
+ - lib/baretest/setup.rb
62
+ - lib/baretest/skipped.rb
63
+ - lib/baretest/skipped/assertion.rb
64
+ - lib/baretest/skipped/suite.rb
65
+ - lib/baretest/suite.rb
66
+ - lib/baretest/utilities.rb
67
+ - lib/baretest/version.rb
46
68
  - test/external/bootstraptest.rb
47
69
  - test/external/bootstrapwrap.rb
48
70
  - test/helper/mocks.rb
49
- - test/lib/test.rb
50
- - test/lib/test/assertion.rb
51
- - test/lib/test/assertion/support.rb
52
- - test/lib/test/debug.rb
53
- - test/lib/test/irb_mode.rb
54
- - test/lib/test/run.rb
55
- - test/lib/test/run/cli.rb
56
- - test/lib/test/run/errors.rb
57
- - test/lib/test/run/interactive.rb
58
- - test/lib/test/run/spec.rb
59
- - test/lib/test/run/tap.rb
60
- - test/lib/test/run/xml.rb
61
- - test/lib/test/suite.rb
62
71
  - test/setup.rb
72
+ - test/suite/lib/baretest.rb
73
+ - test/suite/lib/baretest/assertion.rb
74
+ - test/suite/lib/baretest/assertion/support.rb
75
+ - test/suite/lib/baretest/irb_mode.rb
76
+ - test/suite/lib/baretest/run.rb
77
+ - test/suite/lib/baretest/run/cli.rb
78
+ - test/suite/lib/baretest/run/errors.rb
79
+ - test/suite/lib/baretest/run/interactive.rb
80
+ - test/suite/lib/baretest/run/spec.rb
81
+ - test/suite/lib/baretest/run/tap.rb
82
+ - test/suite/lib/baretest/run/xml.rb
83
+ - test/suite/lib/baretest/suite.rb
63
84
  has_rdoc: true
64
- homepage: http://
85
+ homepage: http://baretest.rubyforge.org
65
86
  licenses: []
66
87
 
67
88
  post_install_message:
@@ -73,7 +94,7 @@ rdoc_options:
73
94
  - --tab-width
74
95
  - "2"
75
96
  - -t
76
- - baretest-#<Proc:0x00539b20@/Users/Shared/Development/Gems/baretest/rake/lib/silverplatter/project/bonesplitter.rb:60> Documentation
97
+ - baretest-0.2.3 Documentation
77
98
  require_paths:
78
99
  - lib
79
100
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -91,9 +112,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
112
  requirements: []
92
113
 
93
114
  rubyforge_project: baretest
94
- rubygems_version: 1.3.3
115
+ rubygems_version: 1.3.5
95
116
  signing_key:
96
117
  specification_version: 3
97
- summary: "A minimal Testframework. Three methods to use it, Twenty to master it, about hundred lines of code1. Bare Test, try it and you\xE2\x80\x99ll love it."
118
+ summary: "A testframework that doesn\xE2\x80\x99t stand in your way or forces you to learn a new language. Two methods is all that is required to know."
98
119
  test_files: []
99
120
 
data/README.markdown DELETED
@@ -1,229 +0,0 @@
1
- Bare Test
2
- =========
3
-
4
-
5
-
6
- Summary
7
- -------
8
-
9
- A minimal Testframework.
10
- Three methods to use it, Twenty to master it, about hundred lines of code[1].
11
- Bare Test, try it and you'll love it.
12
-
13
-
14
-
15
- Description
16
- -----------
17
-
18
- Baretest is a Testframework that tries to stay out of your way, but support you when you want it.
19
- In order to do so it has a load of features:
20
-
21
- * Strightforward and terse assertions (just a block whose return value defines
22
- success/failure)
23
- * Easy grouping of assertions into suites
24
- * BDD style specifications/test descriptions (NOT code), also extractable
25
- * Uncomplicated dependency testing and skipping
26
- * Helpers to deal painlessly with raising, throwing, float imprecision,
27
- unordered collections etc.
28
- * Ships with colored Shell formatter, Diagnostic-, Interactive-, XML- and TAP
29
- formatter
30
- * Interactive formatter - drops you into an irb session within failed assertion
31
- with all setup methods executed, so you can inspect interactively why it
32
- failed.
33
- * Trivial to add new formatters (the standard formatters are only roughly 20-50
34
- lines of code each)
35
- * Teardown and Setup for suites
36
- * Callbacks to integrate mock libraries
37
- * API to use it from code, such as rake tasks (comes with an example rake-task)
38
- * baretest executable to run tests on multiple files at once
39
- * Diagnostic assertion helpers (e.g. same(:a, :b) will give you 'Expected
40
- :a but got :b' as diagnostic)
41
-
42
-
43
-
44
- Quick Try
45
- ---------
46
-
47
- 1. Download from github and unpack (or clone)
48
- 2. Change into the baretest directory: `cd the/baretest/directory`
49
- 3. Run the examples: `./bin/baretest examples/test.rb`
50
-
51
- That's it. Alternatively you can run baretests own tests, and play with formatters:
52
- `./bin/baretest -f tap`
53
-
54
- Unfortunately the installer and gem installer aren't ready yet.
55
-
56
-
57
-
58
- Executable
59
- ----------
60
-
61
- Usage: baretest [options] [glob, ...]
62
- Glob defaults to 'test/**/*.rb'
63
- Providing a directory as glob is equivalent to dir/**/*.rb
64
- Options:
65
- -f, --format FORMAT use FORMAT for output
66
- -F, --formats show available formats
67
- -d, --debug set debugging flags (set $DEBUG to true)
68
- -i, --interactive drop into IRB on error or failure
69
- -s, --setup FILE specify setup file
70
- -v, --version print the version and exit
71
- -w, --warn turn warnings on for your script
72
-
73
-
74
-
75
- Planned Features
76
- ----------------
77
-
78
- * --fail-all flag, to test/review diagnostics of tests
79
- * Word-wrapping for CLI runner
80
- * Flags for color and verbose (\[no-]color and \[no-]verbose) for the executable
81
- * Passing on flags/options for formatters
82
- * Alternative CLI runner with status implicit via colored/bg-colored descriptions
83
- * Alternative CLI runner which prints the name of the test prior the label and rewrites
84
- the line when the test has executed to add status & coloring.
85
- * Simple stubbing with automatic cleanup at teardown. Example:
86
-
87
- assert "Should require a single file listed in :requires option." do |a|
88
- file = 'foo/bar'
89
- stub(Kernel, :require) do |file, *args| a.touch(file) end
90
- ::Test::Suite.create(nil, nil, :requires => file)
91
-
92
- touched file
93
- end
94
-
95
- * Inline tests via Module#describe (basically the same as Test::Suite#suite)
96
- * YARD code to extract the specifications without running the code
97
- * A redmine plugin
98
-
99
-
100
-
101
- Rejected Features
102
- -----------------
103
-
104
- * Currently none
105
-
106
-
107
- A Bit of Background
108
- -------------------
109
-
110
- Originally, bare-test started out as a project for shits & giggles on the flight
111
- back from vegas (railsconf09), to prove that it is possible to have a fully
112
- fledged test-framework in under 100 lines of source-code.
113
- Later I realized that this project could become more. For one it was (still is)
114
- dead simple to add another formatter, it is just as dead simple to embedd it
115
- in code.
116
- The principles are trivial to understand, embrace and extend.
117
- Upon that it dawned me, that the project was viable and I began adding features
118
- not found in other projects.
119
-
120
-
121
-
122
- Example Testsuite
123
- -----------------
124
-
125
- From examples/test.rb:
126
-
127
- Test.run_if_mainfile do
128
- # assertions and refutations can be grouped in suites. They will share
129
- # setup and teardown
130
- # they don't have to be in suites, though
131
- suite "Success" do
132
- assert "An assertion returning a trueish value (non nil/false) is a success" do
133
- true
134
- end
135
- end
136
-
137
- suite "Failure" do
138
- assert "An assertion returning a falsish value (nil/false) is a failure" do
139
- false
140
- end
141
- end
142
-
143
- suite "Pending" do
144
- assert "An assertion without a block is pending"
145
- end
146
-
147
- suite "Error" do
148
- assert "Uncaught exceptions in an assertion are an error" do
149
- raise "Error!"
150
- end
151
- end
152
-
153
- suite "Special assertions" do
154
- assert "Assert a block to raise" do
155
- raises do
156
- sleep(rand()/3+0.05)
157
- raise "If this raises then the assertion is a success"
158
- end
159
- end
160
-
161
- assert "Assert a float to be close to another" do
162
- a = 0.18 - 0.01
163
- b = 0.17
164
- within_delta a, b, 0.001
165
- end
166
-
167
- suite "Nested suite" do
168
- assert "Assert two randomly ordered arrays to contain the same values" do
169
- a = [*"A".."Z"] # an array with values from A to Z
170
- b = a.sort_by { rand }
171
- a.equal_unordered(b) # can be used with any Enumerable, uses hash-key identity
172
- end
173
- end
174
- end
175
-
176
- suite "Setup & Teardown" do
177
- setup do
178
- @foo = "foo"
179
- @bar = "bar"
180
- end
181
-
182
- assert "@foo should be set" do
183
- @foo == "foo"
184
- end
185
-
186
- suite "Nested suite" do
187
- setup do
188
- @bar = "inner bar"
189
- @baz = "baz"
190
- end
191
-
192
- assert "@foo is inherited" do
193
- @foo == "foo"
194
- end
195
-
196
- assert "@bar is overridden" do
197
- @bar == "inner bar"
198
- end
199
-
200
- assert "@baz is defined only for inner" do
201
- @baz == "baz"
202
- end
203
- end
204
-
205
- teardown do
206
- @foo = nil # not that it'd make much sense, just to demonstrate
207
- end
208
- end
209
-
210
- suite "Dependencies", :requires => ['foo', 'bar'] do
211
- assert "Will be skipped, due to unsatisfied dependencies" do
212
- raise "This code therefore will never be executed"
213
- end
214
- end
215
- end
216
-
217
-
218
-
219
- Known bugs
220
- ----------
221
-
222
- * touch/touched have to clean up after every Assertion#execute. Should use the mock hooks.
223
-
224
-
225
-
226
- Foot Notes
227
- ----------
228
- [1]: "" The abbreviated form without support code and output formatters.
229
- The normal code is expanded to more lines for readability.
data/examples/test.rb DELETED
@@ -1,93 +0,0 @@
1
- require 'test'
2
-
3
-
4
-
5
- Test.run_if_mainfile do
6
- # assertions and refutations can be grouped in suites. They will share
7
- # setup and teardown
8
- # they don't have to be in suites, though
9
- suite "Success" do
10
- assert "An assertion returning a trueish value (non nil/false) is a success" do
11
- true
12
- end
13
- end
14
-
15
- suite "Failure" do
16
- assert "An assertion returning a falsish value (nil/false) is a failure" do
17
- false
18
- end
19
- end
20
-
21
- suite "Pending" do
22
- assert "An assertion without a block is pending"
23
- end
24
-
25
- suite "Error" do
26
- assert "Uncaught exceptions in an assertion are an error" do
27
- raise "Error!"
28
- end
29
- end
30
-
31
- suite "Special assertions" do
32
- assert "Assert a block to raise" do
33
- raises do
34
- sleep(rand()/3+0.05)
35
- raise "If this raises then the assertion is a success"
36
- end
37
- end
38
-
39
- assert "Assert a float to be close to another" do
40
- a = 0.18 - 0.01
41
- b = 0.17
42
- within_delta a, b, 0.001
43
- end
44
-
45
- suite "Nested suite" do
46
- assert "Assert two randomly ordered arrays to contain the same values" do
47
- a = [*"A".."Z"] # an array with values from A to Z
48
- b = a.sort_by { rand }
49
- equal_unordered(a, b) # can be used with any Enumerable, uses hash-key identity
50
- end
51
- end
52
- end
53
-
54
- suite "Setup & Teardown" do
55
- setup do
56
- @foo = "foo"
57
- @bar = "bar"
58
- end
59
-
60
- assert "@foo should be set" do
61
- @foo == "foo"
62
- end
63
-
64
- suite "Nested suite" do
65
- setup do
66
- @bar = "inner bar"
67
- @baz = "baz"
68
- end
69
-
70
- assert "@foo is inherited" do
71
- @foo == "foo"
72
- end
73
-
74
- assert "@bar is overridden" do
75
- @bar == "inner bar"
76
- end
77
-
78
- assert "@baz is defined only for inner" do
79
- @baz == "baz"
80
- end
81
- end
82
-
83
- teardown do
84
- @foo = nil # not that it'd make much sense, just to demonstrate
85
- end
86
- end
87
-
88
- suite "Dependencies", :requires => ['foo', 'bar'] do
89
- assert "Will be skipped, due to unsatisfied dependencies" do
90
- failure "Why the heck do you have a 'foo/bar' file?"
91
- end
92
- end
93
- end