assert 1.1.0 → 2.0.0.rc.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/.assert.rb +3 -0
  2. data/README.md +182 -108
  3. data/Rakefile +0 -3
  4. data/bin/assert +1 -1
  5. data/lib/assert.rb +75 -4
  6. data/lib/assert/assert_runner.rb +76 -0
  7. data/lib/assert/cli.rb +25 -46
  8. data/lib/assert/context.rb +3 -3
  9. data/lib/assert/result.rb +65 -55
  10. data/lib/assert/runner.rb +19 -38
  11. data/lib/assert/suite.rb +0 -7
  12. data/lib/assert/test.rb +4 -16
  13. data/lib/assert/version.rb +1 -1
  14. data/lib/assert/view.rb +23 -0
  15. data/lib/assert/view/base.rb +10 -19
  16. data/lib/assert/view/default_view.rb +16 -11
  17. data/lib/assert/view/helpers/ansi_styles.rb +1 -1
  18. data/lib/assert/view/helpers/common.rb +37 -16
  19. data/test/assert_test.rb +29 -14
  20. data/test/context/class_methods_test.rb +2 -2
  21. data/test/context_test.rb +28 -50
  22. data/test/helper.rb +4 -2
  23. data/test/runner_test.rb +5 -4
  24. data/test/suite_test.rb +1 -1
  25. data/test/test_test.rb +8 -15
  26. data/test/view/base_tests.rb +20 -37
  27. metadata +17 -39
  28. data/lib/assert/autorun.rb +0 -37
  29. data/lib/assert/options.rb +0 -43
  30. data/lib/assert/rake_tasks.rb +0 -75
  31. data/lib/assert/rake_tasks/irb.rb +0 -33
  32. data/lib/assert/rake_tasks/scope.rb +0 -100
  33. data/lib/assert/rake_tasks/test_task.rb +0 -66
  34. data/lib/assert/result_set.rb +0 -17
  35. data/lib/assert/setup.rb +0 -3
  36. data/lib/assert/setup/all.rb +0 -5
  37. data/lib/assert/setup/helpers.rb +0 -72
  38. data/lib/assert/setup/options.rb +0 -6
  39. data/lib/assert/setup/runner.rb +0 -13
  40. data/lib/assert/setup/suite.rb +0 -13
  41. data/lib/assert/setup/view.rb +0 -39
  42. data/lib/assert/view/helpers/capture_output.rb +0 -23
  43. data/test/default_view_test.rb +0 -16
  44. data/test/irb.rb +0 -5
  45. data/test/options_test.rb +0 -40
  46. data/test/rake_tasks/irb_test.rb +0 -45
  47. data/test/rake_tasks/scope_test.rb +0 -63
  48. data/test/rake_tasks/test_task_test.rb +0 -80
  49. data/test/result_set_test.rb +0 -72
@@ -0,0 +1,3 @@
1
+ Assert.configure do |c|
2
+ # puts "Applying local settings..."
3
+ end
data/README.md CHANGED
@@ -1,7 +1,34 @@
1
- # The Assert testing framework
1
+ # The Assert Testing Framework
2
2
 
3
3
  Test::Unit style testing framework, just better than Test::Unit.
4
4
 
5
+ ## Usage
6
+
7
+ ```ruby
8
+ # in test/my_tests.rb
9
+
10
+ require 'assert'
11
+
12
+ class MyTests < Assert::Context
13
+
14
+ def test_something
15
+ assert_equal 1, 1
16
+ end
17
+
18
+ end
19
+ ```
20
+
21
+ ```sh
22
+ $ assert test/my_tests.rb
23
+ Loaded suite (1 test)
24
+ Running tests in random order, seeded with "33650"
25
+ .
26
+
27
+ 1 result: pass
28
+
29
+ (0.000199 seconds)
30
+ ```
31
+
5
32
  ## What Assert is
6
33
 
7
34
  * **Framework**: you define tests and the context they run in - Assert runs them. Everything is pure ruby so use any 3rd party testing tools you like. Create 3rd party tools that extend Assert behavior.
@@ -17,106 +44,170 @@ Test::Unit style testing framework, just better than Test::Unit.
17
44
 
18
45
  ## Description
19
46
 
20
- Assert is a Test::Unit style testing framework. This means you can write tests in Assert the same way you would with test-unit. In addition, Assert adds some helpers and syntax sugar to enhance the way tests are written - most taken from ideas in [Shoulda](https://github.com/thoughtbot/shoulda) and [Leftright](https://github.com/jordi/leftright/). Assert uses class-based contexts so if you want to nest your contexts, use good old inheritance.
47
+ Assert is a Test::Unit style testing framework. This means you can write tests in Assert the same way you would with test-unit.
21
48
 
22
- Assert is tested using itself. The tests are a pretty good place to look for examples and usage patterns.
49
+ In addition, Assert adds some helpers and syntax sugar to enhance the way tests are written. Most are taken from ideas in [Shoulda](https://github.com/thoughtbot/shoulda) and [Leftright](https://github.com/jordi/leftright/). Assert uses class-based contexts so if you want to nest your contexts, use inheritance.
23
50
 
24
- ## Installation
51
+ **Note**: Assert is tested using itself. The tests are a pretty good place to look for examples and usage patterns.
25
52
 
26
- ```
27
- $ gem install assert
53
+ ## CLI
54
+
55
+ ```sh
56
+ $ assert --help
28
57
  ```
29
58
 
30
- ## Usage
59
+ Assert ships with a CLI for running tests. Test files must end in `_tests.rb` (or `_test.rb`). The CLI globs any given file path(s), requires any test files, and runs the tests in them.
31
60
 
32
- ```ruby
33
- require 'assert'
61
+ As an example, say your test folder has a file structure like so:
34
62
 
35
- class MyTests < Assert::Context
63
+ ```
64
+ - test
65
+ | - basic_tests.rb
66
+ | - helper.rb
67
+ | - complex_tests.rb
68
+ | - complex
69
+ | | - fast_tests.rb
70
+ | | - slow_tests.rb
71
+ ```
36
72
 
37
- def test_something
38
- assert_equal 1, 1
39
- end
73
+ * `$ assert` - runs all tests ('./test' is used if no paths are given)
74
+ * `$ assert test/basic` - run all tests in basic_tests.rb
75
+ * `$ assert test/complex/fast_tests.rb` - runs all tests in fast_tests.rb
76
+ * `$ assert test/basic test/comp` - runs all tests in basic_tests.rb, complex_tests.rb, fast_tests.rb and slow_tests.rb
77
+
78
+ All you need to do is pass some sort of existing file path (hint: use tab-completion) and Assert will find any test files and run the tests in them.
79
+
80
+ ## Configuring Assert
40
81
 
82
+ ```ruby
83
+ Assert.configure do |config|
84
+ # set your config options here
41
85
  end
42
86
  ```
43
87
 
44
- ## Models
88
+ Assert uses a config pattern for specifying settings. Using this pattern, you can configure settings, extensions, custom views, etc. Settings can be configured in 4 different scopes and are applied in this order: User, Local, CLI, ENV.
45
89
 
46
- Assert models exist to define, collect, structure, and report on Assert test data.
90
+ ### User settings
47
91
 
48
- ### Suite
92
+ Assert will look for and require the file `$HOME/.assert/initializer.rb`. Use this file to specify user settings. User settings can be overridden by Local, CLI, and ENV settings.
49
93
 
50
- A `Suite` object is reponsible for collecting and structuring tests and defines the set of tests to run using the test `Runner`. Tests are grouped within the suite by their context. Suite provides access to the contexts, tests, and test results. In addition, the Suite model provides some stats (ie. run_time, runner_seed, etc...).
94
+ ### Local settings
51
95
 
52
- ### Runner
96
+ Assert will look for and require the file `./.assert.rb`. Use this file to specify project settings. Local settings can be overridden by CLI, and ENV settings.
53
97
 
54
- A `Runner` object is responsible for running a suite of tests and firing event callbacks to the `View`. Any runner object should take the test suite and view as arguments and should provide a 'run' method that runs the tests and renders the view.
98
+ To specify a custom local settings file path, use the `ASSERT_LOCALFILE` env var.
55
99
 
56
- ### Context
100
+ ### CLI settings
57
101
 
58
- A `Context` object is the scope that tests are run in. When tests are run, a new instance of the test context is created and the test code is evaluated within the scope of this context instance. Context provides methods for defining tests and test callbacks and for generating test results in running tests. Subclass context classes to achieve nested context behavior.
102
+ Assert accepts options from its CLI. Use these options to specify runtime settings. CLI settings can be overridden by ENV settings.
59
103
 
60
- ### Test
104
+ ### ENV settings
61
105
 
62
- A `Test` object defines the test code that needs to be run and the results generated by that test code. Tests are aware of their context and are responsible for running their code in context.
106
+ Assert uses ENV vars to drive certain settings. Use these vars to specify absolute runtime settings. ENV settings are always applied last and cannot be overridden.
63
107
 
64
- ### Result
108
+ ## Running Tests
65
109
 
66
- A `Result` object defines the data related to a test result. There are a few kinds of test results available:
110
+ Assert uses its [`Assert::Runner`](/lib/assert/runner.rb) to run tests. You can extend this default runner or use your own runner implementation. Specify it in your user/local settings:
67
111
 
68
- * `Pass`
69
- * `Fail`
70
- * `Error`
71
- * `Skip`
72
- * `Ignore`
112
+ ```ruby
113
+ require 'my_awesome_runner_class'
73
114
 
74
- Tests produce results as they are executed. Every `assert` statement produces a result. Some results, like `Error` and `Skip`, will halt execution. `Pass` and `Ignore` results do not halt execution. `Fail` results, by default, halt execution but there is an option to have them not halt execution. Therefore, tests can have many results of varying types.
115
+ Assert.configure do |config|
116
+ config.runner MyAwesomeRunnerClass.new
117
+ end
118
+ ```
75
119
 
76
- ### View
120
+ ### Test Dir
77
121
 
78
- A `View` object is responsible for rendering test result output. Assert provides a `Assert::View::Base` object to provide common helpers and default runner callback handlers for building views. Assert also provides a `Assert::View::DefaultView` that it renders its output with. See the "Viewing Test Results" section below for more details.
122
+ By default Assert expects tests in the `test` dir. The is where it looks for the helper file and is the default path used when running `$ assert`. To override this dir, do so in your user/local settings file:
79
123
 
80
- ### Macro
124
+ ```ruby
125
+ Assert.configure do |config|
126
+ config.test_dir "testing"
127
+ end
128
+ ```
81
129
 
82
- Macros are procs that define sets of test code and make it available for easy reuse. Macros work nicely with the 'should' and 'test' context methods.
130
+ ### Test Helper File
83
131
 
84
- ## User Options and Helpers
132
+ By default Assert will look for a file named `helper.rb` in the `test_dir` and require it (if found) just before running the tests. To override the helper file name, do so in your user/local settings file:
85
133
 
86
- Assert provides ways for setting user-specfic options and helpers. When Assert is setting itself up, the last setup step is to look for and require the file `~/.assert/options.rb`. This file is essentially a user level test helper file. Use it to set options, configure assert extensions, setup/define how to view test results, etc.
134
+ ```ruby
135
+ Assert.configure do |config|
136
+ config.test_helper "some_helpers.rb"
137
+ end
138
+ ```
87
139
 
88
- ## Running Tests
140
+ ### Test Order
89
141
 
90
- Assert uses its [`Assert::Runner`](https://github.com/teaminsight/assert/blob/master/lib/assert/runner.rb) object to run tests by default. This runner runs its suite's tests in random order based on the suite's `runner_seed`.
142
+ The default runner object runs tests in random order. To run tests in a consistant order, specify a custom runner seed:
91
143
 
92
- You can extend this default runner or use your own runner implementation. Either way, specify that you want to use your new runner class by adding this to your user options file
144
+ In user/local settings file:
93
145
 
94
146
  ```ruby
95
- Assert.runner MyAwesomeRunner
147
+ Assert.configure do |config|
148
+ config.runner_seed 1234
149
+ end
96
150
  ```
97
151
 
98
- ### Test Order
152
+ Using the CLI:
153
+
154
+ ```sh
155
+ $ assert [-s|--seed] 1234
156
+ ```
99
157
 
100
- The default runner object runs tests in random order and the `DefaultView` view will display the seed value. If you want to run tests in a consistant order, set a 'runner_seed' environment variable. Here's an example running tests with rake:
158
+ Using an ENV var:
101
159
 
160
+ ```sh
161
+ $ ASSERT_RUNNER_SEED=1234 assert
102
162
  ```
103
- $ rake test # run tests in random order
104
- $ rake test runner_seed=1234 # run tests seeding with '1234'
163
+
164
+ ### Showing Output
165
+
166
+ By default, Assert shows any output on `$stdout` produced while running a test. It provides a setting to override whether to show this output or to 'capture' it and show it with the test result details:
167
+
168
+ In user/local settings file:
169
+
170
+ ```ruby
171
+ Assert.configure do |config|
172
+ config.show_output false
173
+ end
105
174
  ```
106
175
 
107
- ## Viewing Test Results
176
+ Using the CLI:
108
177
 
109
- You have a few options when it comes to viewing test results in Assert. Assert comes with its own `DefaultView` class that handles displaying test results.
178
+ ```sh
179
+ $ assert [-o|--show-output|--no-show-output]
180
+ ```
181
+
182
+ ### Failure Handling
183
+
184
+ By default, Assert will halt test execution when a test produces a Fail result. It provides a setting to override this default:
110
185
 
111
- First, lets look at the default: `Assert::View::DefaultView`. This is the default view class. Its output goes something like this:
186
+ In user/local settings file:
187
+
188
+ ```ruby
189
+ Assert.configure do |config|
190
+ config.halt_on_fail false
191
+ end
192
+ ```
193
+
194
+ Using the CLI:
195
+
196
+ ```sh
197
+ $ assert [-t|--halt|--no-halt]
198
+ ```
199
+
200
+ ## Viewing Test Results
201
+
202
+ `Assert::View::DefaultView` is the default handler for viewing test results. Its output goes something like this:
112
203
 
113
204
  * before the run starts, output some info about the test suite that is about to run
114
205
  * print out result abbreviations as the test results are generated
115
206
  * after the run finishes...
116
- * display any result details (from failing or error results) in reverse test/result order
117
- * output some summary info
207
+ * display any result details (from failing or error results) in reverse test/result order
208
+ * output some summary info
118
209
 
119
- You can run assert's test suite using `rake test` and get a feel for what this default outputs. This view has a few options you can tweak:
210
+ You can run a test suite and get a feel for what this default outputs. The view has a few options you can tweak:
120
211
 
121
212
  * `styled`: whether to apply ANSI styles to the output, default `true`
122
213
  * `pass_styles`: how to style pass result output, default `:green`
@@ -125,20 +216,24 @@ You can run assert's test suite using `rake test` and get a feel for what this d
125
216
  * `skip_styles`: default `:cyan`
126
217
  * `ignore_styles`: default: `:magenta`
127
218
 
128
- To override an option, do so in your user options file:
219
+ To override an option, do so in your user/local settings:
129
220
 
130
221
  ```ruby
131
- Assert.view.options.styled false
222
+ Assert.configure do |config|
223
+ config.view.styled false
224
+ end
132
225
  ```
133
226
 
134
- However, the view you use is configurable. Define you own view class and specify it in your `~/.assert/options.rb` file:
227
+ However, the view hanlder you use is itself configurable. Define you own view handler class and specify it in your user/local settings:
135
228
 
136
229
  ```ruby
137
230
  class MyCustomView < Assert::View::Base
138
231
  # define your view here...
139
232
  end
140
233
 
141
- Assert.options.view MyCustomView.new
234
+ Assert.configure do |config|
235
+ config.view MyCustomView.new
236
+ end
142
237
  ```
143
238
 
144
239
  ### Anatomy of a View
@@ -157,17 +252,17 @@ Available callbacks from the runner, and when they are called:
157
252
  * `after_test`: after a test finishes running, the test is passed as an arg
158
253
  * `on_finish`: when the test suite is finished running
159
254
 
160
- Beyond that, each view can do as it sees fit. Initialize how you wish, take whatever options you'd like, and output results as you see fit, given the available callbacks.
255
+ Beyond that, each view can do as it sees fit. Initialize how you wish, take whatever settings you'd like, and output results as you see fit, given the available callbacks.
161
256
 
162
257
  ### Using 3rd party views
163
258
 
164
- To use a 3rd party custom view, you first require it in and then specify using the `Assert.options.view` option. Assert provides a helper for requiring in views. It can be used in two ways. You can pass a fully qualified path to the helper and if it exists, will require it in.
259
+ To use a 3rd party custom view, first require it in and then configure it. Assert provides a helper for requiring in views. It can be used in two ways. You can pass a fully qualified path to the helper and if it exists, will require it in.
165
260
 
166
261
  ```ruby
167
262
  Assert::View.require_user_view '/path/to/my/view'
168
263
  ```
169
264
 
170
- Alternatively, you can install/clone/copy/write your view implementations in `~/.assert/views` and require it in by name. To have assert require it by name, have it installed at `~/assert/views/view_name/lib/view_name.rb` (this structure is compatible with popular conventions in rubygem development). For example:
265
+ Alternatively, you can install/clone/copy/write your view implementations in `~/.assert/views` and require it in by name. To have assert require it by name, have it installed at `~/assert/views/view_name/lib/view_name.rb` (this structure is compatible with popular conventions for rubygem development). For example:
171
266
 
172
267
  ```ruby
173
268
  # assuming ~/.assert/views/my-custom-view/lib/my-custom-view.rb exists
@@ -177,75 +272,54 @@ Assert::View.require_user_view 'my-custom-view'
177
272
 
178
273
  Once your view class is required in, use it and configure it just as you would any view.
179
274
 
180
- ## Failure Handling
181
-
182
- Assert, by default, will halt test execution when a test produces a Fail result. However, Assert provides an option to not halt when Fail results are produced. You can control how assert handles fails by either setting a user option (in your user `~/.assert/options.rb` file):
183
-
184
- ```ruby
185
- Assert::Test.options.halt_on_fail false # force not halting on fail results
186
- ```
275
+ ## Assert Models
187
276
 
188
- or by setting an env variable:
277
+ ### Suite
189
278
 
190
- ```
191
- $ rake test halt_on_fail=true # force halt on failure using an env var
192
- ```
279
+ A `Suite` object is reponsible for collecting and structuring tests and defines the set of tests to run using the test `Runner`. Tests are grouped within the suite by their context. Suite provides access to the contexts, tests, and test results. In addition, the Suite model provides some stats (ie. run_time, runner_seed, etc...).
193
280
 
194
- ## Rake Tasks
281
+ ### Runner
195
282
 
196
- **Note**: rake task handling is deprecated and will be removed in v2.0
283
+ A `Runner` object is responsible for running a suite of tests and firing event callbacks to the `View`. Any runner object should take the test suite and view as arguments and should provide a 'run' method that runs the tests and renders the view.
197
284
 
198
- Assert provides some rake task helpers that will scan your test folder and recursively generate rake tasks for each one of your test folders or files. Test files must end in either `'_test.rb'` or `'_tests.rb'`. Use this as an alternative to running ruby on each one of your test files individually.
285
+ ### Context
199
286
 
200
- As an example, say your test folder has a file structure like so:
287
+ A `Context` object is the scope that tests are run in. When tests are run, a new instance of the test context is created and the test code is evaluated within the scope of this context instance. Context provides methods for defining tests and test callbacks and for generating test results in running tests. Subclass context classes to achieve nested context behavior.
201
288
 
202
- ```
203
- - test
204
- | - basic_test.rb
205
- | - helper.rb
206
- | - complex
207
- | | - fast_tests.rb
208
- | | - slow_tests.rb
209
- ```
289
+ ### Test
210
290
 
211
- Add the following to your Rakefile to generate the test tasks:
291
+ A `Test` object defines the test code that needs to be run and the results generated by that test code. Tests are aware of their context and are responsible for running their code in context.
212
292
 
213
- ```ruby
214
- require 'assert/rake_tasks'
215
- Assert::RakeTasks.install
216
- ```
293
+ ### Result
217
294
 
218
- This would generate following rake tasks:
295
+ A `Result` object defines the data related to a test result. There are a few kinds of test results available:
219
296
 
220
- ```
221
- $ rake -T
222
- rake test # Run all tests
223
- rake test:basic # Run tests for basic
224
- rake test:complex # Run all tests for assertions
225
- rake test:complex:fast # Run tests for assertions:assert_block
226
- rake test:complex:slow # Run tests for assertions:assert_empty
227
- ```
297
+ * `Pass`
298
+ * `Fail`
299
+ * `Error`
300
+ * `Skip`
301
+ * `Ignore`
228
302
 
229
- By default, the rake tasks do not show which test files are being loaded. If you want to see this output from the rake tasks, set a "show_loaded_files" environment variable at the rake command line:
303
+ Tests produce results as they are executed. Every `assert` statement produces a result. Some results, like `Error` and `Skip`, will halt execution. `Pass` and `Ignore` results do not halt execution. `Fail` results, by default, halt execution but there is an option to have them not halt execution. Therefore, tests can have many results of varying types.
230
304
 
231
- ```
232
- $ rake test show_loaded_files=true # run the tests showing which files were loaded
233
- ```
305
+ ### View
234
306
 
235
- ## IRB with your environment loaded
307
+ A `View` object is responsible for rendering test result output. Assert provides a `Assert::View::Base` object to provide common helpers and default runner callback handlers for building views. Assert also provides a `Assert::View::DefaultView` that it renders its output with. See the "Viewing Test Results" section below for more details.
236
308
 
237
- Assert provides a rake task for running irb with your test environment loaded. Create an `irb.rb` file in your test file directory and have it `require 'assert/setup'`. See [Assert's irb.rb](https://github.com/teaminsight/assert/blob/master/test/irb.rb) for an example. Here's how you could use it:
309
+ ### Macro
238
310
 
239
- ```
240
- $ rake irb
241
- > Assert
242
- => Assert
243
- ```
311
+ Macros are procs that define sets of test code and make it available for easy reuse. Macros work nicely with the 'should' and 'test' context methods.
244
312
 
245
313
  ## The Assert family of testing tools
246
314
 
247
315
  TODO: add in references to assert related tools.
248
316
 
317
+ ## Installation
318
+
319
+ ```
320
+ $ gem install assert
321
+ ```
322
+
249
323
  ## Contributing
250
324
 
251
325
  The source code is hosted on Github. Feel free to submit pull requests and file bugs on the issues tracker.
@@ -258,6 +332,6 @@ If submitting a Pull Request, please:
258
332
  4. Push to the branch (`git push origin my-new-feature`)
259
333
  5. Create new Pull Request
260
334
 
261
- One note: please respect that Assert itself is intended to be the flexible, base-level type logic that should change little if at all. Pull requests for niche functionality or personal testing philosphy stuff will likely not be accepted.
335
+ One note: please respect that Assert itself is intended to be the flexible, base-level, framework-type logic that should change little if at all. Pull requests for niche functionality or personal testing philosphy stuff will likely not be accepted.
262
336
 
263
- If you wish to extend Assert for your niche purpose/desire/philosophy, please do so in it's own gem (preferrably named 'assert-<whatever>') that uses Assert as a dependency. When you do, tell us about it and we'll add to this readme with a short description.
337
+ If you wish to extend Assert for your niche purpose/desire/philosophy, please do so in it's own gem (preferrably named `assert-<whatever>`) that uses Assert as a dependency. When you do, tell us about it and we'll add to this README with a short description.
data/Rakefile CHANGED
@@ -1,6 +1,3 @@
1
- require 'assert/rake_tasks'
2
- Assert::RakeTasks.install
3
-
4
1
  require 'bundler'
5
2
  Bundler::GemHelper.install_tasks
6
3
 
data/bin/assert CHANGED
@@ -4,4 +4,4 @@
4
4
  #
5
5
 
6
6
  require 'assert/cli'
7
- Assert::CLI.run ARGV
7
+ Assert::CLI.run *ARGV
@@ -1,5 +1,76 @@
1
- require 'assert/setup/all'
2
- require 'assert/autorun'
1
+ require 'singleton'
3
2
 
4
- Assert::Helpers.load(caller)
5
- Assert.autorun
3
+ module Assert; end
4
+
5
+ require 'assert/view'
6
+ require 'assert/suite'
7
+ require 'assert/runner'
8
+ require 'assert/context'
9
+
10
+ module Assert
11
+
12
+ def self.view; Config.view; end
13
+ def self.suite; Config.suite; end
14
+ def self.runner; Config.runner; end
15
+
16
+ def self.config; Config; end
17
+ def self.configure; yield Config if block_given?; end
18
+
19
+ def self.init(test_files, opts)
20
+ # load any test helper file
21
+ if p = opts[:test_dir_path]
22
+ helper_file = File.join(p, Config.test_helper)
23
+ require helper_file if File.exists?(helper_file)
24
+ end
25
+
26
+ # load the test files
27
+ Assert.view.fire(:before_load, test_files)
28
+ test_files.each{ |p| require p }
29
+ Assert.view.fire(:after_load)
30
+ end
31
+
32
+ class Config
33
+ include Singleton
34
+ # map any class methods to the singleton
35
+ def self.method_missing(m, *a, &b); self.instance.send(m, *a, &b); end
36
+ def self.respond_to?(m); super || self.instance.respond_to?(m); end
37
+
38
+ def self.settings(*items)
39
+ items.each do |item|
40
+ define_method(item) do |*args|
41
+ if !(value = args.size > 1 ? args : args.first).nil?
42
+ instance_variable_set("@#{item}", value)
43
+ end
44
+ instance_variable_get("@#{item}")
45
+ end
46
+ end
47
+ end
48
+
49
+ settings :view, :suite, :runner, :test_dir, :test_helper
50
+ settings :runner_seed, :show_output, :halt_on_fail, :debug
51
+
52
+ def initialize
53
+ @view = Assert::View::DefaultView.new($stdout)
54
+ @suite = Assert::Suite.new
55
+ @runner = Assert::Runner.new
56
+ @test_dir = "test"
57
+ @test_helper = "helper.rb"
58
+
59
+ # TODO: secure random??
60
+ @runner_seed = begin; srand; srand % 0xFFFF; end.to_i
61
+ @show_output = true
62
+ @halt_on_fail = true
63
+ @debug = false
64
+ end
65
+
66
+ def apply(settings)
67
+ settings.keys.each do |name|
68
+ if !settings[name].nil? && self.respond_to?(name.to_s)
69
+ self.send(name.to_s, settings[name])
70
+ end
71
+ end
72
+ end
73
+
74
+ end
75
+
76
+ end