kintama 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +247 -0
- data/lib/kintama.rb +100 -0
- data/lib/kintama/assertions.rb +38 -0
- data/lib/kintama/context.rb +187 -0
- data/lib/kintama/runnable.rb +33 -0
- data/lib/kintama/runner.rb +153 -0
- data/lib/kintama/test.rb +68 -0
- data/test/aliases_test.rb +26 -0
- data/test/assertions_test.rb +42 -0
- data/test/automatic_running_test.rb +45 -0
- data/test/exceptions_test.rb +40 -0
- data/test/kintama_test.rb +114 -0
- data/test/matcher_test.rb +65 -0
- data/test/method_behaviour_test.rb +176 -0
- data/test/pending_test.rb +13 -0
- data/test/runners/base_runner_test.rb +153 -0
- data/test/runners/inline_runner_test.rb +64 -0
- data/test/runners/verbose_runner_test.rb +129 -0
- data/test/setup_test.rb +107 -0
- data/test/teardown_test.rb +92 -0
- data/test/test_and_subcontext_access_test.rb +110 -0
- data/test/test_helper.rb +36 -0
- metadata +89 -0
@@ -0,0 +1,65 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class MatcherTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
class EqualMatcher
|
6
|
+
def initialize(expected)
|
7
|
+
@expected = expected
|
8
|
+
end
|
9
|
+
|
10
|
+
def matches?(provided_value)
|
11
|
+
@actual = provided_value
|
12
|
+
@actual == @expected
|
13
|
+
end
|
14
|
+
|
15
|
+
def failure_message
|
16
|
+
"Expected #{@expected}, but got #{@actual}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def negative_failure_message
|
20
|
+
"Didn't expect #{@expected}, but got it anyway"
|
21
|
+
end
|
22
|
+
|
23
|
+
def description
|
24
|
+
"be equal to #{@expected.inspect}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_should_allow_use_of_matchers_within_contexts
|
29
|
+
c = context "x" do
|
30
|
+
subject { 123 }
|
31
|
+
should EqualMatcher.new(456)
|
32
|
+
end
|
33
|
+
c.run
|
34
|
+
assert !c.passed?
|
35
|
+
assert_match /^Expected 456, but got 123/, c.failures.first.failure_message
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_should_allow_negation_of_matchers
|
39
|
+
c = context "x" do
|
40
|
+
subject { 123 }
|
41
|
+
should_not EqualMatcher.new(123)
|
42
|
+
end
|
43
|
+
c.run
|
44
|
+
assert !c.passed?
|
45
|
+
assert_match /^Didn't expect 123, but got it anyway/, c.failures.first.failure_message
|
46
|
+
end
|
47
|
+
|
48
|
+
module MatcherExtension
|
49
|
+
def be_equal_to(expected)
|
50
|
+
EqualMatcher.new(expected)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_should_allow_definition_of_matchers_in_contexts
|
55
|
+
Kintama.extend(MatcherExtension)
|
56
|
+
c = context "x" do
|
57
|
+
subject { 'abc' }
|
58
|
+
should be_equal_to('abc')
|
59
|
+
should_not be_equal_to('def')
|
60
|
+
end
|
61
|
+
c.run
|
62
|
+
assert c.passed?
|
63
|
+
assert_equal ["should be equal to \"abc\"", "should not be equal to \"def\""], c.tests.map { |t| t.name }
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,176 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class MethodBehaviourTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_should_allow_methods_defined_in_the_context_to_be_called_in_tests
|
6
|
+
x = context "Given I ran a method" do
|
7
|
+
should "set something" do
|
8
|
+
assert self.respond_to?(:do_something)
|
9
|
+
assert_equal 123, do_something
|
10
|
+
end
|
11
|
+
def do_something
|
12
|
+
123
|
13
|
+
end
|
14
|
+
end
|
15
|
+
x.run
|
16
|
+
assert x.passed?
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_should_allow_methods_defined_in_the_context_to_be_called_in_tests_in_subcontexts
|
20
|
+
x = context "Given I ran a method" do
|
21
|
+
context "in a subcontext" do
|
22
|
+
should "set something" do
|
23
|
+
assert self.respond_to?(:do_something)
|
24
|
+
assert_equal 234, do_something
|
25
|
+
end
|
26
|
+
end
|
27
|
+
def do_something
|
28
|
+
234
|
29
|
+
end
|
30
|
+
end
|
31
|
+
x.run
|
32
|
+
assert x.passed?
|
33
|
+
end
|
34
|
+
|
35
|
+
module MyStuff
|
36
|
+
def do_something
|
37
|
+
456
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_should_be_able_to_call_methods_from_included_modules_in_tests
|
42
|
+
x = context "Given I include a module" do
|
43
|
+
include MyStuff
|
44
|
+
should "allow calling methods from that module" do
|
45
|
+
assert_equal 456, do_something
|
46
|
+
end
|
47
|
+
end
|
48
|
+
x.run
|
49
|
+
assert x.passed?
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_should_not_allow_methods_from_one_context_to_bleed_into_another
|
53
|
+
context "Given I define a method in one context" do
|
54
|
+
def do_another_thing
|
55
|
+
end
|
56
|
+
end
|
57
|
+
x = context "And I define another context" do
|
58
|
+
it "should not be possible to call that method" do
|
59
|
+
assert !self.respond_to?(:do_another_thing)
|
60
|
+
assert_raises("should not be able to call this") { do_another_thing }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
x.run
|
64
|
+
assert x.passed?
|
65
|
+
end
|
66
|
+
|
67
|
+
module MoreMyStuff
|
68
|
+
def get_thing
|
69
|
+
@thing
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_should_allow_defined_methods_to_refer_to_instance_variables_defined_in_setup_when_included_via_modules
|
74
|
+
c = context "Given I define an instance variable in my setup" do
|
75
|
+
include MoreMyStuff
|
76
|
+
setup do
|
77
|
+
@thing = 123
|
78
|
+
end
|
79
|
+
should "be able to call a method that refers to that variable in a test" do
|
80
|
+
assert_equal 123, get_thing
|
81
|
+
end
|
82
|
+
end
|
83
|
+
c.run
|
84
|
+
assert c.passed?, "Thing was not defined!"
|
85
|
+
end
|
86
|
+
|
87
|
+
module DefaultBehaviour
|
88
|
+
def something
|
89
|
+
'abc'
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_should_allow_including_default_behaviour_in_all_contexts
|
94
|
+
Kintama.include DefaultBehaviour
|
95
|
+
c = context "Given a context" do
|
96
|
+
should "be able to call a method from the globally shared behaviour" do
|
97
|
+
assert_equal 'abc', something
|
98
|
+
end
|
99
|
+
end
|
100
|
+
c.run
|
101
|
+
assert c.passed?, "something was not defined!"
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_should_be_able_to_compose_shoulds_into_methods
|
105
|
+
$ran = false
|
106
|
+
x = context "Given a context" do
|
107
|
+
def self.should_create_a_should_from_a_method
|
108
|
+
should "have created this test" do
|
109
|
+
$ran = true
|
110
|
+
assert true
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
should_create_a_should_from_a_method
|
115
|
+
end
|
116
|
+
x.run
|
117
|
+
assert x.passed?
|
118
|
+
assert $ran
|
119
|
+
|
120
|
+
assert_not_nil x.should_have_created_this_test
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_should_be_able_to_call_methods_in_subcontexts_that_create_tests
|
124
|
+
x = context "Given a subcontext" do
|
125
|
+
def self.with_a_method
|
126
|
+
should "create this test in the subcontext" do
|
127
|
+
flunk
|
128
|
+
end
|
129
|
+
end
|
130
|
+
context "which calls a method defined at the top level" do
|
131
|
+
with_a_method
|
132
|
+
end
|
133
|
+
end
|
134
|
+
x.run
|
135
|
+
subcontext = x.subcontexts.first
|
136
|
+
assert_equal ["should create this test in the subcontext"], subcontext.tests.map { |t| t.name }
|
137
|
+
end
|
138
|
+
|
139
|
+
module TestCreatingBehaviour
|
140
|
+
def with_a_method
|
141
|
+
should "create this test in the subcontext" do
|
142
|
+
flunk
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_should_be_able_to_call_methods_in_subcontexts_that_create_tests_when_defined_in_modules
|
148
|
+
x = context "Given a subcontext" do
|
149
|
+
extend TestCreatingBehaviour
|
150
|
+
|
151
|
+
context "which calls a method defined at the top level" do
|
152
|
+
with_a_method
|
153
|
+
end
|
154
|
+
end
|
155
|
+
x.run
|
156
|
+
subcontext = x.subcontexts.first
|
157
|
+
assert_equal ["should create this test in the subcontext"], subcontext.tests.map { |t| t.name }
|
158
|
+
end
|
159
|
+
|
160
|
+
module NewKintamaBehaviour
|
161
|
+
def define_a_test
|
162
|
+
should "define a test" do
|
163
|
+
flunk
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_should_be_able_to_add_behaviour_to_kintama
|
169
|
+
Kintama.extend NewKintamaBehaviour
|
170
|
+
x = context "A context" do
|
171
|
+
define_a_test
|
172
|
+
end
|
173
|
+
x.run
|
174
|
+
assert !x.passed?
|
175
|
+
end
|
176
|
+
end
|
@@ -0,0 +1,153 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class BaseRunnerTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_assert_output_works
|
6
|
+
assert_output("yes\n") do
|
7
|
+
puts "yes"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_should_print_summary_when_a_test_passes
|
12
|
+
c = context "given something" do
|
13
|
+
should "pass" do
|
14
|
+
assert true
|
15
|
+
end
|
16
|
+
end
|
17
|
+
r = runner(c)
|
18
|
+
capture_stdout { r.run }
|
19
|
+
assert_match /^1 tests, 0 failures/, r.test_summary
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_should_print_out_summary_when_multiple_tests_pass
|
23
|
+
c = context "given something" do
|
24
|
+
should "pass" do
|
25
|
+
assert true
|
26
|
+
end
|
27
|
+
should "also pass" do
|
28
|
+
assert true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
r = runner(c)
|
32
|
+
capture_stdout { r.run }
|
33
|
+
assert_match /^2 tests, 0 failures/, r.test_summary
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_should_print_out_summary_when_a_pending_test_exists
|
37
|
+
c = context "given something" do
|
38
|
+
should "pass" do
|
39
|
+
assert true
|
40
|
+
end
|
41
|
+
should "not be implemented yet"
|
42
|
+
end
|
43
|
+
r = runner(c)
|
44
|
+
capture_stdout { r.run }
|
45
|
+
assert_match /^2 tests, 0 failures, 1 pending/, r.test_summary
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_should_print_out_failure_details_if_tests_fail
|
49
|
+
c = context "given something" do
|
50
|
+
should "fail" do
|
51
|
+
flunk
|
52
|
+
end
|
53
|
+
should "pass" do
|
54
|
+
assert true
|
55
|
+
end
|
56
|
+
end
|
57
|
+
r = runner(c)
|
58
|
+
capture_stdout { r.run }
|
59
|
+
assert_match /^1\) given something should fail:\n flunked\./, r.failure_messages[0]
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_should_print_out_the_test_duration
|
63
|
+
c = context "given something" do
|
64
|
+
should "pass" do
|
65
|
+
assert true
|
66
|
+
end
|
67
|
+
end
|
68
|
+
r = runner(c)
|
69
|
+
capture_stdout { r.run }
|
70
|
+
assert_match /^1 tests, 0 failures \(0\.\d+ seconds\)/, r.test_summary
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_should_be_able_to_run_tests_from_several_contexts
|
74
|
+
c1 = context "given something" do
|
75
|
+
should "pass" do
|
76
|
+
assert true
|
77
|
+
end
|
78
|
+
end
|
79
|
+
c2 = context "given another thing" do
|
80
|
+
should "also pass" do
|
81
|
+
assert true
|
82
|
+
end
|
83
|
+
end
|
84
|
+
r = runner(c1, c2)
|
85
|
+
capture_stdout { r.run }
|
86
|
+
assert_match /^2 tests, 0 failures/, r.test_summary
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_should_return_true_if_all_tests_pass
|
90
|
+
c = context "given something" do
|
91
|
+
should("pass") { assert true }
|
92
|
+
should("also pass") { assert true }
|
93
|
+
end
|
94
|
+
capture_stdout do
|
95
|
+
assert_equal true, runner(c).run
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_should_return_false_if_any_tests_fails
|
100
|
+
c = context "given something" do
|
101
|
+
should("pass") { assert true }
|
102
|
+
should("fail") { flunk }
|
103
|
+
end
|
104
|
+
capture_stdout do
|
105
|
+
assert_equal false, runner(c).run
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_should_only_run_each_context_once
|
110
|
+
Kintama.reset
|
111
|
+
$already_run = false
|
112
|
+
c = context "Given something" do
|
113
|
+
context "and a thing" do
|
114
|
+
should "only run this once" do
|
115
|
+
flunk if $already_run
|
116
|
+
$already_run = true
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
capture_stdout do
|
121
|
+
assert runner(c).run, "should not have run the context twice"
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_should_print_out_the_names_of_tests_that_fail
|
126
|
+
c = context "given something" do
|
127
|
+
should "fail" do
|
128
|
+
flunk
|
129
|
+
end
|
130
|
+
end
|
131
|
+
r = runner(c)
|
132
|
+
capture_stdout { r.run }
|
133
|
+
assert_match /^1\) given something should fail:\n flunked\./, r.failure_messages[0]
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_should_include_line_in_test_of_error_in_failure_message
|
137
|
+
c = context "given jazz" do
|
138
|
+
should "tapdance" do
|
139
|
+
$line = __LINE__; flunk
|
140
|
+
end
|
141
|
+
end
|
142
|
+
r = runner(c)
|
143
|
+
capture_stdout { r.run }
|
144
|
+
assert_match /at #{Regexp.escape(__FILE__)}:#{$line}/, r.failure_messages.first
|
145
|
+
end
|
146
|
+
|
147
|
+
private
|
148
|
+
|
149
|
+
def runner(*args)
|
150
|
+
Kintama::Runner::Base.new(*args)
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class InlineRunnerTest < Test::Unit::TestCase
|
4
|
+
def test_should_print_out_dots_when_a_test_passes
|
5
|
+
c = context "given something" do
|
6
|
+
should "pass" do
|
7
|
+
assert true
|
8
|
+
end
|
9
|
+
end
|
10
|
+
r = runner(c)
|
11
|
+
assert_output(/^\.\n/) do
|
12
|
+
r.run
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_should_print_out_many_dots_as_tests_run
|
17
|
+
c = context "given something" do
|
18
|
+
should "pass" do
|
19
|
+
assert true
|
20
|
+
end
|
21
|
+
should "also pass" do
|
22
|
+
assert true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
r = runner(c)
|
26
|
+
assert_output(/^\.\.\n/) do
|
27
|
+
r.run
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_should_print_out_Fs_as_tests_fail
|
32
|
+
c = context "given something" do
|
33
|
+
should "fail" do
|
34
|
+
flunk
|
35
|
+
end
|
36
|
+
should "pass" do
|
37
|
+
assert true
|
38
|
+
end
|
39
|
+
end
|
40
|
+
r = runner(c)
|
41
|
+
assert_output(/^F\./) do
|
42
|
+
r.run
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_should_print_out_Ps_for_pending_tests
|
47
|
+
c = context "given something" do
|
48
|
+
should "not be implemented yet"
|
49
|
+
should "pass" do
|
50
|
+
assert true
|
51
|
+
end
|
52
|
+
end
|
53
|
+
r = runner(c)
|
54
|
+
assert_output(/^P\./) do
|
55
|
+
r.run
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def runner(*args)
|
62
|
+
Kintama::Runner::Inline.new(*args)
|
63
|
+
end
|
64
|
+
end
|