kintama 0.1.9 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -22,7 +22,7 @@ module Kintama
22
22
 
23
23
  # Returns the full name of this context, taking any parent contexts into account
24
24
  def full_name
25
- if @name
25
+ if instance_variable_defined?(:@name) && @name
26
26
  [parent ? parent.full_name : nil, @name].compact.join(" ")
27
27
  else
28
28
  nil
@@ -34,4 +34,4 @@ module Kintama
34
34
  end
35
35
  end
36
36
  end
37
- end
37
+ end
@@ -58,15 +58,15 @@ module Kintama
58
58
  runnable = @runnables.map { |r| r.runnable_on_line(@line) }.compact.first
59
59
  if runnable
60
60
  if runnable.is_a_test?
61
- heirarchy = []
61
+ hierarchy = []
62
62
  parent = runnable.parent.parent
63
63
  until parent == Kintama.default_context do
64
- heirarchy.unshift parent
64
+ hierarchy.unshift parent
65
65
  parent = parent.parent
66
66
  end
67
- heirarchy.each { |context| reporter.context_started(context) }
67
+ hierarchy.each { |context| reporter.context_started(context) }
68
68
  runnable.parent.run_tests([runnable], false, reporter)
69
- heirarchy.reverse.each { |context| reporter.context_finished(context) }
69
+ hierarchy.reverse.each { |context| reporter.context_finished(context) }
70
70
  [runnable.parent]
71
71
  else
72
72
  runnable.run(reporter)
@@ -74,7 +74,7 @@ module Kintama
74
74
  end
75
75
  else
76
76
  puts "Nothing runnable found on line #{@line}"
77
- exit -1
77
+ exit(-1)
78
78
  end
79
79
  end
80
80
  end
@@ -9,7 +9,7 @@ module Kintama
9
9
  attr_accessor :block
10
10
 
11
11
  def pending?
12
- @block.nil?
12
+ !instance_variable_defined?(:@block) || @block.nil?
13
13
  end
14
14
 
15
15
  def run
@@ -65,4 +65,4 @@ module Kintama
65
65
  @failure.backtrace.select { |line| File.expand_path(line).index(base_dir).nil? }.map { |l| " "*4 + File.expand_path(l) }.join("\n")
66
66
  end
67
67
  end
68
- end
68
+ end
@@ -0,0 +1,22 @@
1
+ require 'test_helper'
2
+
3
+ class AutomaticRunningTest < KintamaIntegrationTest
4
+
5
+ def test_should_be_able_to_run_kintama_tests_automatically_when_file_is_loaded
6
+ test_with_content(%{
7
+ context "given a thing" do
8
+ should "work" do
9
+ assert true
10
+ end
11
+ end
12
+ }).run.should_have_passing_exit_status
13
+
14
+ test_with_content(%{
15
+ context "given a thing" do
16
+ should "not work" do
17
+ flunk
18
+ end
19
+ end
20
+ }).run.should_have_failing_exit_status
21
+ end
22
+ end
@@ -0,0 +1,129 @@
1
+ require "test_helper"
2
+
3
+ class LineBasedRunningTest < KintamaIntegrationTest
4
+ def test_should_be_able_to_run_the_test_by_giving_the_line_number_the_test_is_defined_on
5
+ test = test_with_content(%{
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
+ })
15
+ test.run('--line 3') do
16
+ assert_output(/^#{passing("should run this test")}\n\n1 tests/)
17
+ assert_output(/^1 tests, 0 failures/)
18
+ end
19
+ test.run('--line 6') do
20
+ assert_output(/^#{failing("should not run this test")}\n\n1 tests/)
21
+ assert_output(/^1 tests, 1 failures/)
22
+ end
23
+ end
24
+
25
+ def test_should_be_able_to_run_the_test_by_giving_the_line_number_within_the_test_definition
26
+ test = test_with_content(%{
27
+ context "given a thing" do
28
+ should "run this test" do
29
+ assert true
30
+ end
31
+ should "not run this test" do
32
+ flunk
33
+ end
34
+ end
35
+ })
36
+ test.run('--line 4') do
37
+ assert_output(/^#{passing("should run this test")}\n\n1 tests/)
38
+ end
39
+ test.run('--line 7') do
40
+ assert_output(/^#{failing("should not run this test")}\n\n1 tests/)
41
+ end
42
+ end
43
+
44
+ def test_should_be_able_to_run_all_tests_within_a_context_when_line_falls_on_a_context
45
+ test_with_content(%{
46
+ context "given a thing" do
47
+ should "not run this test" do
48
+ flunk
49
+ end
50
+ context "and another thing" do
51
+ should "run this test" do
52
+ end
53
+ should "run this test too" do
54
+ end
55
+ end
56
+ end
57
+ }).run('--line 6') do
58
+ assert_output(/#{passing("should run this test")}\n#{passing("should run this test too")}\n\n2 tests/)
59
+ end
60
+ end
61
+
62
+ def test_should_be_able_to_run_a_test_defined_in_a_second_top_level_context
63
+ test_with_content(%{
64
+ context "given a thing" do
65
+ should "not run this test" do
66
+ flunk
67
+ end
68
+ end
69
+ context "and another thing" do
70
+ should "run this test" do
71
+ end
72
+ end
73
+ }).run('--line 8') do
74
+ assert_output(/#{passing("should run this test")}\n\n1 tests/)
75
+ end
76
+ end
77
+
78
+ def test_should_print_out_the_full_nested_test_name
79
+ test_with_content(%{
80
+ context "given a test" do
81
+ context "that is nested deeply" do
82
+ should "print the full nesting name" do
83
+ end
84
+ end
85
+ end
86
+ }).run('--line 5') do
87
+ assert_output(/given a test\n that is nested deeply\n/)
88
+ end
89
+ end
90
+
91
+ def test_should_not_show_pending_tests_in_the_same_context_as_pending_when_not_targeted
92
+ test_with_content(%{
93
+ context "given a context with a pending test" do
94
+ should "only show the run test" do
95
+ end
96
+ should "ignore the pending test"
97
+ end
98
+ }).run('--line 3') do
99
+ refute_output(/1 pending/)
100
+ end
101
+ end
102
+
103
+ def test_should_be_able_to_target_a_top_level_context
104
+ end
105
+
106
+ def test_should_run_all_tests_when_context_is_on_target_line
107
+ test_with_content(%{
108
+ context "given a context with a pending test" do
109
+ should "run this" do
110
+ end
111
+ should "run this too" do
112
+ end
113
+ end
114
+ }).run('--line 2') do
115
+ assert_output(/2 tests/)
116
+ end
117
+ end
118
+
119
+ def test_should_report_if_nothing_runnable_can_be_found_for_that_line
120
+ test_with_content(%{
121
+ context "given a short context" do
122
+ should "not run this" do
123
+ end
124
+ end
125
+ }).run('--line 1') do
126
+ assert_output(/Nothing runnable found on line 1/)
127
+ end
128
+ end
129
+ end
@@ -1,10 +1,7 @@
1
1
  require 'test_helper'
2
2
 
3
- class BaseReporterTest < Test::Unit::TestCase
4
-
5
- def setup
6
- @reporter = Kintama::Reporter::Base.new
7
- end
3
+ class BaseReporterTest < KintamaIntegrationTest
4
+ report_with Kintama::Reporter::Base
8
5
 
9
6
  def test_assert_output_works
10
7
  assert_output("yes\n") do
@@ -13,145 +10,78 @@ class BaseReporterTest < Test::Unit::TestCase
13
10
  end
14
11
 
15
12
  def test_should_print_summary_when_a_test_passes
16
- c = context "given something" do
13
+ context "given something" do
17
14
  should "pass" do
18
15
  assert true
19
16
  end
20
- end
21
- r = runner(c)
22
- capture_stdout { r.run(@reporter) }
23
- assert_match /^1 tests, 0 failures/, @reporter.test_summary
17
+ end.
18
+ should_output("1 tests, 0 failures")
24
19
  end
25
20
 
26
21
  def test_should_print_out_summary_when_multiple_tests_pass
27
- c = context "given something" do
22
+ context "given something" do
28
23
  should "pass" do
29
24
  assert true
30
25
  end
31
26
  should "also pass" do
32
27
  assert true
33
28
  end
34
- end
35
- r = runner(c)
36
- capture_stdout { r.run(@reporter) }
37
- assert_match /^2 tests, 0 failures/, @reporter.test_summary
29
+ end.
30
+ should_output("2 tests, 0 failures")
38
31
  end
39
32
 
40
33
  def test_should_print_out_summary_when_a_pending_test_exists
41
- c = context "given something" do
34
+ context "given something" do
42
35
  should "pass" do
43
36
  assert true
44
37
  end
45
38
  should "not be implemented yet"
46
- end
47
- r = runner(c)
48
- capture_stdout { r.run(@reporter) }
49
- assert_match /^2 tests, 0 failures, 1 pending/, @reporter.test_summary
39
+ end.
40
+ should_output("2 tests, 0 failures, 1 pending")
50
41
  end
51
42
 
52
43
  def test_should_print_out_failure_details_if_tests_fail
53
- c = context "given something" do
44
+ context "given something" do
54
45
  should "fail" do
55
46
  flunk
56
47
  end
57
48
  should "pass" do
58
49
  assert true
59
50
  end
60
- end
61
- r = runner(c)
62
- capture_stdout { r.run(@reporter) }
63
- assert_match /^1\) given something should fail:\n flunked\./, @reporter.failure_messages[0]
51
+ end.
52
+ should_output(%{
53
+ 1) given something should fail:
54
+ flunked
55
+ })
64
56
  end
65
57
 
66
58
  def test_should_print_out_the_test_duration
67
- c = context "given something" do
68
- should "pass" do
69
- assert true
70
- end
71
- end
72
- r = runner(c)
73
- capture_stdout { r.run(@reporter) }
74
- assert_match /^1 tests, 0 failures \(0\.\d+ seconds\)/, @reporter.test_summary
75
- end
76
-
77
- def test_should_be_able_to_run_tests_from_several_contexts
78
- c1 = context "given something" do
59
+ context "given something" do
79
60
  should "pass" do
80
61
  assert true
81
62
  end
82
- end
83
- c2 = context "given another thing" do
84
- should "also pass" do
85
- assert true
86
- end
87
- end
88
- r = runner(c1, c2)
89
- capture_stdout { r.run(@reporter) }
90
- assert_match /^2 tests, 0 failures/, @reporter.test_summary
91
- end
92
-
93
- def test_should_return_true_if_all_tests_pass
94
- c = context "given something" do
95
- should("pass") { assert true }
96
- should("also pass") { assert true }
97
- end
98
- capture_stdout do
99
- assert_equal true, runner(c).run(@reporter)
100
- end
101
- end
102
-
103
- def test_should_return_false_if_any_tests_fails
104
- c = context "given something" do
105
- should("pass") { assert true }
106
- should("fail") { flunk }
107
- end
108
- capture_stdout do
109
- assert_equal false, runner(c).run(@reporter)
110
- end
111
- end
112
-
113
- def test_should_only_run_each_context_once
114
- Kintama.reset
115
- $already_run = false
116
- c = context "Given something" do
117
- context "and a thing" do
118
- should "only run this once" do
119
- flunk if $already_run
120
- $already_run = true
121
- end
122
- end
123
- end
124
- capture_stdout do
125
- assert runner(c).run(@reporter), "should not have run the context twice"
126
- end
63
+ end.
64
+ should_output(/^1 tests, 0 failures \(0\.\d+ seconds\)/)
127
65
  end
128
66
 
129
67
  def test_should_print_out_the_names_of_tests_that_fail
130
- c = context "given something" do
68
+ context "given something" do
131
69
  should "fail" do
132
70
  flunk
133
71
  end
134
- end
135
- r = runner(c)
136
- capture_stdout { r.run(@reporter) }
137
- assert_match /^1\) given something should fail:\n flunked\./, @reporter.failure_messages[0]
72
+ end.
73
+ should_output(%{
74
+ 1) given something should fail:
75
+ flunked
76
+ })
138
77
  end
139
78
 
140
79
  def test_should_include_line_in_test_of_error_in_failure_message
141
- c = context "given jazz" do
142
- should "tapdance" do
80
+ context "given a test that fails" do
81
+ should "report line of failing test" do
143
82
  $line = __LINE__; flunk
144
83
  end
145
- end
146
- r = runner(c)
147
- capture_stdout { r.run(@reporter) }
148
- assert_match /#{Regexp.escape(File.expand_path(__FILE__))}:#{$line}/, @reporter.failure_messages.first
84
+ end.
85
+ should_output(/#{Regexp.escape(File.expand_path(__FILE__))}:#{$line}/)
149
86
  end
150
-
151
- private
152
-
153
- def runner(*args)
154
- Kintama::Runner::Default.new.with(*args)
155
- end
156
-
157
- end
87
+ end
@@ -1,68 +1,56 @@
1
1
  require 'test_helper'
2
2
 
3
- class InlineReporterTest < Test::Unit::TestCase
4
- def setup
5
- @reporter = Kintama::Reporter::Inline.new
6
- end
3
+ class InlineReporterTest < KintamaIntegrationTest
4
+ report_with Kintama::Reporter::Inline
7
5
 
8
6
  def test_should_print_out_dots_when_a_test_passes
9
- c = context "given something" do
7
+ context "given something" do
10
8
  should "pass" do
11
9
  assert true
12
10
  end
13
- end
14
- r = runner(c)
15
- assert_output(/^\.\n/) do
16
- r.run(@reporter)
17
- end
11
+ end.
12
+ should_output(%{
13
+ .
14
+ })
18
15
  end
19
16
 
20
17
  def test_should_print_out_many_dots_as_tests_run
21
- c = context "given something" do
18
+ context "given something" do
22
19
  should "pass" do
23
20
  assert true
24
21
  end
25
22
  should "also pass" do
26
23
  assert true
27
24
  end
28
- end
29
- r = runner(c)
30
- assert_output(/^\.\.\n/) do
31
- r.run(@reporter)
32
- end
25
+ end.
26
+ should_output(%{
27
+ ..
28
+ })
33
29
  end
34
30
 
35
31
  def test_should_print_out_Fs_as_tests_fail
36
- c = context "given something" do
32
+ context "given something" do
37
33
  should "fail" do
38
34
  flunk
39
35
  end
40
36
  should "pass" do
41
37
  assert true
42
38
  end
43
- end
44
- r = runner(c)
45
- assert_output(/^F\./) do
46
- r.run(@reporter)
47
- end
39
+ end.
40
+ should_output(%{
41
+ F.
42
+ })
48
43
  end
49
44
 
50
45
  def test_should_print_out_Ps_for_pending_tests
51
- c = context "given something" do
46
+ context "given something" do
52
47
  should "not be implemented yet"
53
48
  should "pass" do
54
49
  assert true
55
50
  end
56
- end
57
- r = runner(c)
58
- assert_output(/^P\./) do
59
- r.run(@reporter)
60
- end
61
- end
62
-
63
- private
64
-
65
- def runner(*args)
66
- Kintama::Runner::Default.new.with(*args)
51
+ end.
52
+ should_output(%{
53
+ P.
54
+ })
67
55
  end
68
- end
56
+ end