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
@@ -0,0 +1,15 @@
1
+ require 'test_helper'
2
+
3
+ class ContextTest < Minitest::Test
4
+ def test_should_clear_previous_failure_when_running_test_again
5
+ $thing = 456
6
+ x = context "Given something" do
7
+ should "work" do
8
+ assert_equal 123, $thing
9
+ end
10
+ end
11
+ assert_equal false, x.run
12
+ $thing = 123
13
+ assert_equal true, x.run
14
+ end
15
+ end
@@ -0,0 +1,87 @@
1
+ require "test_helper"
2
+
3
+ class RunnerTest < Minitest::Test
4
+ def setup
5
+ @reporter = Kintama::Reporter::Verbose.new(colour=false)
6
+ end
7
+
8
+ def test_should_return_true_if_all_tests_pass
9
+ c = context "given something" do
10
+ should("pass") { assert true }
11
+ should("also pass") { assert true }
12
+ end
13
+ assert_equal true, silence_stdout { runner(c).run(@reporter) }
14
+ end
15
+
16
+ def test_should_return_false_if_any_tests_fails
17
+ c = context "given something" do
18
+ should("pass") { assert true }
19
+ should("fail") { flunk }
20
+ end
21
+ assert_equal false, silence_stdout { runner(c).run(@reporter) }
22
+ end
23
+
24
+ def test_should_be_able_to_run_tests_from_several_contexts
25
+ reporter = stub_reporter
26
+
27
+ reporter.expects(:test_started).twice
28
+
29
+ c1 = context "given something" do
30
+ should "pass" do
31
+ assert true
32
+ end
33
+ end
34
+ c2 = context "given another thing" do
35
+ should "also pass" do
36
+ assert true
37
+ end
38
+ end
39
+ r = runner(c1, c2)
40
+ silence_stdout { r.run(reporter) }
41
+ end
42
+
43
+ def test_should_only_run_each_context_once
44
+ c = context "Given something" do
45
+ context "and a thing" do
46
+ should "only run this once" do
47
+ end
48
+ end
49
+ end
50
+
51
+ reporter = stub_reporter
52
+ reporter.expects(:context_started).with(responds_with(:name, "and a thing")).once
53
+
54
+ silence_stdout { runner(c).run(reporter) }
55
+ end
56
+
57
+ def test_should_nest_verbose_output_properly_when_running_tests_from_several_contexts
58
+ c1 = context "given something" do
59
+ should "pass" do
60
+ assert true
61
+ end
62
+ end
63
+ c2 = context "given another thing" do
64
+ should "also pass" do
65
+ assert true
66
+ end
67
+ end
68
+ assert_output(/^given something\n should pass: \.\n\ngiven another thing\n should also pass: \./) do
69
+ runner(c1, c2).run(@reporter)
70
+ end
71
+ end
72
+
73
+ private
74
+
75
+ def stub_reporter
76
+ reporter = stub('reporter')
77
+ [:started, :finished, :context_started, :context_finished,
78
+ :test_started, :test_finished, :show_results].each do |method|
79
+ reporter.stubs(method)
80
+ end
81
+ reporter
82
+ end
83
+
84
+ def runner(*args)
85
+ Kintama::Runner::Default.new.with(*args)
86
+ end
87
+ end
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class TestAndSubcontextAccessTest < Test::Unit::TestCase
3
+ class TestAndSubcontextAccessTest < Minitest::Test
4
4
 
5
5
  def test_should_stash_all_defined_contexts_so_they_can_be_accessed_later
6
6
  c1 = context "Given some context" do
@@ -14,33 +14,6 @@ class TestAndSubcontextAccessTest < Test::Unit::TestCase
14
14
  assert_equal [c1, c2], Kintama.default_context.subcontexts
15
15
  end
16
16
 
17
- def test_should_allow_running_of_specific_subcontexts
18
- x = context "Given something" do
19
- should "not be run" do
20
- flunk
21
- end
22
- context "and another thing" do
23
- should "pass" do
24
- assert true
25
- end
26
- end
27
- end
28
- inner_context = x.and_another_thing
29
- inner_context.run
30
- assert inner_context.passed?
31
- end
32
-
33
- def test_should_allow_running_of_specific_tests
34
- x = context "Given something" do
35
- should "fail when run" do
36
- flunk
37
- end
38
- end
39
- t = x.should_fail_when_run.new
40
- t.run
41
- assert !t.passed?
42
- end
43
-
44
17
  def test_should_allow_running_of_specific_subcontexts_using_hashlike_syntax
45
18
  x = context "Given something" do
46
19
  should "not be run" do
@@ -76,7 +49,7 @@ class TestAndSubcontextAccessTest < Test::Unit::TestCase
76
49
  end
77
50
  end
78
51
  end
79
- assert_equal true, x.and_another_thing.run
52
+ assert_equal true, x['and another thing'].run
80
53
  end
81
54
 
82
55
  def test_should_return_true_if_running_a_test_passes
@@ -85,7 +58,7 @@ class TestAndSubcontextAccessTest < Test::Unit::TestCase
85
58
  assert true
86
59
  end
87
60
  end
88
- assert_equal true, x.should_pass_when_run.run
61
+ assert_equal true, x['should pass when run'].run
89
62
  end
90
63
 
91
64
  def test_should_return_false_if_running_a_subcontext_fails
@@ -96,7 +69,7 @@ class TestAndSubcontextAccessTest < Test::Unit::TestCase
96
69
  end
97
70
  end
98
71
  end
99
- assert_equal false, x.and_another_thing.run
72
+ assert_equal false, x['and another thing'].run
100
73
  end
101
74
 
102
75
  def test_should_return_false_if_running_a_test_fails
@@ -105,6 +78,6 @@ class TestAndSubcontextAccessTest < Test::Unit::TestCase
105
78
  flunk
106
79
  end
107
80
  end
108
- assert_equal false, x.should_fail_when_run.run
81
+ assert_equal false, x['should fail when run'].run
109
82
  end
110
- end
83
+ end
@@ -0,0 +1,131 @@
1
+ require 'test_helper'
2
+
3
+ class BasicUsageTest < KintamaIntegrationTest
4
+
5
+ def test_should_pass_when_all_tests_pass
6
+ context "Given a test that passes" do
7
+ should "pass this test" do
8
+ assert true
9
+ end
10
+
11
+ should "pass this test too" do
12
+ assert true
13
+ end
14
+ end.
15
+ should_output(%{
16
+ Given a test that passes
17
+ should pass this test: .
18
+ should pass this test too: .
19
+ }).
20
+ and_pass
21
+ end
22
+
23
+ def test_should_fail_when_all_tests_fail
24
+ context "Given a test that fails" do
25
+ should "fail the test" do
26
+ flunk
27
+ end
28
+ end.
29
+ should_output(%{
30
+ Given a test that fails
31
+ should fail the test: F
32
+ }).
33
+ and_fail
34
+ end
35
+
36
+ def test_should_fail_when_any_tests_fail
37
+ context "Given two tests" do
38
+ should "pass the passing test" do
39
+ assert true
40
+ end
41
+
42
+ should "ultimately fail because there is one failing test" do
43
+ flunk
44
+ end
45
+ end.
46
+ should_run_tests(2).
47
+ and_fail.
48
+ with_failure("should ultimately fail because there is one failing test")
49
+ end
50
+
51
+ def test_should_fail_when_any_assertion_within_a_test_fails
52
+ context "Given a test with two assertions" do
53
+ should "fail because one of the assertions doesn't pass" do
54
+ assert 1 == 2
55
+ assert true
56
+ end
57
+ end.
58
+ should_run_tests(1).
59
+ and_fail
60
+ end
61
+
62
+ def test_should_not_run_any_code_beyond_a_failing_assertion
63
+ context "Given a test with a failure before the end of the test" do
64
+ should "not execute any test after the test failures" do
65
+ flunk "fail here"
66
+ raise "should not get here!"
67
+ end
68
+ end.
69
+ should_fail.with_failure("fail here")
70
+ end
71
+
72
+ def test_should_allow_nesting_of_contexts
73
+ context "Given a context" do
74
+ context "and a subcontext" do
75
+ should "nest this test within the inner context" do
76
+ assert true
77
+ end
78
+ end
79
+ end.
80
+ should_output(%{
81
+ Given a context
82
+ and a subcontext
83
+ should nest this test within the inner context: .
84
+ }).
85
+ and_pass
86
+ end
87
+
88
+ def test_should_allow_multiple_subcontexts
89
+ context "Given some contexts" do
90
+ context "one containing failing tests" do
91
+ should "ultimately fail because of the failing test" do
92
+ flunk
93
+ end
94
+ end
95
+
96
+ context "one containing passing tests" do
97
+ should "still run the passing test" do
98
+ assert true
99
+ end
100
+ end
101
+ end.
102
+ should_run_tests(2).
103
+ and_output(%{
104
+ Given some contexts
105
+ one containing failing tests
106
+ should ultimately fail because of the failing test: F
107
+ one containing passing tests
108
+ should still run the passing test: .
109
+ }).
110
+ and_fail
111
+ end
112
+
113
+ def test_should_allow_deep_nesting_of_subcontexts
114
+ context "Given something" do
115
+ context "and another thing" do
116
+ context "and one more thing" do
117
+ should "work" do
118
+ assert true
119
+ end
120
+ end
121
+ end
122
+ end.
123
+ should_output(%{
124
+ Given something
125
+ and another thing
126
+ and one more thing
127
+ should work: .
128
+ }).
129
+ and_pass
130
+ end
131
+ end
@@ -0,0 +1,98 @@
1
+ require 'test_helper'
2
+
3
+ class SetupTest < KintamaIntegrationTest
4
+
5
+ def test_should_allow_setup_to_provide_instance_variables
6
+ context "When setup sets an instance variable" do
7
+ setup do
8
+ @name = "james"
9
+ end
10
+
11
+ should "provide access to that instance variable in the test" do
12
+ assert_equal "james", @name
13
+ end
14
+ end.
15
+ should_run_tests(1).
16
+ and_pass
17
+ end
18
+
19
+ def test_should_call_all_setup_methods_when_running_tests_in_a_nested_context
20
+ context "Given a setup block in the outer context" do
21
+ setup do
22
+ @name = "james"
23
+ end
24
+
25
+ context "and another setup block in the inner context" do
26
+ setup do
27
+ @name += " is amazing"
28
+ end
29
+
30
+ should "run both setup blocks before the test" do
31
+ assert_equal "james is amazing", @name
32
+ end
33
+ end
34
+ end.
35
+ should_run_tests(1).
36
+ and_pass
37
+ end
38
+
39
+ def test_should_only_run_necessary_setups_where_tests_at_different_nestings_exist
40
+ context "Given a setup in the outer context" do
41
+ setup do
42
+ @name = "james"
43
+ end
44
+
45
+ context "and another setup in the inner context" do
46
+ setup do
47
+ @name += " is amazing"
48
+ end
49
+
50
+ should "run both setups for tests in the inner context" do
51
+ assert_equal "james is amazing", @name
52
+ end
53
+ end
54
+
55
+ should "only run the outer setup for tests in the outer context" do
56
+ assert_equal "james", @name
57
+ end
58
+ end.
59
+ should_run_tests(2).
60
+ and_pass
61
+ end
62
+
63
+ def test_should_run_setup_defined_on_kintama_itself_before_other_setups
64
+ Kintama.setup do
65
+ @thing = 'abc'
66
+ end
67
+
68
+ context "Given a context with a setup block" do
69
+ setup do
70
+ @thing += ' easy as 123'
71
+ end
72
+
73
+ should "have run the setup defined in the default behaviour before the context setup" do
74
+ assert_equal 'abc easy as 123', @thing
75
+ end
76
+ end.
77
+ should_run_tests(1).
78
+ and_pass
79
+ end
80
+
81
+ def test_should_allow_multiple_setups_to_be_registered
82
+ context "Given a context with multiple setup blocks" do
83
+ setup do
84
+ @name ||= "James"
85
+ end
86
+
87
+ setup do
88
+ @name += " Bond"
89
+ end
90
+
91
+ should "run them all in order" do
92
+ assert_equal "James Bond", @name
93
+ end
94
+ end.
95
+ should_run_tests(1).
96
+ and_pass
97
+ end
98
+ end
@@ -0,0 +1,121 @@
1
+ require 'test_helper'
2
+
3
+ class TeardownTest < KintamaIntegrationTest
4
+
5
+ def setup
6
+ super
7
+ @order = sequence('teardown order')
8
+ end
9
+ attr_reader :order
10
+
11
+ def test_should_run_teardown_after_the_test_finishes
12
+ spy = teardown_spy
13
+ spy.expects(:in_test).once.in_sequence(order)
14
+ spy.expects(:tore_down).once.in_sequence(order)
15
+
16
+ context "Given a context with a teardown block" do
17
+ teardown do
18
+ spy.tore_down
19
+ end
20
+
21
+ should "run teardown after the test runs" do
22
+ spy.in_test
23
+ end
24
+ end
25
+ end
26
+
27
+ def test_should_run_all_teardowns_in_proximity_of_nesting_order_after_a_nested_test_finishes
28
+ spy = teardown_spy
29
+ spy.expects(:tore_down).with(:inner).in_sequence(order)
30
+ spy.expects(:tore_down).with(:outer).in_sequence(order)
31
+
32
+ context "Given a context with a teardown block" do
33
+ teardown do
34
+ spy.tore_down(:outer)
35
+ end
36
+
37
+ context "with a subcontext with another teardown block" do
38
+ teardown do
39
+ spy.tore_down(:inner)
40
+ end
41
+
42
+ should "run the inner and then outer teardowns after this test" do
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ def test_should_run_teardown_defined_on_kintama_itself_after_other_teardowns
49
+ spy = teardown_spy
50
+ spy.expects(:tore_down).with(:context_teardown).in_sequence(order)
51
+ spy.expects(:tore_down).with(:kintama_global_teardown).in_sequence(order)
52
+
53
+ Kintama.teardown do
54
+ spy.tore_down(:kintama_global_teardown)
55
+ end
56
+
57
+ context "Given a context with a teardown block" do
58
+ should "run the context teardown, and then the kintama global teardown" do
59
+ end
60
+
61
+ teardown do
62
+ spy.tore_down(:context_teardown)
63
+ end
64
+ end
65
+ end
66
+
67
+ def test_should_allow_multiple_teardowns_to_be_registered
68
+ spy = teardown_spy
69
+ spy.expects(:tore_down).with(:first_teardown).in_sequence(order)
70
+ spy.expects(:tore_down).with(:second_teardown).in_sequence(order)
71
+
72
+ context "Given a context with multiple teardown blocks" do
73
+ should "run them all in the order they appear" do
74
+ assert true
75
+ end
76
+
77
+ teardown do
78
+ spy.tore_down(:first_teardown)
79
+ end
80
+
81
+ teardown do
82
+ spy.tore_down(:second_teardown)
83
+ end
84
+ end
85
+ end
86
+
87
+ def test_should_run_teardowns_even_after_exceptions_in_tests
88
+ spy = teardown_spy
89
+ spy.expects(:tore_down)
90
+
91
+ context "Given a test that fails" do
92
+ should "still run teardown" do
93
+ raise "BOOM"
94
+ end
95
+
96
+ teardown do
97
+ spy.tore_down
98
+ end
99
+ end
100
+ end
101
+
102
+ def test_should_not_mask_exceptions_in_tests_with_ones_in_teardown
103
+ context "Given a test and teardown that fails" do
104
+ should "report the error in the test" do
105
+ raise "exception from test"
106
+ end
107
+
108
+ teardown do
109
+ raise "exception from teardown"
110
+ end
111
+ end.
112
+ should_fail.
113
+ with_failure("exception from test")
114
+ end
115
+
116
+ private
117
+
118
+ def teardown_spy
119
+ stub('teardown spy', tore_down: nil)
120
+ end
121
+ end