kintama 0.1.9 → 0.2

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.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +2 -2
  3. data/lib/kintama.rb +26 -12
  4. data/lib/kintama/assertions.rb +40 -1
  5. data/lib/kintama/context.rb +65 -50
  6. data/lib/kintama/mocha.rb +32 -10
  7. data/lib/kintama/no_conflict.rb +2 -0
  8. data/lib/kintama/reporter.rb +11 -10
  9. data/lib/kintama/runnable.rb +2 -2
  10. data/lib/kintama/runner.rb +5 -5
  11. data/lib/kintama/test.rb +2 -2
  12. data/test/integration/automatic_running_test.rb +22 -0
  13. data/test/integration/line_based_running_test.rb +129 -0
  14. data/test/reporters/base_reporter_test.rb +31 -101
  15. data/test/reporters/inline_reporter_test.rb +23 -35
  16. data/test/reporters/verbose_reporter_test.rb +78 -76
  17. data/test/test_helper.rb +159 -2
  18. data/test/{assertions_test.rb → unit/assertions_test.rb} +54 -5
  19. data/test/unit/context_test.rb +15 -0
  20. data/test/unit/runner_test.rb +87 -0
  21. data/test/{test_and_subcontext_access_test.rb → unit/test_and_subcontext_access_test.rb} +6 -33
  22. data/test/usage/01_basic_usage_test.rb +131 -0
  23. data/test/usage/02_setup_test.rb +98 -0
  24. data/test/usage/03_teardown_test.rb +121 -0
  25. data/test/usage/04_pending_tests_test.rb +16 -0
  26. data/test/usage/05_aliases_test.rb +73 -0
  27. data/test/usage/06_defining_methods_in_tests_test.rb +202 -0
  28. data/test/usage/07_exceptions_test.rb +42 -0
  29. data/test/usage/08_start_and_finish_test.rb +261 -0
  30. data/test/usage/09_expectations_and_mocking_test.rb +85 -0
  31. data/test/usage/10_let_and_subject_test.rb +134 -0
  32. data/test/usage/11_matcher_test.rb +148 -0
  33. data/test/usage/12_action_test.rb +118 -0
  34. metadata +55 -48
  35. data/test/aliases_test.rb +0 -26
  36. data/test/automatic_running_test.rb +0 -45
  37. data/test/exceptions_test.rb +0 -40
  38. data/test/kintama_test.rb +0 -114
  39. data/test/line_based_running_test.rb +0 -143
  40. data/test/matcher_test.rb +0 -80
  41. data/test/method_behaviour_test.rb +0 -176
  42. data/test/pending_test_and_context.rb +0 -20
  43. data/test/setup_test.rb +0 -107
  44. data/test/start_and_finish_test.rb +0 -94
  45. data/test/teardown_test.rb +0 -106
metadata CHANGED
@@ -1,49 +1,58 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kintama
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
5
- prerelease:
4
+ version: '0.2'
6
5
  platform: ruby
7
6
  authors:
8
7
  - James Adam
9
- autorequire:
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-11-18 00:00:00.000000000 Z
11
+ date: 2020-07-10 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: mocha
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.11.2
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.11.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
20
32
  - !ruby/object:Gem::Version
21
33
  version: '0'
22
34
  type: :development
23
35
  prerelease: false
24
36
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
37
  requirements:
27
- - - ! '>='
38
+ - - ">="
28
39
  - !ruby/object:Gem::Version
29
40
  version: '0'
30
41
  - !ruby/object:Gem::Dependency
31
- name: rake
42
+ name: minitest
32
43
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
44
  requirements:
35
- - - ! '>='
45
+ - - ">="
36
46
  - !ruby/object:Gem::Version
37
47
  version: '0'
38
48
  type: :development
39
49
  prerelease: false
40
50
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
51
  requirements:
43
- - - ! '>='
52
+ - - ">="
44
53
  - !ruby/object:Gem::Version
45
54
  version: '0'
46
- description:
55
+ description:
47
56
  email: james@lazyatom.com
48
57
  executables: []
49
58
  extensions: []
@@ -51,61 +60,59 @@ extra_rdoc_files:
51
60
  - README.md
52
61
  files:
53
62
  - README.md
54
- - test/aliases_test.rb
55
- - test/assertions_test.rb
56
- - test/automatic_running_test.rb
57
- - test/exceptions_test.rb
58
- - test/kintama_test.rb
59
- - test/line_based_running_test.rb
60
- - test/matcher_test.rb
61
- - test/method_behaviour_test.rb
62
- - test/pending_test_and_context.rb
63
- - test/reporters/base_reporter_test.rb
64
- - test/reporters/inline_reporter_test.rb
65
- - test/reporters/verbose_reporter_test.rb
66
- - test/setup_test.rb
67
- - test/start_and_finish_test.rb
68
- - test/teardown_test.rb
69
- - test/test_and_subcontext_access_test.rb
70
- - test/test_helper.rb
63
+ - lib/kintama.rb
71
64
  - lib/kintama/assertions.rb
72
65
  - lib/kintama/context.rb
73
66
  - lib/kintama/mocha.rb
67
+ - lib/kintama/no_conflict.rb
74
68
  - lib/kintama/reporter.rb
75
69
  - lib/kintama/runnable.rb
76
70
  - lib/kintama/runner.rb
77
71
  - lib/kintama/test.rb
78
- - lib/kintama.rb
72
+ - test/integration/automatic_running_test.rb
73
+ - test/integration/line_based_running_test.rb
74
+ - test/reporters/base_reporter_test.rb
75
+ - test/reporters/inline_reporter_test.rb
76
+ - test/reporters/verbose_reporter_test.rb
77
+ - test/test_helper.rb
78
+ - test/unit/assertions_test.rb
79
+ - test/unit/context_test.rb
80
+ - test/unit/runner_test.rb
81
+ - test/unit/test_and_subcontext_access_test.rb
82
+ - test/usage/01_basic_usage_test.rb
83
+ - test/usage/02_setup_test.rb
84
+ - test/usage/03_teardown_test.rb
85
+ - test/usage/04_pending_tests_test.rb
86
+ - test/usage/05_aliases_test.rb
87
+ - test/usage/06_defining_methods_in_tests_test.rb
88
+ - test/usage/07_exceptions_test.rb
89
+ - test/usage/08_start_and_finish_test.rb
90
+ - test/usage/09_expectations_and_mocking_test.rb
91
+ - test/usage/10_let_and_subject_test.rb
92
+ - test/usage/11_matcher_test.rb
93
+ - test/usage/12_action_test.rb
79
94
  homepage: http://github.com/lazyatom
80
95
  licenses: []
81
- post_install_message:
96
+ metadata: {}
97
+ post_install_message:
82
98
  rdoc_options:
83
- - --main
99
+ - "--main"
84
100
  - README.md
85
101
  require_paths:
86
102
  - lib
87
103
  required_ruby_version: !ruby/object:Gem::Requirement
88
- none: false
89
104
  requirements:
90
- - - ! '>='
105
+ - - ">="
91
106
  - !ruby/object:Gem::Version
92
107
  version: '0'
93
- segments:
94
- - 0
95
- hash: 807595197132176464
96
108
  required_rubygems_version: !ruby/object:Gem::Requirement
97
- none: false
98
109
  requirements:
99
- - - ! '>='
110
+ - - ">="
100
111
  - !ruby/object:Gem::Version
101
112
  version: '0'
102
- segments:
103
- - 0
104
- hash: 807595197132176464
105
113
  requirements: []
106
- rubyforge_project:
107
- rubygems_version: 1.8.23
108
- signing_key:
109
- specification_version: 3
114
+ rubygems_version: 3.0.3
115
+ signing_key:
116
+ specification_version: 4
110
117
  summary: It's for writing tests.
111
118
  test_files: []
@@ -1,26 +0,0 @@
1
- require 'test_helper'
2
-
3
- class AliasesTest < Test::Unit::TestCase
4
-
5
- def test_should_provide_given_and_it_aliases_for_context_and_should
6
- x = context "In a world without hope" do
7
- given "a massive gun" do
8
- it "should work out well in the end" do
9
- assert true
10
- end
11
- end
12
- end
13
- x.run
14
- assert x.passed?
15
- end
16
-
17
- def test_should_provide_testcase_alias_for_context
18
- x = testcase "In a world without hope" do
19
- should "work out well in the end" do
20
- assert true
21
- end
22
- end
23
- x.run
24
- assert x.passed?
25
- end
26
- end
@@ -1,45 +0,0 @@
1
- require 'test_helper'
2
-
3
- class AutomaticRunningTest < Test::Unit::TestCase
4
-
5
- def test_should_be_able_to_run_tests_automatically_when_file_is_loaded
6
- assert_passes write_test %{
7
- context "given a thing" do
8
- should "work" do
9
- assert true
10
- end
11
- end}
12
- assert_fails write_test %{
13
- context "given a thing" do
14
- should "not work" do
15
- flunk
16
- end
17
- end}
18
- end
19
-
20
- private
21
-
22
- def write_test(string)
23
- f = File.open("/tmp/kintama_tmp_test.rb", "w") do |f|
24
- f.puts %|$LOAD_PATH.unshift "#{File.expand_path("../../lib", __FILE__)}"; require "kintama"|
25
- f.puts string
26
- end
27
- "/tmp/kintama_tmp_test.rb"
28
- end
29
-
30
- def run_test(path)
31
- prev = ENV["KINTAMA_EXPLICITLY_DONT_RUN"]
32
- ENV["KINTAMA_EXPLICITLY_DONT_RUN"] = nil
33
- output = `ruby #{path}`
34
- ENV["KINTAMA_EXPLICITLY_DONT_RUN"] = prev
35
- $?
36
- end
37
-
38
- def assert_passes(path)
39
- assert_equal 0, run_test(path).exitstatus
40
- end
41
-
42
- def assert_fails(path)
43
- assert_equal 1, run_test(path).exitstatus
44
- end
45
- end
@@ -1,40 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ExceptionsTest < Test::Unit::TestCase
4
-
5
- def test_should_capture_exceptions_in_tests_as_failing_tests
6
- x = context "Given a test" do
7
- should "that raises an exception" do
8
- raise "aaargh"
9
- end
10
- end
11
- x.run
12
- assert !x.passed?
13
- end
14
-
15
- def test_should_capture_exceptions_in_setups_as_failing_tests
16
- x = context "Given a test with setup that fails" do
17
- setup do
18
- raise "aargh"
19
- end
20
- should "that would otherwise pass" do
21
- assert true
22
- end
23
- end
24
- x.run
25
- assert !x.passed?
26
- end
27
-
28
- def test_should_capture_exceptions_in_teardowns_as_failing_tests
29
- x = context "Given a test with teardown that fails" do
30
- teardown do
31
- raise "aargh"
32
- end
33
- should "that would otherwise pass" do
34
- assert true
35
- end
36
- end
37
- x.run
38
- assert !x.passed?
39
- end
40
- end
@@ -1,114 +0,0 @@
1
- require 'test_helper'
2
-
3
- class KintamaTest < Test::Unit::TestCase
4
-
5
- def test_should_pass_when_all_tests_pass
6
- x = context "Given something" do
7
- should "work" do
8
- assert true
9
- end
10
- end
11
- x.run
12
- assert x.passed?
13
- end
14
-
15
- def test_should_fail_when_all_tests_fail
16
- x = context "Given something" do
17
- should "work" do
18
- flunk
19
- end
20
- end
21
- x.run
22
- assert !x.passed?
23
- end
24
-
25
- def test_should_fail_when_any_tests_fail
26
- x = context "Given something" do
27
- should "work" do
28
- flunk
29
- end
30
- should "also work" do
31
- assert true
32
- end
33
- end
34
- x.run
35
- assert !x.passed?
36
- end
37
-
38
- def test_should_fail_when_any_assertion_within_a_test_fails
39
- x = context "Given something" do
40
- should "ultimately not work" do
41
- flunk
42
- assert true
43
- end
44
- end
45
- x.run
46
- assert !x.passed?
47
- end
48
-
49
- def test_should_not_run_any_code_beyond_a_failing_assertion
50
- x = context "Given something" do
51
- should "ultimately not work" do
52
- flunk
53
- raise "should not get here!"
54
- end
55
- end
56
- x.run
57
- assert !x.passed?
58
- end
59
-
60
- def test_should_allow_nesting_of_contexts
61
- x = context "Given something" do
62
- context "and another thing" do
63
- should "work" do
64
- flunk
65
- end
66
- end
67
- end
68
- x.run
69
- assert !x.passed?
70
- end
71
-
72
- def test_should_allow_multiple_subcontexts
73
- x = context "Given something" do
74
- context "and another thing" do
75
- should "work" do
76
- flunk
77
- end
78
- end
79
- context "and another different thing" do
80
- should "work" do
81
- assert true
82
- end
83
- end
84
- end
85
- x.run
86
- assert !x.passed?
87
- end
88
-
89
- def test_should_allow_deep_nesting_of_subcontexts
90
- x = context "Given something" do
91
- context "and another thing" do
92
- context "and one more thing" do
93
- should "work" do
94
- flunk
95
- end
96
- end
97
- end
98
- end
99
- x.run
100
- assert !x.passed?
101
- end
102
-
103
- def test_should_clear_previous_failure_when_running_test_again
104
- $thing = 456
105
- x = context "Given something" do
106
- should "work" do
107
- assert_equal 123, $thing
108
- end
109
- end
110
- assert_equal false, x.run
111
- $thing = 123
112
- assert_equal true, x.run
113
- end
114
- end
@@ -1,143 +0,0 @@
1
- require "test_helper"
2
-
3
- class LineBasedRunningTest < Test::Unit::TestCase
4
- def test_should_be_able_to_run_the_test_by_giving_the_line_number_the_test_is_defined_on
5
- test_file = %{
6
- context "given a thing" do
7
- should "run this test" do
8
- assert true
9
- end
10
- should "not run this test" do
11
- flunk
12
- end
13
- end}
14
- assert_match /^#{passing("should run this test")}\n\n1 tests/, run_test(test_file, "--line 3")
15
- assert_match /^1 tests, 0 failures/, run_test(test_file, "--line 3")
16
-
17
- # assert_match /^#{failing("should not run this test")}\n\n1 tests/, run_test(test_file, "--line 6")
18
- # assert_match /^1 tests, 1 failures/, run_test(test_file, "--line 6")
19
- end
20
-
21
- def test_should_be_able_to_run_the_test_by_giving_the_line_number_within_the_test_definition
22
- test_file = %{
23
- context "given a thing" do
24
- should "run this test" do
25
- assert true
26
- end
27
- should "not run this test" do
28
- flunk
29
- end
30
- end}
31
- assert_match /^#{passing("should run this test")}\n\n1 tests/, run_test(test_file, "--line 4")
32
- assert_match /^#{failing("should not run this test")}\n\n1 tests/, run_test(test_file, "--line 7")
33
- end
34
-
35
- def test_should_be_able_to_run_all_tests_within_a_context_when_line_falls_on_a_context
36
- test_file = %{
37
- context "given a thing" do
38
- should "not run this test" do
39
- flunk
40
- end
41
- context "and another thing" do
42
- should "run this test" do
43
- end
44
- should "run this test too" do
45
- end
46
- end
47
- end}
48
- assert_match /#{passing("should run this test")}\n#{passing("should run this test too")}\n\n2 tests/, run_test(test_file, "--line 6")
49
- end
50
-
51
- def test_should_be_able_to_run_a_test_defined_in_a_second_top_level_context
52
- test_file = %{
53
- context "given a thing" do
54
- should "not run this test" do
55
- flunk
56
- end
57
- end
58
- context "and another thing" do
59
- should "run this test" do
60
- end
61
- end}
62
- assert_match /#{passing("should run this test")}\n\n1 tests/, run_test(test_file, "--line 8")
63
- end
64
-
65
- def test_should_print_out_the_full_nested_test_name
66
- test_file = %{
67
- context "given a test" do
68
- context "that is nested deeply" do
69
- should "print the full nesting name" do
70
- end
71
- end
72
- end}
73
- assert_match /given a test\n that is nested deeply\n/, run_test(test_file, "--line 5")
74
- end
75
-
76
- def test_should_not_show_pending_tests_in_the_same_context_as_pending_when_not_targeted
77
- test_file = %{
78
- context "given a context with a pending test" do
79
- should "only show the run test" do
80
- end
81
- should "ignore the pending test"
82
- end}
83
- assert_no_match /1 pending/, run_test(test_file, "--line 3")
84
- end
85
-
86
- def test_should_be_able_to_target_a_top_level_context
87
- end
88
-
89
- def test_should_not_show_pending_tests_in_the_same_context_as_pending_when_not_targeted
90
- test_file = %{
91
- context "given a context with a pending test" do
92
- should "run this" do
93
- end
94
- should "run this too" do
95
- end
96
- end}
97
- assert_match /2 tests/, run_test(test_file, "--line 2")
98
- end
99
-
100
- def test_should_report_if_nothing_runnable_can_be_found_for_that_line
101
- test_file = %{
102
- context "given a short context" do
103
- should "not run this" do
104
- end
105
- end}
106
- assert_match /Nothing runnable found on line 1/, run_test(test_file, "--line 1")
107
- end
108
-
109
- private
110
-
111
- def write_test(string, path)
112
- f = File.open(path, "w") do |f|
113
- f.puts %|$LOAD_PATH.unshift "#{File.expand_path("../../lib", __FILE__)}"; require "kintama"|
114
- f.puts string.strip
115
- end
116
- end
117
-
118
- def run_test(test_content, options)
119
- path = "/tmp/kintama_tmp_test.rb"
120
- write_test(test_content.strip, path)
121
- prev = ENV["KINTAMA_EXPLICITLY_DONT_RUN"]
122
- ENV["KINTAMA_EXPLICITLY_DONT_RUN"] = nil
123
- output = `ruby #{path} #{options}`
124
- ENV["KINTAMA_EXPLICITLY_DONT_RUN"] = prev
125
- output
126
- end
127
-
128
- def passing(test_name)
129
- if $stdin.tty?
130
- /\e\[32m\s*#{test_name}\e\[0m/
131
- else
132
- /\s*#{test_name}: ./
133
- end
134
- end
135
-
136
- def failing(test_name)
137
- if $stdin.tty?
138
- /\e\[31m\s*#{test_name}\e\[0m/
139
- else
140
- /\s*#{test_name}: F/
141
- end
142
- end
143
- end