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
@@ -0,0 +1,16 @@
1
+ require 'test_helper'
2
+
3
+ class PendingTestsTest < KintamaIntegrationTest
4
+
5
+ def test_should_pass_any_pending_tests
6
+ context "Given a context with an unimplemented test" do
7
+ should "indicate that the test is not implemented" # NOTE - no test body
8
+ end.
9
+ should_output(%{
10
+ Given a context with an unimplemented test
11
+ should indicate that the test is not implemented: P
12
+ }).
13
+ and_pass
14
+ end
15
+
16
+ end
@@ -0,0 +1,73 @@
1
+ require 'test_helper'
2
+
3
+ class AliasesTest < KintamaIntegrationTest
4
+
5
+ def test_provides_given_alias_for_context
6
+ context "In a kintama test" do
7
+ given "a context that is defined using the `given` method" do
8
+ test "will be described using `given` in the output" do
9
+ assert true
10
+ end
11
+ end
12
+ end.
13
+ should_output(%{
14
+ In a kintama test
15
+ given a context that is defined using the `given` method
16
+ will be described using `given` in the output: .
17
+ })
18
+ end
19
+
20
+ def test_provides_testcase_alias_for_context
21
+ context "In a kintama test" do
22
+ testcase "a context defined using `testcase`" do
23
+ test "does not prefix anything to the context name" do
24
+ assert true
25
+ end
26
+ end
27
+ end.
28
+ should_output(%{
29
+ In a kintama test
30
+ a context defined using `testcase`
31
+ does not prefix anything to the context name: .
32
+ })
33
+ end
34
+
35
+ def test_provides_describe_alias_for_context
36
+ context "In a kintama test" do
37
+ describe "a context defined using `describe`" do
38
+ test "does not prefix anything to the context name" do
39
+ assert true
40
+ end
41
+ end
42
+ end.
43
+ should_output(%{
44
+ In a kintama test
45
+ a context defined using `describe`
46
+ does not prefix anything to the context name: .
47
+ })
48
+ end
49
+
50
+ def test_provides_should_alias_for_test
51
+ context "A context with a test defined using `should`" do
52
+ should "output the test with `should` in the name" do
53
+ assert true
54
+ end
55
+ end.
56
+ should_output(%{
57
+ A context with a test defined using `should`
58
+ should output the test with `should` in the name: .
59
+ })
60
+ end
61
+
62
+ def test_provides_it_alias_for_test
63
+ context "A context with a test defined using `it`" do
64
+ it "outputs the test with `it` in the name" do
65
+ assert true
66
+ end
67
+ end.
68
+ should_output(%{
69
+ A context with a test defined using `it`
70
+ it outputs the test with `it` in the name: .
71
+ })
72
+ end
73
+ end
@@ -0,0 +1,202 @@
1
+ require 'test_helper'
2
+
3
+ class DefiningMethodsInTestsTest < KintamaIntegrationTest
4
+
5
+ def test_should_allow_methods_defined_in_the_context_to_be_called_in_tests
6
+ context "Given a context with a method defined in it" do
7
+ def do_something
8
+ 123
9
+ end
10
+
11
+ should "allow the method to be called within the test" do
12
+ assert self.respond_to?(:do_something)
13
+ assert_equal 123, do_something
14
+ end
15
+ end.
16
+ should_run_tests(1).
17
+ and_pass
18
+ end
19
+
20
+ def test_should_allow_methods_defined_in_the_context_to_be_called_in_tests_in_subcontexts
21
+ context "Given a method defined in the outer context" do
22
+ def do_something
23
+ 234
24
+ end
25
+
26
+ context "in a subcontext" do
27
+ should "allow the method to be called" do
28
+ assert self.respond_to?(:do_something)
29
+ assert_equal 234, do_something
30
+ end
31
+ end
32
+ end.
33
+ should_run_tests(1).
34
+ and_pass
35
+ end
36
+
37
+ def test_should_not_allow_methods_from_one_context_to_bleed_into_another
38
+ context "Given some subcontexts" do
39
+ context "one of which contains a method" do
40
+ def do_another_thing
41
+ 123
42
+ end
43
+
44
+ it "should be possible to call the method within the same subcontext" do
45
+ assert self.respond_to?(:do_another_thing)
46
+ assert_equal 123, do_another_thing
47
+ end
48
+ end
49
+
50
+ context "one of which does not contain that method" do
51
+ it "should not be possible to call the method defined in a different context" do
52
+ assert !self.respond_to?(:do_another_thing)
53
+ assert_raises("should not be able to call this") { do_another_thing }
54
+ end
55
+ end
56
+ end.
57
+ should_run_tests(2).
58
+ and_pass
59
+ end
60
+
61
+ module ModuleIncludedInContext
62
+ def method_from_module
63
+ 456
64
+ end
65
+ end
66
+
67
+ def test_should_be_able_to_call_methods_from_included_modules_in_tests
68
+ context "Given a module included into a context" do
69
+ include ModuleIncludedInContext
70
+
71
+ should "allow calling methods from that module" do
72
+ assert_equal 456, method_from_module
73
+ end
74
+ end.
75
+ should_run_tests(1).
76
+ and_pass
77
+ end
78
+
79
+ module ModuleWithMethodReferencingAnInstanceVariable
80
+ def method_referencing_an_instance_variable
81
+ @thing
82
+ end
83
+ end
84
+
85
+ def test_should_allow_defined_methods_to_refer_to_instance_variables_defined_in_setup_when_included_via_modules
86
+ context "Given I define an instance variable in my setup" do
87
+ setup do
88
+ @thing = 123
89
+ end
90
+
91
+ include ModuleWithMethodReferencingAnInstanceVariable
92
+
93
+ should "be able to call a method that refers to that variable in a test" do
94
+ assert_equal 123, method_referencing_an_instance_variable
95
+ end
96
+ end.
97
+ should_run_tests(1).
98
+ and_pass "Thing was not defined!"
99
+ end
100
+
101
+ module ModuleIncludedIntoGlobalScope
102
+ def method_included_in_global_scope
103
+ 'abc'
104
+ end
105
+ end
106
+
107
+ def test_should_allow_including_default_behaviour_in_all_contexts
108
+ Kintama.include ModuleIncludedIntoGlobalScope
109
+ context "Given a context" do
110
+ should "be able to call a method from the globally shared behaviour" do
111
+ assert_equal 'abc', method_included_in_global_scope
112
+ end
113
+ end.
114
+ should_run_tests(1).
115
+ and_pass "something was not defined!"
116
+ end
117
+
118
+ def test_should_be_able_to_compose_shoulds_into_methods
119
+ context "Given a context" do
120
+ def self.should_create_a_should_from_a_method
121
+ should "have created this test" do
122
+ assert true
123
+ end
124
+ end
125
+
126
+ should_create_a_should_from_a_method
127
+ end.
128
+ should_run_tests(1).
129
+ and_output(%{
130
+ Given a context
131
+ should have created this test: .
132
+ }).
133
+ and_pass
134
+ end
135
+
136
+ def test_should_be_able_to_call_methods_in_subcontexts_that_create_tests
137
+ context "Given a subcontext" do
138
+ def self.with_a_method
139
+ should "create this test in the subcontext" do
140
+ assert true
141
+ end
142
+ end
143
+
144
+ context "which calls a method defined at the top level" do
145
+ with_a_method
146
+ end
147
+ end.
148
+ should_run_tests(1).
149
+ and_output(%{
150
+ Given a subcontext
151
+ which calls a method defined at the top level
152
+ should create this test in the subcontext: .
153
+ }).
154
+ and_pass
155
+ end
156
+
157
+ module ModuleToAddBehaviourToContext
158
+ def method_to_define_test
159
+ should "create this test in the subcontext" do
160
+ assert true
161
+ end
162
+ end
163
+ end
164
+
165
+ def test_should_be_able_to_call_methods_in_subcontexts_that_create_tests_when_defined_in_modules
166
+ context "Given a subcontext" do
167
+ extend ModuleToAddBehaviourToContext
168
+
169
+ context "which calls a method defined at the top level" do
170
+ method_to_define_test
171
+ end
172
+ end.
173
+ should_run_tests(1).
174
+ and_output(%{
175
+ Given a subcontext
176
+ which calls a method defined at the top level
177
+ should create this test in the subcontext: .
178
+ }).
179
+ and_pass
180
+ end
181
+
182
+ module ModuleExtendedIntoGlobalScope
183
+ def method_to_define_a_test
184
+ should "define a test within the top-level-extended module" do
185
+ assert true
186
+ end
187
+ end
188
+ end
189
+
190
+ def test_should_be_able_to_add_behaviour_to_kintama
191
+ Kintama.extend ModuleExtendedIntoGlobalScope
192
+ context "A context that isn't explicitly extended by a module" do
193
+ method_to_define_a_test
194
+ end.
195
+ should_run_tests(1).
196
+ and_output(%{
197
+ A context that isn't explicitly extended by a module
198
+ should define a test within the top-level-extended module: .
199
+ }).
200
+ and_pass
201
+ end
202
+ end
@@ -0,0 +1,42 @@
1
+ require 'test_helper'
2
+
3
+ class ExceptionsTest < KintamaIntegrationTest
4
+
5
+ def test_should_capture_exceptions_in_tests_as_failing_tests
6
+ context "Given a test" do
7
+ should "fail when there is an exception" do
8
+ raise "aaargh"
9
+ end
10
+ end.
11
+ should_run_tests(1).
12
+ and_fail
13
+ end
14
+
15
+ def test_should_capture_exceptions_in_setups_as_failing_tests
16
+ context "Given a test with setup that fails" do
17
+ setup do
18
+ raise "aargh"
19
+ end
20
+
21
+ should "fail even though it would otherwise pass" do
22
+ assert true
23
+ end
24
+ end.
25
+ should_run_tests(1).
26
+ and_fail
27
+ end
28
+
29
+ def test_should_capture_exceptions_in_teardowns_as_failing_tests
30
+ context "Given a test with teardown that fails" do
31
+ teardown do
32
+ raise "aargh"
33
+ end
34
+
35
+ should "fail even though it would otherwise pass" do
36
+ assert true
37
+ end
38
+ end.
39
+ should_run_tests(1).
40
+ and_fail
41
+ end
42
+ end
@@ -0,0 +1,261 @@
1
+ require "test_helper"
2
+
3
+ class StartAndFinishTest < KintamaIntegrationTest
4
+
5
+ def setup
6
+ super
7
+ @order = sequence('order')
8
+ end
9
+ attr_reader :order
10
+
11
+ def test_should_call_any_on_start_block_when_running_a_context
12
+ spy = test_spy
13
+
14
+ spy.expects(:in_startup).in_sequence(order)
15
+ spy.expects(:in_test).in_sequence(order)
16
+
17
+ context "A context with an `on_start` block" do
18
+ on_start do
19
+ spy.in_startup
20
+ end
21
+
22
+ should "have run the `on_start` block before a test" do
23
+ spy.in_test
24
+ end
25
+ end
26
+ end
27
+
28
+ def test_should_only_call_on_start_block_once_when_running_a_context
29
+ spy = test_spy
30
+
31
+ spy.expects(:in_startup).once.in_sequence(order)
32
+ spy.expects(:in_test).twice.in_sequence(order)
33
+
34
+ context "A context with an `on_start` block" do
35
+ on_start do
36
+ spy.in_startup
37
+ end
38
+
39
+ should "have run the `on_start` block before a test" do
40
+ spy.in_test
41
+ end
42
+
43
+ should "not run that block again before a second test" do
44
+ spy.in_test
45
+ end
46
+ end
47
+ end
48
+
49
+ def test_should_call_on_start_block_in_nested_contexts
50
+ spy = test_spy
51
+
52
+ spy.expects(:outer_startup).once.in_sequence(order)
53
+ spy.expects(:inner_startup).once.in_sequence(order)
54
+ spy.expects(:in_test).twice.in_sequence(order)
55
+
56
+ context "A context with an `on_start` block" do
57
+ on_start do
58
+ spy.outer_startup
59
+ end
60
+
61
+ context "and another `on_start` block in a nested context" do
62
+ on_start do
63
+ spy.inner_startup
64
+ end
65
+
66
+ should "have run both `on_start` blocks before running any tests" do
67
+ spy.in_test
68
+ end
69
+
70
+ should "not run either `on_start` blocks before running subsequent tests" do
71
+ spy.in_test
72
+ end
73
+ end
74
+ end
75
+ end
76
+
77
+ def test_should_call_any_on_finish_block_when_running_a_context
78
+ spy = test_spy
79
+
80
+ spy.expects(:in_test).in_sequence(order)
81
+ spy.expects(:in_finish).in_sequence(order)
82
+
83
+ context "A context with an `on_finish` block" do
84
+ should "not run the `on_finish` block before the test" do
85
+ spy.in_test
86
+ end
87
+
88
+ on_finish do
89
+ spy.in_finish
90
+ end
91
+ end
92
+ end
93
+
94
+ def test_should_only_call_on_finish_block_once_when_running_a_context
95
+ spy = test_spy
96
+
97
+ spy.expects(:in_test).twice.in_sequence(order)
98
+ spy.expects(:in_finish).once.in_sequence(order)
99
+
100
+ context "A context with an `on_finish` block" do
101
+ should "not be run after every test" do
102
+ spy.in_test
103
+ end
104
+
105
+ should "really not be run after every test" do
106
+ spy.in_test
107
+ end
108
+
109
+ on_finish do
110
+ spy.in_finish
111
+ end
112
+ end
113
+ end
114
+
115
+ def test_should_only_call_on_finish_block_after_all_tests
116
+ spy = test_spy
117
+
118
+ spy.expects(:in_test).times(3).in_sequence(order)
119
+ spy.expects(:in_finish).once.in_sequence(order)
120
+
121
+ context "A context with an `on_finish` block" do
122
+ should "have not run the `on_finish` block before the first test" do
123
+ spy.in_test
124
+ end
125
+
126
+ should "have not run the `on_finish` block before the second test" do
127
+ spy.in_test
128
+ end
129
+
130
+ should "have not run the `on_finish` block before the third test" do
131
+ spy.in_test
132
+ end
133
+
134
+ on_finish do
135
+ spy.in_finish
136
+ end
137
+ end
138
+ end
139
+
140
+ def test_should_call_on_finish_block_in_nested_contexts
141
+ spy = test_spy
142
+
143
+ spy.expects(:in_test).twice.in_sequence(order)
144
+ spy.expects(:inner_finish).once.in_sequence(order)
145
+ spy.expects(:outer_finish).once.in_sequence(order)
146
+
147
+ context "A context with an `on_finish` block" do
148
+ context "and another `on_finish` block in a nested context" do
149
+ should "not run either `on_finish` blocks before running the first test" do
150
+ spy.in_test
151
+ end
152
+
153
+ should "not run either `on_start` blocks before running subsequent tests" do
154
+ spy.in_test
155
+ end
156
+
157
+ on_finish do
158
+ spy.inner_finish
159
+ end
160
+ end
161
+
162
+ on_finish do
163
+ spy.outer_finish
164
+ end
165
+ end
166
+ end
167
+
168
+ def test_should_not_rely_on_any_ordering_to_register_on_start_or_on_finish_blocks
169
+ spy = test_spy
170
+
171
+ spy.expects(:on_start).in_sequence(order)
172
+ spy.expects(:in_test).in_sequence(order)
173
+ spy.expects(:on_finish).in_sequence(order)
174
+
175
+ context "A context with both an `on_start` and `on_finish` block" do
176
+ on_finish do
177
+ spy.on_finish
178
+ end
179
+
180
+ on_start do
181
+ spy.on_start
182
+ end
183
+
184
+ should "allow those blocks to be defined in any order, but run them correctly" do
185
+ spy.in_test
186
+ end
187
+ end
188
+ end
189
+
190
+ def test_should_be_able_to_use_rspec_like_aliases
191
+ spy = test_spy
192
+
193
+ spy.expects(:in_before_all).in_sequence(order)
194
+ spy.expects(:in_test).in_sequence(order)
195
+ spy.expects(:in_after_all).in_sequence(order)
196
+
197
+ context "A context with `before_all` and `after_all` blocks" do
198
+ before_all do
199
+ spy.in_before_all
200
+ end
201
+
202
+ should "run exactly as `on_start` and `on_finish` blocks" do
203
+ spy.in_test
204
+ end
205
+
206
+ after_all do
207
+ spy.in_after_all
208
+ end
209
+ end
210
+ end
211
+
212
+ def test_should_be_able_to_run_things_once_before_any_tests_run
213
+ spy = test_spy
214
+
215
+ spy.expects(:before_all_tests).once.in_sequence(order)
216
+ spy.expects(:in_test).twice.in_sequence(order)
217
+
218
+ Kintama.reset
219
+ Kintama.on_start do
220
+ spy.before_all_tests
221
+ end
222
+
223
+ running_default_context "A context" do
224
+ should "have run the `before_all_tests` block before a test" do
225
+ spy.in_test
226
+ end
227
+
228
+ should "only run `before_all_tests` once" do
229
+ spy.in_test
230
+ end
231
+ end
232
+ end
233
+
234
+ def test_should_be_able_to_run_things_after_all_tests_have_run
235
+ spy = test_spy
236
+
237
+ spy.expects(:in_test).twice.in_sequence(order)
238
+ spy.expects(:after_all_tests).once.in_sequence(order)
239
+
240
+ Kintama.reset
241
+ Kintama.on_finish do
242
+ spy.after_all_tests
243
+ end
244
+
245
+ running_default_context "A context" do
246
+ should "have run the `before_all_tests` block before a test" do
247
+ spy.in_test
248
+ end
249
+
250
+ should "only run `after_all_tests` once all tests have finished" do
251
+ spy.in_test
252
+ end
253
+ end
254
+ end
255
+
256
+ private
257
+
258
+ def test_spy
259
+ stub('test spy', poke: nil)
260
+ end
261
+ end