petitest 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -1
- data/README.md +196 -45
- data/images/demo.png +0 -0
- data/lib/petitest.rb +9 -7
- data/lib/petitest/assertion_skip_error.rb +4 -0
- data/lib/petitest/autorun.rb +4 -2
- data/lib/petitest/dsl.rb +27 -0
- data/lib/petitest/subscriber_concerns/time_concern.rb +2 -2
- data/lib/petitest/subscribers/base_subscriber.rb +12 -12
- data/lib/petitest/subscribers/document_report_subscriber.rb +7 -7
- data/lib/petitest/subscribers/json_report_subscriber.rb +13 -13
- data/lib/petitest/subscribers/progress_report_subscriber.rb +5 -5
- data/lib/petitest/test.rb +142 -0
- data/lib/petitest/test_group.rb +35 -125
- data/lib/petitest/test_plan.rb +102 -0
- data/lib/petitest/{test_case.rb → test_runner.rb} +38 -21
- data/lib/petitest/texts/error_message_text.rb +7 -7
- data/lib/petitest/texts/failures_element_text.rb +9 -14
- data/lib/petitest/texts/failures_text.rb +7 -7
- data/lib/petitest/texts/filtered_backtrace_text.rb +6 -6
- data/lib/petitest/texts/raised_code_text.rb +7 -7
- data/lib/petitest/texts/test_counts_text.rb +26 -26
- data/lib/petitest/texts/test_result_character_text.rb +27 -0
- data/lib/petitest/texts/test_result_line_text.rb +37 -0
- data/lib/petitest/texts/tests_result_margin_top_text.rb +24 -0
- data/lib/petitest/texts/{test_cases_result_text.rb → tests_result_text.rb} +14 -12
- data/lib/petitest/version.rb +1 -1
- metadata +12 -8
- data/lib/petitest/test_cases_runner.rb +0 -90
- data/lib/petitest/texts/test_case_result_character_text.rb +0 -27
- data/lib/petitest/texts/test_case_result_line_text.rb +0 -37
- data/lib/petitest/texts/test_cases_result_margin_top_text.rb +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2fa31c282318eafafb3924faa1b0d8896b8d7c3a
|
4
|
+
data.tar.gz: 147f137bf109acfb85ad8e6a36f7ce1c07605b25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3767d10b75eb06fc7943fb46aeee35a14daf2870eb55aa7c33268ab3345e32e1a50a4ef36548cbc67144ab683e2a62ac0b7a263ddf27f397b3e5f4d2380bbf39
|
7
|
+
data.tar.gz: 2f7ecabd8e1fcb9000818cbf2c6062f160149fbe04599f4cd20f365dc5815f9b696c897424966343fbe0037727863a5e52f5e5ba161a038422ffe43e68d94dcf
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,21 @@
|
|
1
|
+
## v0.3.0
|
2
|
+
|
3
|
+
- Add `Petitest::DSL`
|
4
|
+
- Add `Petitest::TestRunner`
|
5
|
+
- Add `Petitest::Test#skip`
|
6
|
+
- Remove `Petitest::Test.nest_level`
|
7
|
+
- Change `Petitest::Test.sub_test` to `Petitest::DSL#sub_test`
|
8
|
+
- Change `Petitest::TestGroup` to `Petitest::Test`
|
9
|
+
- Change `#after_running_test_case` to `#after_running_test`
|
10
|
+
- Change `#after_running_tests` to `#after_running_test_plan`
|
11
|
+
- Change `#before_running_test_case` to `#before_running_test`
|
12
|
+
- Change `#before_running_tests` to `#before_running_test_plan`
|
13
|
+
|
1
14
|
## v0.2.1
|
2
15
|
|
3
16
|
- Add `after_running_test_group` and `before_running_test_group` events
|
4
17
|
- Add `Petitest::TestGroup#nest_level`
|
5
|
-
- Add `Petitest::TestGroup#
|
18
|
+
- Add `Petitest::TestGroup#sub_test`
|
6
19
|
- Add document style report
|
7
20
|
- Improve error report format
|
8
21
|
- Improve default `#assert` message
|
data/README.md
CHANGED
@@ -5,6 +5,8 @@
|
|
5
5
|
|
6
6
|
A minimal solid testing framework for Ruby.
|
7
7
|
|
8
|
+

|
9
|
+
|
8
10
|
## Installation
|
9
11
|
|
10
12
|
Add this line to your application's Gemfile:
|
@@ -27,85 +29,234 @@ gem install petitest
|
|
27
29
|
|
28
30
|
## Usage
|
29
31
|
|
30
|
-
###
|
32
|
+
### Create your test file
|
31
33
|
|
32
|
-
Define a child class of `Petitest::
|
34
|
+
Define a child class of `Petitest::Test` with `#test_xxx` methods.
|
33
35
|
|
34
36
|
```ruby
|
35
37
|
require "petitest/autorun"
|
36
38
|
|
37
|
-
class
|
38
|
-
def
|
39
|
-
assert
|
39
|
+
class ExampleTest < Petitest::Test
|
40
|
+
def test_addition
|
41
|
+
assert { 1 + 1 == 100 }
|
40
42
|
end
|
43
|
+
end
|
44
|
+
```
|
41
45
|
|
42
|
-
|
43
|
-
assert(false)
|
44
|
-
end
|
46
|
+
### Run it
|
45
47
|
|
46
|
-
|
47
|
-
|
48
|
-
|
48
|
+
Run your test file as a Ruby script:
|
49
|
+
|
50
|
+
```bash
|
51
|
+
ruby test/example_test.rb
|
52
|
+
```
|
53
|
+
|
54
|
+
```
|
55
|
+
PetitestTest
|
56
|
+
#test_one_plus_one_to_be_two
|
57
|
+
|
58
|
+
|
59
|
+
Counts:
|
60
|
+
|
61
|
+
1 tests
|
62
|
+
1 passes
|
63
|
+
0 failures
|
64
|
+
0 skips
|
65
|
+
|
66
|
+
Times:
|
67
|
+
|
68
|
+
Started: 2017-03-25T15:29:21.243918+09:00
|
69
|
+
Finished: 2017-03-25T15:29:21.244149+09:00
|
70
|
+
Total: 0.000231s
|
71
|
+
```
|
72
|
+
|
73
|
+
If any test failed, exit code 1 is returned, othewise 0.
|
74
|
+
|
75
|
+
```bash
|
76
|
+
echo $?
|
77
|
+
```
|
78
|
+
|
79
|
+
```
|
80
|
+
0
|
81
|
+
```
|
82
|
+
|
83
|
+
## Assertions
|
84
|
+
|
85
|
+
Petitest provides only one assertion method, `#assert`.
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
assert { foo }
|
89
|
+
```
|
49
90
|
|
50
|
-
|
51
|
-
|
91
|
+
If you need more assertions, use plugins like [patitest-assertions](https://github.com/petitest/petitest-assertions).
|
92
|
+
|
93
|
+
## DSL
|
94
|
+
|
95
|
+
If you want to use `#desc`, `#test` and `#sub_test` DSL, extend `Petitest::DSL` into your test class.
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
class ExampleTest < Petitest::Test
|
99
|
+
extend ::Petitest::DSL
|
100
|
+
|
101
|
+
test "foo" do
|
102
|
+
assert { foo }
|
52
103
|
end
|
53
104
|
|
54
|
-
|
55
|
-
|
105
|
+
desc "fuba"
|
106
|
+
def test_fuba
|
107
|
+
assert { fuba }
|
56
108
|
end
|
57
109
|
|
58
|
-
|
59
|
-
|
110
|
+
sub_test "bar" do
|
111
|
+
test "baz" do
|
112
|
+
assert { baz }
|
113
|
+
end
|
114
|
+
|
115
|
+
sub_test "boo" do
|
116
|
+
test "boz" do
|
117
|
+
assert { boz }
|
118
|
+
end
|
119
|
+
end
|
60
120
|
end
|
61
121
|
end
|
62
122
|
```
|
63
123
|
|
64
|
-
|
124
|
+
## Configuration
|
65
125
|
|
66
|
-
|
126
|
+
### backtrace_filters
|
67
127
|
|
68
|
-
|
69
|
-
|
128
|
+
Mechanism for filter out unnecessary lines from error backtrace.
|
129
|
+
Each element must be able to respond to `#===` method.
|
130
|
+
|
131
|
+
```ruby
|
132
|
+
Petitest.configuration.backtrace_filters = [
|
133
|
+
-> (line) { line.start_with?("/path/to/petitest/lib") },
|
134
|
+
]
|
70
135
|
```
|
71
136
|
|
137
|
+
### color
|
138
|
+
|
139
|
+
Enable colored output.
|
140
|
+
|
141
|
+
```ruby
|
142
|
+
Petitest.configuration.color = true
|
72
143
|
```
|
73
|
-
.FFF..
|
74
144
|
|
75
|
-
|
145
|
+
### color_scheme
|
76
146
|
|
77
|
-
|
78
|
-
assert(false)
|
79
|
-
Expected false to be truthy
|
80
|
-
# test/petitest_test.rb:9:in `test_false'
|
147
|
+
Color scheme for colored output.
|
81
148
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
149
|
+
```ruby
|
150
|
+
Petitest.configuration.color_scheme = {
|
151
|
+
detail: :cyan,
|
152
|
+
error: :red,
|
153
|
+
pass: :green,
|
154
|
+
skip: :yellow,
|
155
|
+
}
|
156
|
+
```
|
86
157
|
|
87
|
-
|
88
|
-
raise
|
89
|
-
RuntimeError
|
158
|
+
These color types are available on color scheme configuration:
|
90
159
|
|
91
|
-
|
160
|
+
- `:black`
|
161
|
+
- `:blue`
|
162
|
+
- `:bold`
|
163
|
+
- `:cyan`
|
164
|
+
- `:green`
|
165
|
+
- `:magenta`
|
166
|
+
- `:red`
|
167
|
+
- `:white`
|
168
|
+
- `:yellow`
|
92
169
|
|
93
|
-
|
170
|
+
### output
|
94
171
|
|
95
|
-
|
96
|
-
3 passes
|
97
|
-
3 failures
|
98
|
-
0 skips
|
172
|
+
Output path for some subscribers.
|
99
173
|
|
100
|
-
|
174
|
+
```ruby
|
175
|
+
Petitest.configuration.output = ::STDOUT
|
176
|
+
Petitest.configuration.output.sync = true
|
177
|
+
```
|
101
178
|
|
102
|
-
|
103
|
-
|
104
|
-
|
179
|
+
### subscribers
|
180
|
+
|
181
|
+
Test event subscribers (test reporters are kind of subscribers).
|
182
|
+
|
183
|
+
```ruby
|
184
|
+
Petitest.configuration.subscribers = [
|
185
|
+
::Petitest::Subscribers::DocomentReportSubscriber.new,
|
186
|
+
]
|
105
187
|
```
|
106
188
|
|
107
|
-
|
189
|
+
These subscribers are provided by default:
|
190
|
+
|
191
|
+
- `Petitest::Subscribers::DocumentReportSubscriber` (default)
|
192
|
+
- `Petitest::Subscribers::JsonReportSubscriber`
|
193
|
+
- `Petitest::Subscribers::ProgressReportSubscriber`
|
194
|
+
|
195
|
+
## Official Plugins
|
196
|
+
|
197
|
+
Here are some official plugins for Petitest:
|
108
198
|
|
109
199
|
- https://github.com/petitest/petitest-assertions
|
110
200
|
- https://github.com/petitest/petitest-power_assert
|
111
201
|
- https://github.com/petitest/petitest-tap
|
202
|
+
|
203
|
+
## For developers
|
204
|
+
|
205
|
+
### Tree
|
206
|
+
|
207
|
+
```
|
208
|
+
TestPlan
|
209
|
+
|---Test 1
|
210
|
+
|---Test 2
|
211
|
+
|---Test 3
|
212
|
+
|---TestGroup 1
|
213
|
+
| |---Test 1-1
|
214
|
+
| |---Test 1-2
|
215
|
+
| |---Test 1-3
|
216
|
+
| `---TestGroup1-1
|
217
|
+
| |---Test 1-1-1
|
218
|
+
| |---Test 1-1-2
|
219
|
+
| `---Test 1-1-3
|
220
|
+
|---TestGroup2
|
221
|
+
| |---Test 2-1
|
222
|
+
| |---Test 2-2
|
223
|
+
| `---Test 2-3
|
224
|
+
`---TestGroup3
|
225
|
+
|---Test 3-1
|
226
|
+
|---Test 3-2
|
227
|
+
|---Test 3-3
|
228
|
+
`---TestGroup3-1
|
229
|
+
|---Test 3-1-1
|
230
|
+
|---Test 3-1-2
|
231
|
+
`---Test 3-1-3
|
232
|
+
```
|
233
|
+
|
234
|
+
### Order
|
235
|
+
|
236
|
+
1. Test 1
|
237
|
+
1. Test 2
|
238
|
+
1. Test 3
|
239
|
+
1. Test 1-1
|
240
|
+
1. Test 1-2
|
241
|
+
1. Test 1-3
|
242
|
+
1. Test 1-1-1
|
243
|
+
1. Test 1-1-2
|
244
|
+
1. Test 1-1-3
|
245
|
+
1. Test 2-1
|
246
|
+
1. Test 2-2
|
247
|
+
1. Test 2-3
|
248
|
+
1. Test 3-1
|
249
|
+
1. Test 3-2
|
250
|
+
1. Test 3-3
|
251
|
+
1. Test 3-1-1
|
252
|
+
1. Test 3-1-2
|
253
|
+
1. Test 3-1-3
|
254
|
+
|
255
|
+
### Events
|
256
|
+
|
257
|
+
- `#before_running_test_plan(test_plan)`
|
258
|
+
- `#before_running_test_group(test_group)`
|
259
|
+
- `#before_running_test(test)`
|
260
|
+
- `#after_running_test(test)`
|
261
|
+
- `#after_running_test_group(test_group)`
|
262
|
+
- `#after_running_test_plan(test_plan)`
|
data/images/demo.png
ADDED
Binary file
|
data/lib/petitest.rb
CHANGED
@@ -1,26 +1,28 @@
|
|
1
1
|
require "petitest/assertion_failure_error"
|
2
|
+
require "petitest/assertion_skip_error"
|
2
3
|
require "petitest/configuration"
|
4
|
+
require "petitest/dsl"
|
3
5
|
require "petitest/subscriber_concerns/output_concern"
|
4
6
|
require "petitest/subscriber_concerns/time_concern"
|
5
7
|
require "petitest/subscribers/base_subscriber"
|
6
8
|
require "petitest/subscribers/document_report_subscriber"
|
7
9
|
require "petitest/subscribers/json_report_subscriber"
|
8
10
|
require "petitest/subscribers/progress_report_subscriber"
|
9
|
-
require "petitest/
|
10
|
-
require "petitest/test_cases_runner"
|
11
|
+
require "petitest/test"
|
11
12
|
require "petitest/test_group"
|
12
|
-
require "petitest/test_groups"
|
13
13
|
require "petitest/test_method"
|
14
|
+
require "petitest/test_plan"
|
15
|
+
require "petitest/test_runner"
|
14
16
|
require "petitest/texts/base_text"
|
15
17
|
require "petitest/texts/error_message_text"
|
16
18
|
require "petitest/texts/failures_element_text"
|
17
19
|
require "petitest/texts/failures_text"
|
18
20
|
require "petitest/texts/filtered_backtrace_text"
|
19
21
|
require "petitest/texts/raised_code_text"
|
20
|
-
require "petitest/texts/
|
21
|
-
require "petitest/texts/
|
22
|
-
require "petitest/texts/
|
23
|
-
require "petitest/texts/
|
22
|
+
require "petitest/texts/test_result_character_text"
|
23
|
+
require "petitest/texts/test_result_line_text"
|
24
|
+
require "petitest/texts/tests_result_margin_top_text"
|
25
|
+
require "petitest/texts/tests_result_text"
|
24
26
|
require "petitest/texts/test_counts_text"
|
25
27
|
require "petitest/texts/times_text"
|
26
28
|
require "petitest/version"
|
data/lib/petitest/autorun.rb
CHANGED
@@ -4,7 +4,9 @@ at_exit do
|
|
4
4
|
if $! && !($!.is_a?(::SystemExit) && $!.success?)
|
5
5
|
next
|
6
6
|
end
|
7
|
-
|
8
|
-
|
7
|
+
test_classes = Petitest::Test.children
|
8
|
+
test_plan = Petitest::TestPlan.new(test_classes: test_classes)
|
9
|
+
test_plan.run
|
10
|
+
exit_code = test_plan.passed? ? 0 : 1
|
9
11
|
exit(exit_code)
|
10
12
|
end
|
data/lib/petitest/dsl.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
module Petitest
|
2
|
+
module DSL
|
3
|
+
# @param current_description [String]
|
4
|
+
def desc(current_description)
|
5
|
+
self.current_description = current_description
|
6
|
+
end
|
7
|
+
|
8
|
+
# @param description [String]
|
9
|
+
# @param metadata [Hash{Symbol => Object}]
|
10
|
+
def sub_test(description, metadata = {}, &block)
|
11
|
+
child = ::Class.new(self)
|
12
|
+
child.description = description
|
13
|
+
child.metadata = self.metadata.merge(metadata)
|
14
|
+
child.undefine_test_methods
|
15
|
+
child.class_eval(&block)
|
16
|
+
child
|
17
|
+
end
|
18
|
+
|
19
|
+
# @param description [String]
|
20
|
+
# @param metadata [Hash{Symbol => Object}]
|
21
|
+
def test(description, metadata = {}, &block)
|
22
|
+
block ||= -> { skip }
|
23
|
+
desc(description)
|
24
|
+
define_method("test_#{description}", &block)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -10,13 +10,13 @@ module Petitest
|
|
10
10
|
attr_accessor :started_at
|
11
11
|
|
12
12
|
# @note Override
|
13
|
-
def
|
13
|
+
def after_running_test_plan(test_plan)
|
14
14
|
super
|
15
15
|
self.finished_at = ::Time.now
|
16
16
|
end
|
17
17
|
|
18
18
|
# @note Override
|
19
|
-
def
|
19
|
+
def before_running_test_plan(test_plan)
|
20
20
|
super
|
21
21
|
self.started_at = ::Time.now
|
22
22
|
end
|
@@ -1,29 +1,29 @@
|
|
1
1
|
module Petitest
|
2
2
|
module Subscribers
|
3
3
|
class BaseSubscriber
|
4
|
-
# @param
|
5
|
-
def
|
4
|
+
# @param test [Petitest::Test]
|
5
|
+
def after_running_test(test)
|
6
6
|
end
|
7
7
|
|
8
|
-
# @param
|
9
|
-
def after_running_test_cases(test_cases)
|
10
|
-
end
|
11
|
-
|
12
|
-
# @param test_group [Class]
|
8
|
+
# @param test_group [Petitest::TestGroup]
|
13
9
|
def after_running_test_group(test_group)
|
14
10
|
end
|
15
11
|
|
16
|
-
# @param
|
17
|
-
def
|
12
|
+
# @param test_plan [Petitest::TestPlan]
|
13
|
+
def after_running_test_plan(test_plan)
|
18
14
|
end
|
19
15
|
|
20
|
-
# @param
|
21
|
-
def
|
16
|
+
# @param test [Petitest::Test]
|
17
|
+
def before_running_test(test)
|
22
18
|
end
|
23
19
|
|
24
|
-
# @param test_group [
|
20
|
+
# @param test_group [Petitest::TestGroup]
|
25
21
|
def before_running_test_group(test_group)
|
26
22
|
end
|
23
|
+
|
24
|
+
# @param test_plan [Petitest::TestPlan]
|
25
|
+
def before_running_test_plan(test_plan)
|
26
|
+
end
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|