kintama 0.1.11 → 0.1.12
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.
- checksums.yaml +7 -0
- data/lib/kintama.rb +19 -5
- data/lib/kintama/assertions.rb +4 -0
- data/lib/kintama/context.rb +58 -47
- data/lib/kintama/mocha.rb +13 -0
- data/lib/kintama/no_conflict.rb +2 -0
- data/lib/kintama/reporter.rb +3 -3
- data/test/{automatic_running_test.rb → integration/automatic_running_test.rb} +5 -5
- data/test/{line_based_running_test.rb → integration/line_based_running_test.rb} +13 -13
- data/test/reporters/base_reporter_test.rb +31 -101
- data/test/reporters/inline_reporter_test.rb +23 -35
- data/test/reporters/verbose_reporter_test.rb +77 -76
- data/test/test_helper.rb +92 -0
- data/test/{assertions_test.rb → unit/assertions_test.rb} +8 -0
- data/test/unit/context_test.rb +15 -0
- data/test/unit/runner_test.rb +87 -0
- data/test/{test_and_subcontext_access_test.rb → unit/test_and_subcontext_access_test.rb} +5 -32
- data/test/usage/01_basic_usage_test.rb +131 -0
- data/test/usage/02_setup_test.rb +98 -0
- data/test/usage/03_teardown_test.rb +120 -0
- data/test/usage/04_pending_tests_test.rb +16 -0
- data/test/usage/05_aliases_test.rb +73 -0
- data/test/usage/06_defining_methods_in_tests_test.rb +202 -0
- data/test/usage/07_exceptions_test.rb +42 -0
- data/test/usage/08_start_and_finish_test.rb +252 -0
- data/test/usage/09_expectations_and_mocking_test.rb +86 -0
- data/test/usage/10_let_and_subject_test.rb +125 -0
- data/test/usage/11_matcher_test.rb +148 -0
- data/test/usage/12_action_test.rb +118 -0
- metadata +36 -42
- data/test/aliases_test.rb +0 -26
- data/test/exceptions_test.rb +0 -40
- data/test/kintama_test.rb +0 -114
- data/test/matcher_test.rb +0 -80
- data/test/method_behaviour_test.rb +0 -176
- data/test/pending_test_and_context.rb +0 -20
- data/test/setup_test.rb +0 -107
- data/test/start_and_finish_test.rb +0 -94
- data/test/teardown_test.rb +0 -106
@@ -1,68 +1,56 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class InlineReporterTest <
|
4
|
-
|
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
|
-
|
7
|
+
context "given something" do
|
10
8
|
should "pass" do
|
11
9
|
assert true
|
12
10
|
end
|
13
|
-
end
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
-
|
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
|
-
|
30
|
-
|
31
|
-
|
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
|
-
|
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
|
-
|
45
|
-
|
46
|
-
|
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
|
-
|
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
|
-
|
58
|
-
|
59
|
-
|
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
|
@@ -1,147 +1,148 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class VerboseReporterTest <
|
4
|
-
|
5
|
-
def setup
|
6
|
-
@reporter = Kintama::Reporter::Verbose.new(false)
|
7
|
-
end
|
3
|
+
class VerboseReporterTest < KintamaIntegrationTest
|
4
|
+
report_with Kintama::Reporter::Verbose
|
8
5
|
|
9
6
|
def test_should_print_out_test_names
|
10
|
-
|
11
|
-
should "
|
7
|
+
context "given something" do
|
8
|
+
should "pass" do
|
12
9
|
assert true
|
13
10
|
end
|
14
|
-
should "pass" do
|
11
|
+
should "pass too" do
|
15
12
|
assert true
|
16
13
|
end
|
17
|
-
end
|
18
|
-
|
19
|
-
|
20
|
-
|
14
|
+
end.
|
15
|
+
should_output(%{
|
16
|
+
given something
|
17
|
+
should pass: .
|
18
|
+
should pass too: .
|
19
|
+
})
|
21
20
|
end
|
22
21
|
|
23
22
|
def test_should_print_out_Ps_beside_pending_test_names
|
24
|
-
|
23
|
+
context "given something" do
|
25
24
|
should "not be implemented"
|
26
25
|
should "pass" do
|
27
26
|
assert true
|
28
27
|
end
|
29
|
-
end
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
end.
|
29
|
+
should_output(%{
|
30
|
+
given something
|
31
|
+
should not be implemented: P
|
32
|
+
should pass: .
|
33
|
+
})
|
33
34
|
end
|
34
35
|
|
35
36
|
def test_should_nest_printed_context_and_test_names
|
36
|
-
|
37
|
+
context "given something" do
|
37
38
|
should "pass" do
|
38
39
|
assert true
|
39
40
|
end
|
40
|
-
context "and
|
41
|
-
should "
|
41
|
+
context "and something else" do
|
42
|
+
should "pass" do
|
42
43
|
assert true
|
43
44
|
end
|
44
45
|
end
|
45
|
-
context "and
|
46
|
-
should "pass" do
|
46
|
+
context "and then this" do
|
47
|
+
should "also pass" do
|
47
48
|
assert true
|
48
49
|
end
|
49
50
|
end
|
50
|
-
end
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
end.
|
52
|
+
should_output(%{
|
53
|
+
given something
|
54
|
+
should pass: .
|
55
|
+
and something else
|
56
|
+
should pass: .
|
57
|
+
and then this
|
58
|
+
should also pass: .
|
59
|
+
})
|
54
60
|
end
|
55
61
|
|
56
62
|
def test_should_print_out_a_summary_of_the_failing_tests_if_some_fail
|
57
|
-
|
63
|
+
context "given something" do
|
58
64
|
should "fail" do
|
59
65
|
assert 1 == 2, "1 should equal 2"
|
60
66
|
end
|
61
|
-
end
|
62
|
-
|
67
|
+
end.
|
68
|
+
should_output(%{
|
69
|
+
given something should fail:
|
70
|
+
1 should equal 2
|
71
|
+
})
|
63
72
|
end
|
64
73
|
|
65
74
|
def test_should_print_out_a_summary_of_the_failing_tests_if_an_exception_occurs_in_a_test
|
66
|
-
|
75
|
+
context "given something" do
|
67
76
|
should "fail" do
|
68
77
|
raise "unexpected issue!"
|
69
78
|
end
|
70
|
-
end
|
71
|
-
|
79
|
+
end.
|
80
|
+
should_output(%{
|
81
|
+
given something should fail:
|
82
|
+
unexpected issue!
|
83
|
+
})
|
72
84
|
end
|
73
85
|
|
74
86
|
def test_should_print_out_a_summary_of_the_failing_tests_if_a_nested_test_fails
|
75
|
-
|
87
|
+
context "given something" do
|
76
88
|
context "and something else" do
|
77
89
|
should "fail" do
|
78
90
|
assert 1 == 2, "1 should equal 2"
|
79
91
|
end
|
80
92
|
end
|
81
|
-
end
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
c1 = context "given something" do
|
87
|
-
should "pass" do
|
88
|
-
assert true
|
89
|
-
end
|
90
|
-
end
|
91
|
-
c2 = context "given another thing" do
|
92
|
-
should "also pass" do
|
93
|
-
assert true
|
94
|
-
end
|
95
|
-
end
|
96
|
-
assert_output(/^given something\n should pass: \.\n\ngiven another thing\n should also pass: \./) do
|
97
|
-
runner(c1, c2).run(@reporter)
|
98
|
-
end
|
93
|
+
end.
|
94
|
+
should_output(%{
|
95
|
+
given something and something else should fail:
|
96
|
+
1 should equal 2
|
97
|
+
})
|
99
98
|
end
|
100
99
|
|
101
100
|
def test_should_treat_a_context_as_transparent_if_it_has_no_name
|
102
|
-
|
101
|
+
context "given something" do
|
103
102
|
context do
|
104
103
|
should "pass" do
|
105
104
|
assert true
|
106
105
|
end
|
107
106
|
end
|
108
|
-
end
|
109
|
-
|
110
|
-
|
111
|
-
|
107
|
+
end.
|
108
|
+
should_output(%{
|
109
|
+
given something
|
110
|
+
should pass: .
|
111
|
+
})
|
112
112
|
end
|
113
113
|
|
114
114
|
def test_should_print_out_test_names_in_colour_if_colour_is_set
|
115
|
-
|
116
|
-
|
115
|
+
use_reporter Kintama::Reporter::Verbose.new(colour=true)
|
116
|
+
|
117
|
+
context "given tests reported in colour" do
|
118
|
+
should "show failures in red" do
|
117
119
|
flunk
|
118
120
|
end
|
119
|
-
should "
|
121
|
+
should "show passes in green" do
|
120
122
|
assert true
|
121
123
|
end
|
122
|
-
should "
|
123
|
-
end
|
124
|
-
|
125
|
-
|
126
|
-
|
124
|
+
should "show pending tests in yellow"
|
125
|
+
end.
|
126
|
+
should_output(%{
|
127
|
+
given tests reported in colour
|
128
|
+
\e\[31m should show failures in red\e\[0m
|
129
|
+
\e\[32m should show passes in green\e\[0m
|
130
|
+
\e\[33m should show pending tests in yellow\e\[0m
|
131
|
+
})
|
127
132
|
end
|
128
133
|
|
129
134
|
def test_should_print_appropriate_test_names_when_given_and_it_aliases_are_used
|
130
|
-
|
135
|
+
context "In a world without hope" do
|
131
136
|
given "a massive gun" do
|
132
137
|
it "should work out well in the end" do
|
133
138
|
assert true
|
134
139
|
end
|
135
140
|
end
|
136
|
-
end
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
private
|
143
|
-
|
144
|
-
def runner(*args)
|
145
|
-
Kintama::Runner::Default.new.with(*args)
|
141
|
+
end.
|
142
|
+
should_output(%{
|
143
|
+
In a world without hope
|
144
|
+
given a massive gun
|
145
|
+
it should work out well in the end: .
|
146
|
+
})
|
146
147
|
end
|
147
|
-
end
|
148
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
|
+
|
1
2
|
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
2
3
|
require 'test/unit'
|
4
|
+
require 'bundler/setup'
|
3
5
|
|
4
6
|
ENV["KINTAMA_EXPLICITLY_DONT_RUN"] = "true"
|
5
7
|
require 'kintama'
|
6
8
|
|
7
9
|
require 'stringio'
|
10
|
+
require 'mocha/setup'
|
8
11
|
|
9
12
|
class Test::Unit::TestCase
|
10
13
|
def setup
|
@@ -23,6 +26,13 @@ class Test::Unit::TestCase
|
|
23
26
|
ensure
|
24
27
|
$stdout = STDOUT
|
25
28
|
end
|
29
|
+
|
30
|
+
def silence_stdout
|
31
|
+
$stdout = StringIO.new
|
32
|
+
return yield
|
33
|
+
ensure
|
34
|
+
$stdout = STDOUT
|
35
|
+
end
|
26
36
|
end
|
27
37
|
|
28
38
|
def assert_output(expected, &block)
|
@@ -34,3 +44,85 @@ class Test::Unit::TestCase
|
|
34
44
|
end
|
35
45
|
end
|
36
46
|
end
|
47
|
+
|
48
|
+
class KintamaIntegrationTest < Test::Unit::TestCase
|
49
|
+
class << self
|
50
|
+
def reporter_class
|
51
|
+
@reporter_class || Kintama::Reporter::Verbose
|
52
|
+
end
|
53
|
+
|
54
|
+
def report_with(reporter_class)
|
55
|
+
@reporter_class = reporter_class
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
attr_reader :reporter
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def use_reporter(reporter)
|
64
|
+
@reporter = reporter
|
65
|
+
end
|
66
|
+
|
67
|
+
def context(name, &block)
|
68
|
+
ContextTestRunner.new(Kintama.context(name, &block), self)
|
69
|
+
end
|
70
|
+
|
71
|
+
def running_default_context(name, &block)
|
72
|
+
Kintama.context(name, &block)
|
73
|
+
ContextTestRunner.new(Kintama.default_context, self)
|
74
|
+
end
|
75
|
+
|
76
|
+
class ContextTestRunner
|
77
|
+
def initialize(context, test_unit_test)
|
78
|
+
@test_unit_test = test_unit_test
|
79
|
+
@context = context
|
80
|
+
@result = nil
|
81
|
+
@reporter = @test_unit_test.reporter || test_unit_test.class.reporter_class.new(colour=false)
|
82
|
+
@output = capture_stdout do
|
83
|
+
@result = Kintama::Runner.default.with(context).run(@reporter)
|
84
|
+
end.read
|
85
|
+
end
|
86
|
+
|
87
|
+
def should_output(expected_output)
|
88
|
+
if expected_output.is_a?(Regexp)
|
89
|
+
processed_output = expected_output
|
90
|
+
else
|
91
|
+
processed_output = deindent_string_argument(expected_output)
|
92
|
+
end
|
93
|
+
@test_unit_test.assert_match processed_output, @output
|
94
|
+
self
|
95
|
+
end
|
96
|
+
alias_method :and_output, :should_output
|
97
|
+
|
98
|
+
def should_pass(message=nil)
|
99
|
+
@test_unit_test.assert(@result == true, message || "Expected a pass, but failed: #{@context.failures.map { |f| f.failure.message }.join(", ")}")
|
100
|
+
self
|
101
|
+
end
|
102
|
+
alias_method :and_pass, :should_pass
|
103
|
+
|
104
|
+
def should_fail(message=nil)
|
105
|
+
@test_unit_test.assert(@result == false, message || "Expected a failure, but passed!")
|
106
|
+
self
|
107
|
+
end
|
108
|
+
alias_method :and_fail, :should_fail
|
109
|
+
|
110
|
+
def with_failure(failure)
|
111
|
+
@test_unit_test.assert_match deindent_string_argument(failure), @output
|
112
|
+
self
|
113
|
+
end
|
114
|
+
|
115
|
+
def should_run_tests(number)
|
116
|
+
@test_unit_test.assert_equal number, @reporter.test_count, "Expected #{number} tests to run, but #{@reporter.test_count} actually did"
|
117
|
+
self
|
118
|
+
end
|
119
|
+
|
120
|
+
private
|
121
|
+
|
122
|
+
def deindent_string_argument(string)
|
123
|
+
initial_indent = string.gsub(/^\n/, '').match(/^(\s+)/)
|
124
|
+
initial_indent = initial_indent ? initial_indent[1] : ""
|
125
|
+
string.gsub("\n#{initial_indent}", "\n").gsub(/^\n/, '').gsub(/\s+$/, '')
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
@@ -73,6 +73,14 @@ class AssertionsTest < Test::Unit::TestCase
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
|
+
def test_should_provide_assert_same
|
77
|
+
expected, actual = 'foo', 'foo'
|
78
|
+
assert_passed { @test.assert_same expected, expected }
|
79
|
+
assert_failed("Expected #{expected.inspect} (oid=#{expected.object_id}) to be the same as #{actual.inspect} (oid=#{actual.object_id})") do
|
80
|
+
@test.assert_same expected, actual
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
76
84
|
private
|
77
85
|
|
78
86
|
def assert_passed
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ContextTest < Test::Unit::TestCase
|
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
|