petitest 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +14 -1
  3. data/README.md +196 -45
  4. data/images/demo.png +0 -0
  5. data/lib/petitest.rb +9 -7
  6. data/lib/petitest/assertion_skip_error.rb +4 -0
  7. data/lib/petitest/autorun.rb +4 -2
  8. data/lib/petitest/dsl.rb +27 -0
  9. data/lib/petitest/subscriber_concerns/time_concern.rb +2 -2
  10. data/lib/petitest/subscribers/base_subscriber.rb +12 -12
  11. data/lib/petitest/subscribers/document_report_subscriber.rb +7 -7
  12. data/lib/petitest/subscribers/json_report_subscriber.rb +13 -13
  13. data/lib/petitest/subscribers/progress_report_subscriber.rb +5 -5
  14. data/lib/petitest/test.rb +142 -0
  15. data/lib/petitest/test_group.rb +35 -125
  16. data/lib/petitest/test_plan.rb +102 -0
  17. data/lib/petitest/{test_case.rb → test_runner.rb} +38 -21
  18. data/lib/petitest/texts/error_message_text.rb +7 -7
  19. data/lib/petitest/texts/failures_element_text.rb +9 -14
  20. data/lib/petitest/texts/failures_text.rb +7 -7
  21. data/lib/petitest/texts/filtered_backtrace_text.rb +6 -6
  22. data/lib/petitest/texts/raised_code_text.rb +7 -7
  23. data/lib/petitest/texts/test_counts_text.rb +26 -26
  24. data/lib/petitest/texts/test_result_character_text.rb +27 -0
  25. data/lib/petitest/texts/test_result_line_text.rb +37 -0
  26. data/lib/petitest/texts/tests_result_margin_top_text.rb +24 -0
  27. data/lib/petitest/texts/{test_cases_result_text.rb → tests_result_text.rb} +14 -12
  28. data/lib/petitest/version.rb +1 -1
  29. metadata +12 -8
  30. data/lib/petitest/test_cases_runner.rb +0 -90
  31. data/lib/petitest/texts/test_case_result_character_text.rb +0 -27
  32. data/lib/petitest/texts/test_case_result_line_text.rb +0 -37
  33. 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: bea44c83eede7392c848c866de9ad3f02e8bf6cd
4
- data.tar.gz: 6de656fb3130c545bd98bb7702f16e281b9e8d04
3
+ metadata.gz: 2fa31c282318eafafb3924faa1b0d8896b8d7c3a
4
+ data.tar.gz: 147f137bf109acfb85ad8e6a36f7ce1c07605b25
5
5
  SHA512:
6
- metadata.gz: 2f46a03a8de9f1cbfa1a689a06a8883671f7ddc36429adebf2e1beef431498735f87a0d1739a03dcee74af70b87d8b2e42e61b9fd64ccf7ca0e1dc2c73739068
7
- data.tar.gz: '0550090e2cf0f0b70d950d25785446af0030d73cf862d2f4160d62461ffe3b0d6e09d1bf2c2da64c67e8473150be9725393b40ff3bec4288ec4aab215351dd98'
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#sub_test_group`
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
+ ![demo](/images/demo.png)
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
- ### 1. Write test cases
32
+ ### Create your test file
31
33
 
32
- Define a child class of `Petitest::TestGroup` with `#test_xxx` methods.
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 Sometest < Petitest::TestGroup
38
- def test_empty_string
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
- def test_false
43
- assert(false)
44
- end
46
+ ### Run it
45
47
 
46
- def test_nil
47
- assert(nil)
48
- end
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
- def test_raise
51
- raise
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
- def test_true
55
- assert(true)
105
+ desc "fuba"
106
+ def test_fuba
107
+ assert { fuba }
56
108
  end
57
109
 
58
- def test_zero
59
- assert(0)
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
- ### 2. Run tests
124
+ ## Configuration
65
125
 
66
- Run your test file as a Ruby script:
126
+ ### backtrace_filters
67
127
 
68
- ```bash
69
- ruby test/sometest_test.rb
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
- Failures:
145
+ ### color_scheme
76
146
 
77
- 1) PetitestTest#test_false
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
- 2) PetitestTest#test_nil
83
- assert(nil)
84
- Expected nil to be truthy
85
- # test/petitest_test.rb:13:in `test_nil'
149
+ ```ruby
150
+ Petitest.configuration.color_scheme = {
151
+ detail: :cyan,
152
+ error: :red,
153
+ pass: :green,
154
+ skip: :yellow,
155
+ }
156
+ ```
86
157
 
87
- 3) PetitestTest#test_raise
88
- raise
89
- RuntimeError
158
+ These color types are available on color scheme configuration:
90
159
 
91
- # test/petitest_test.rb:17:in `test_raise'
160
+ - `:black`
161
+ - `:blue`
162
+ - `:bold`
163
+ - `:cyan`
164
+ - `:green`
165
+ - `:magenta`
166
+ - `:red`
167
+ - `:white`
168
+ - `:yellow`
92
169
 
93
- Counts:
170
+ ### output
94
171
 
95
- 6 tests
96
- 3 passes
97
- 3 failures
98
- 0 skips
172
+ Output path for some subscribers.
99
173
 
100
- Times:
174
+ ```ruby
175
+ Petitest.configuration.output = ::STDOUT
176
+ Petitest.configuration.output.sync = true
177
+ ```
101
178
 
102
- Started: 2017-03-24T03:09:17.776418+09:00
103
- Finished: 2017-03-24T03:09:17.776527+09:00
104
- Total: 0.000109s
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
- ## Plug-ins
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/test_case"
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/test_case_result_character_text"
21
- require "petitest/texts/test_case_result_line_text"
22
- require "petitest/texts/test_cases_result_margin_top_text"
23
- require "petitest/texts/test_cases_result_text"
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"
@@ -0,0 +1,4 @@
1
+ module Petitest
2
+ class AssertionSkipError < ::StandardError
3
+ end
4
+ end
@@ -4,7 +4,9 @@ at_exit do
4
4
  if $! && !($!.is_a?(::SystemExit) && $!.success?)
5
5
  next
6
6
  end
7
- result = Petitest::TestCasesRunner.new(Petitest::TestGroup.children).run
8
- exit_code = result ? 0 : 1
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
@@ -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 after_running_test_cases(test_cases)
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 before_running_test_cases(test_cases)
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 test_case [Petit::TestCase]
5
- def after_running_test_case(test_case)
4
+ # @param test [Petitest::Test]
5
+ def after_running_test(test)
6
6
  end
7
7
 
8
- # @param test_cases [Array<Petit::TestCase>]
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 test_case [Petit::TestCase]
17
- def before_running_test_case(test_case)
12
+ # @param test_plan [Petitest::TestPlan]
13
+ def after_running_test_plan(test_plan)
18
14
  end
19
15
 
20
- # @param test_cases [Array<Petit::TestCase>]
21
- def before_running_test_cases(test_cases)
16
+ # @param test [Petitest::Test]
17
+ def before_running_test(test)
22
18
  end
23
19
 
24
- # @param test_group [Class]
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