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
@@ -0,0 +1,24 @@
1
+ require "petitest/texts/base_text"
2
+
3
+ module Petitest
4
+ module Texts
5
+ class TestsResultMarginTopText < ::Petitest::Texts::BaseText
6
+ # @return [Array<Petitest::Test>]
7
+ attr_reader :tests
8
+
9
+ # @param tests [Array<Petitest::Test>]
10
+ def initialize(tests:)
11
+ @tests = tests
12
+ end
13
+
14
+ # @note Override
15
+ def to_s
16
+ if tests.empty?
17
+ "\n"
18
+ else
19
+ "\n\n"
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -2,27 +2,27 @@ require "petitest/texts/base_text"
2
2
 
3
3
  module Petitest
4
4
  module Texts
5
- class TestCasesResultText < ::Petitest::Texts::BaseText
5
+ class TestsResultText < ::Petitest::Texts::BaseText
6
6
  # @return [Time]
7
7
  attr_reader :finished_at
8
8
 
9
9
  # @return [Time]
10
10
  attr_reader :started_at
11
11
 
12
- # @return [Array<Petitest::TestCase>]
13
- attr_reader :test_cases
12
+ # @return [Array<Petitest::Test>]
13
+ attr_reader :tests
14
14
 
15
15
  # @param finished_at [Time]
16
16
  # @param started_at [Time]
17
- # @param test_cases [Array<Petitest::TestCase>]
17
+ # @param tests [Array<Petitest::Test>]
18
18
  def initialize(
19
19
  finished_at:,
20
20
  started_at:,
21
- test_cases:
21
+ tests:
22
22
  )
23
23
  @finished_at = finished_at
24
24
  @started_at = started_at
25
- @test_cases = test_cases
25
+ @tests = tests
26
26
  end
27
27
 
28
28
  # @note Override
@@ -38,8 +38,8 @@ module Petitest
38
38
  # @return [String]
39
39
  def body
40
40
  texts = []
41
- texts << ::Petitest::Texts::FailuresText.new(test_cases: test_cases_failed) unless test_cases_failed.empty?
42
- texts << ::Petitest::Texts::TestCountsText.new(test_cases: test_cases)
41
+ texts << ::Petitest::Texts::FailuresText.new(tests: tests_failed) unless tests_failed.empty?
42
+ texts << ::Petitest::Texts::TestCountsText.new(tests: tests)
43
43
  texts << ::Petitest::Texts::TimesText.new(
44
44
  finished_at: finished_at,
45
45
  started_at: started_at,
@@ -49,12 +49,14 @@ module Petitest
49
49
 
50
50
  # @return [String]
51
51
  def header
52
- ::Petitest::Texts::TestCasesResultMarginTopText.new(test_cases: test_cases).to_s
52
+ ::Petitest::Texts::TestsResultMarginTopText.new(tests: tests).to_s
53
53
  end
54
54
 
55
- # @return [Array<Petitest::TestCase>]
56
- def test_cases_failed
57
- @test_cases_failed ||= test_cases.select(&:failed?)
55
+ # @return [Array<Petitest::Test>]
56
+ def tests_failed
57
+ @tests_failed ||= tests.select do |test|
58
+ test.runner.failed?
59
+ end
58
60
  end
59
61
  end
60
62
  end
@@ -1,3 +1,3 @@
1
1
  module Petitest
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: petitest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-24 00:00:00.000000000 Z
11
+ date: 2017-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -65,32 +65,36 @@ files:
65
65
  - LICENSE.txt
66
66
  - README.md
67
67
  - Rakefile
68
+ - images/demo.png
68
69
  - lib/petitest.rb
69
70
  - lib/petitest/assertion_failure_error.rb
71
+ - lib/petitest/assertion_skip_error.rb
70
72
  - lib/petitest/autorun.rb
71
73
  - lib/petitest/configuration.rb
74
+ - lib/petitest/dsl.rb
72
75
  - lib/petitest/subscriber_concerns/output_concern.rb
73
76
  - lib/petitest/subscriber_concerns/time_concern.rb
74
77
  - lib/petitest/subscribers/base_subscriber.rb
75
78
  - lib/petitest/subscribers/document_report_subscriber.rb
76
79
  - lib/petitest/subscribers/json_report_subscriber.rb
77
80
  - lib/petitest/subscribers/progress_report_subscriber.rb
78
- - lib/petitest/test_case.rb
79
- - lib/petitest/test_cases_runner.rb
81
+ - lib/petitest/test.rb
80
82
  - lib/petitest/test_group.rb
81
83
  - lib/petitest/test_groups.rb
82
84
  - lib/petitest/test_method.rb
85
+ - lib/petitest/test_plan.rb
86
+ - lib/petitest/test_runner.rb
83
87
  - lib/petitest/texts/base_text.rb
84
88
  - lib/petitest/texts/error_message_text.rb
85
89
  - lib/petitest/texts/failures_element_text.rb
86
90
  - lib/petitest/texts/failures_text.rb
87
91
  - lib/petitest/texts/filtered_backtrace_text.rb
88
92
  - lib/petitest/texts/raised_code_text.rb
89
- - lib/petitest/texts/test_case_result_character_text.rb
90
- - lib/petitest/texts/test_case_result_line_text.rb
91
- - lib/petitest/texts/test_cases_result_margin_top_text.rb
92
- - lib/petitest/texts/test_cases_result_text.rb
93
93
  - lib/petitest/texts/test_counts_text.rb
94
+ - lib/petitest/texts/test_result_character_text.rb
95
+ - lib/petitest/texts/test_result_line_text.rb
96
+ - lib/petitest/texts/tests_result_margin_top_text.rb
97
+ - lib/petitest/texts/tests_result_text.rb
94
98
  - lib/petitest/texts/times_text.rb
95
99
  - lib/petitest/version.rb
96
100
  - petitest.gemspec
@@ -1,90 +0,0 @@
1
- module Petitest
2
- class TestCasesRunner
3
- # @return [Array<Class>]
4
- attr_reader :test_group_classes
5
-
6
- # @param test_group_classes [Array<Class>]
7
- def initialize(test_group_classes)
8
- @test_group_classes = test_group_classes
9
- end
10
-
11
- # @return [Boolean]
12
- def run
13
- test_cases = test_group_classes.flat_map(&:test_cases_and_children_test_cases)
14
- before_running_test_cases(test_cases)
15
- test_group_classes.each do |test_group_class|
16
- run_test_group(test_group_class)
17
- end
18
- after_running_test_cases(test_cases)
19
- test_cases.all?(&:passed?)
20
- end
21
-
22
- private
23
-
24
- # @param test_case [Petitest::TestCase]
25
- def after_running_test_case(test_case)
26
- subscribers.each do |subscriber|
27
- subscriber.after_running_test_case(test_case)
28
- end
29
- end
30
-
31
- # @param test_cases [Array<Petitest::TestCase>]
32
- def after_running_test_cases(test_cases)
33
- subscribers.each do |subscriber|
34
- subscriber.after_running_test_cases(test_cases)
35
- end
36
- end
37
-
38
- # @param test_group_class [Class]
39
- def after_running_test_group(test_group_class)
40
- subscribers.each do |subscriber|
41
- subscriber.after_running_test_group(test_group_class)
42
- end
43
- end
44
-
45
- # @param test_case [Petitest::TestCase]
46
- def before_running_test_case(test_case)
47
- subscribers.each do |subscriber|
48
- subscriber.before_running_test_case(test_case)
49
- end
50
- end
51
-
52
- # @param test_cases [Array<Petitest::TestCase>]
53
- def before_running_test_cases(test_cases)
54
- subscribers.each do |subscriber|
55
- subscriber.before_running_test_cases(test_cases)
56
- end
57
- end
58
-
59
- # @param test_group_class [Class]
60
- def before_running_test_group(test_group_class)
61
- subscribers.each do |subscriber|
62
- subscriber.before_running_test_group(test_group_class)
63
- end
64
- end
65
-
66
- # @param test_case [Petitest::TestCase]
67
- def run_test_case(test_case)
68
- before_running_test_case(test_case)
69
- test_case.run
70
- after_running_test_case(test_case)
71
- end
72
-
73
- # @param test_group_class [Class]
74
- def run_test_group(test_group_class)
75
- before_running_test_group(test_group_class)
76
- test_group_class.test_cases.each do |test_case|
77
- run_test_case(test_case)
78
- end
79
- test_group_class.children.each do |child_test_group_class|
80
- run_test_group(child_test_group_class)
81
- end
82
- after_running_test_group(test_group_class)
83
- end
84
-
85
- # @return [Array<Petitest::Subscribers::BaseSubscriber>]
86
- def subscribers
87
- ::Petitest.configuration.subscribers
88
- end
89
- end
90
- end
@@ -1,27 +0,0 @@
1
- require "petitest/texts/base_text"
2
-
3
- module Petitest
4
- module Texts
5
- class TestCaseResultCharacterText < ::Petitest::Texts::BaseText
6
- # @return [Petitest::TestCase]
7
- attr_reader :test_case
8
-
9
- # @param test_case [Petitest::TestCase]
10
- def initialize(test_case:)
11
- @test_case = test_case
12
- end
13
-
14
- # @note Override
15
- def to_s
16
- case
17
- when test_case.failed?
18
- colorize("F", :error)
19
- when test_case.skipped?
20
- colorize("*", :skip)
21
- else
22
- "."
23
- end
24
- end
25
- end
26
- end
27
- end
@@ -1,37 +0,0 @@
1
- require "petitest/texts/base_text"
2
-
3
- module Petitest
4
- module Texts
5
- class TestCaseResultLineText < ::Petitest::Texts::BaseText
6
- # @return [Petitest::TestCase]
7
- attr_reader :test_case
8
-
9
- # @param test_case [Petitest::TestCase]
10
- def initialize(test_case:)
11
- @test_case = test_case
12
- end
13
-
14
- # @note Override
15
- def to_s
16
- indent(
17
- colorize("##{test_case.test_method.method_name}", color_type),
18
- 2 * (test_case.test_group_class.nest_level + 1),
19
- )
20
- end
21
-
22
- private
23
-
24
- # @return [Symbol]
25
- def color_type
26
- case
27
- when test_case.failed?
28
- :error
29
- when test_case.skipped?
30
- :skip
31
- else
32
- :pass
33
- end
34
- end
35
- end
36
- end
37
- end
@@ -1,24 +0,0 @@
1
- require "petitest/texts/base_text"
2
-
3
- module Petitest
4
- module Texts
5
- class TestCasesResultMarginTopText < ::Petitest::Texts::BaseText
6
- # @return [Array<Petitest::TestCase>]
7
- attr_reader :test_cases
8
-
9
- # @param test_cases [Array<Petitest::TestCase>]
10
- def initialize(test_cases:)
11
- @test_cases = test_cases
12
- end
13
-
14
- # @note Override
15
- def to_s
16
- if test_cases.empty?
17
- "\n"
18
- else
19
- "\n\n"
20
- end
21
- end
22
- end
23
- end
24
- end