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.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/lib/kintama.rb +19 -5
  3. data/lib/kintama/assertions.rb +4 -0
  4. data/lib/kintama/context.rb +58 -47
  5. data/lib/kintama/mocha.rb +13 -0
  6. data/lib/kintama/no_conflict.rb +2 -0
  7. data/lib/kintama/reporter.rb +3 -3
  8. data/test/{automatic_running_test.rb → integration/automatic_running_test.rb} +5 -5
  9. data/test/{line_based_running_test.rb → integration/line_based_running_test.rb} +13 -13
  10. data/test/reporters/base_reporter_test.rb +31 -101
  11. data/test/reporters/inline_reporter_test.rb +23 -35
  12. data/test/reporters/verbose_reporter_test.rb +77 -76
  13. data/test/test_helper.rb +92 -0
  14. data/test/{assertions_test.rb → unit/assertions_test.rb} +8 -0
  15. data/test/unit/context_test.rb +15 -0
  16. data/test/unit/runner_test.rb +87 -0
  17. data/test/{test_and_subcontext_access_test.rb → unit/test_and_subcontext_access_test.rb} +5 -32
  18. data/test/usage/01_basic_usage_test.rb +131 -0
  19. data/test/usage/02_setup_test.rb +98 -0
  20. data/test/usage/03_teardown_test.rb +120 -0
  21. data/test/usage/04_pending_tests_test.rb +16 -0
  22. data/test/usage/05_aliases_test.rb +73 -0
  23. data/test/usage/06_defining_methods_in_tests_test.rb +202 -0
  24. data/test/usage/07_exceptions_test.rb +42 -0
  25. data/test/usage/08_start_and_finish_test.rb +252 -0
  26. data/test/usage/09_expectations_and_mocking_test.rb +86 -0
  27. data/test/usage/10_let_and_subject_test.rb +125 -0
  28. data/test/usage/11_matcher_test.rb +148 -0
  29. data/test/usage/12_action_test.rb +118 -0
  30. metadata +36 -42
  31. data/test/aliases_test.rb +0 -26
  32. data/test/exceptions_test.rb +0 -40
  33. data/test/kintama_test.rb +0 -114
  34. data/test/matcher_test.rb +0 -80
  35. data/test/method_behaviour_test.rb +0 -176
  36. data/test/pending_test_and_context.rb +0 -20
  37. data/test/setup_test.rb +0 -107
  38. data/test/start_and_finish_test.rb +0 -94
  39. 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,252 @@
1
+ require "test_helper"
2
+
3
+ class StartAndFinishTest < KintamaIntegrationTest
4
+
5
+ def setup
6
+ @order = sequence('order')
7
+ end
8
+ attr_reader :order
9
+
10
+ def test_should_call_any_on_start_block_when_running_a_context
11
+ spy = test_spy
12
+
13
+ spy.expects(:in_startup).in_sequence(order)
14
+ spy.expects(:in_test).in_sequence(order)
15
+
16
+ context "A context with an `on_start` block" do
17
+ on_start do
18
+ spy.in_startup
19
+ end
20
+
21
+ should "have run the `on_start` block before a test" do
22
+ spy.in_test
23
+ end
24
+ end
25
+ end
26
+
27
+ def test_should_only_call_on_start_block_once_when_running_a_context
28
+ spy = test_spy
29
+
30
+ spy.expects(:in_startup).once.in_sequence(order)
31
+ spy.expects(:in_test).twice.in_sequence(order)
32
+
33
+ context "A context with an `on_start` block" do
34
+ on_start do
35
+ spy.in_startup
36
+ end
37
+
38
+ should "have run the `on_start` block before a test" do
39
+ spy.in_test
40
+ end
41
+
42
+ should "not run that block again before a second test" do
43
+ spy.in_test
44
+ end
45
+ end
46
+ end
47
+
48
+ def test_should_call_on_start_block_in_nested_contexts
49
+ spy = test_spy
50
+
51
+ spy.expects(:outer_startup).once.in_sequence(order)
52
+ spy.expects(:inner_startup).once.in_sequence(order)
53
+ spy.expects(:in_test).twice.in_sequence(order)
54
+
55
+ context "A context with an `on_start` block" do
56
+ on_start do
57
+ spy.outer_startup
58
+ end
59
+
60
+ context "and another `on_start` block in a nested context" do
61
+ on_start do
62
+ spy.inner_startup
63
+ end
64
+
65
+ should "have run both `on_start` blocks before running any tests" do
66
+ spy.in_test
67
+ end
68
+
69
+ should "not run either `on_start` blocks before running subsequent tests" do
70
+ spy.in_test
71
+ end
72
+ end
73
+ end
74
+ end
75
+
76
+ def test_should_call_any_on_finish_block_when_running_a_context
77
+ spy = test_spy
78
+
79
+ spy.expects(:in_test).in_sequence(order)
80
+ spy.expects(:in_finish).in_sequence(order)
81
+
82
+ context "A context with an `on_finish` block" do
83
+ should "not run the `on_finish` block before the test" do
84
+ spy.in_test
85
+ end
86
+
87
+ on_finish do
88
+ spy.in_finish
89
+ end
90
+ end
91
+ end
92
+
93
+ def test_should_only_call_on_finish_block_once_when_running_a_context
94
+ spy = test_spy
95
+
96
+ spy.expects(:in_test).twice.in_sequence(order)
97
+ spy.expects(:in_finish).once.in_sequence(order)
98
+
99
+ context "A context with an `on_finish` block" do
100
+ should "not be run after every test" do
101
+ spy.in_test
102
+ end
103
+
104
+ should "really not be run after every test" do
105
+ spy.in_test
106
+ end
107
+
108
+ on_finish do
109
+ spy.in_finish
110
+ end
111
+ end
112
+ end
113
+
114
+ def test_should_only_call_on_finish_block_after_all_tests
115
+ spy = test_spy
116
+
117
+ spy.expects(:in_test).times(3).in_sequence(order)
118
+ spy.expects(:in_finish).once.in_sequence(order)
119
+
120
+ context "A context with an `on_finish` block" do
121
+ should "have not run the `on_finish` block before the first test" do
122
+ spy.in_test
123
+ end
124
+
125
+ should "have not run the `on_finish` block before the second test" do
126
+ spy.in_test
127
+ end
128
+
129
+ should "have not run the `on_finish` block before the third test" do
130
+ spy.in_test
131
+ end
132
+
133
+ on_finish do
134
+ spy.in_finish
135
+ end
136
+ end
137
+ end
138
+
139
+ def test_should_call_on_finish_block_in_nested_contexts
140
+ spy = test_spy
141
+
142
+ spy.expects(:in_test).twice.in_sequence(order)
143
+ spy.expects(:inner_finish).once.in_sequence(order)
144
+ spy.expects(:outer_finish).once.in_sequence(order)
145
+
146
+ context "A context with an `on_finish` block" do
147
+ context "and another `on_finish` block in a nested context" do
148
+ should "not run either `on_finish` blocks before running the first test" do
149
+ spy.in_test
150
+ end
151
+
152
+ should "not run either `on_start` blocks before running subsequent tests" do
153
+ spy.in_test
154
+ end
155
+
156
+ on_finish do
157
+ spy.inner_finish
158
+ end
159
+ end
160
+
161
+ on_finish do
162
+ spy.outer_finish
163
+ end
164
+ end
165
+ end
166
+
167
+ def test_should_not_rely_on_any_ordering_to_register_on_start_or_on_finish_blocks
168
+ spy = test_spy
169
+
170
+ spy.expects(:on_start).in_sequence(order)
171
+ spy.expects(:in_test).in_sequence(order)
172
+ spy.expects(:on_finish).in_sequence(order)
173
+
174
+ context "A context with both an `on_start` and `on_finish` block" do
175
+ on_finish do
176
+ spy.on_finish
177
+ end
178
+
179
+ on_start do
180
+ spy.on_start
181
+ end
182
+
183
+ should "allow those blocks to be defined in any order, but run them correctly" do
184
+ spy.in_test
185
+ end
186
+ end
187
+ end
188
+
189
+ def test_should_be_able_to_use_rspec_like_aliases
190
+ spy = test_spy
191
+
192
+ spy.expects(:in_before_all).in_sequence(order)
193
+ spy.expects(:in_test).in_sequence(order)
194
+ spy.expects(:in_after_all).in_sequence(order)
195
+
196
+ context "A context with `before_all` and `after_all` blocks" do
197
+ before_all do
198
+ spy.in_before_all
199
+ end
200
+
201
+ should "run exactly as `on_start` and `on_finish` blocks" do
202
+ spy.in_test
203
+ end
204
+
205
+ after_all do
206
+ spy.in_after_all
207
+ end
208
+ end
209
+ end
210
+
211
+ def test_should_be_able_to_run_things_once_before_any_tests_run
212
+ spy = test_spy
213
+
214
+ spy.expects(:before_all_tests).once.in_sequence(order)
215
+ spy.expects(:in_test).in_sequence(order)
216
+
217
+ Kintama.reset
218
+ Kintama.on_start do
219
+ spy.before_all_tests
220
+ end
221
+
222
+ running_default_context "A context" do
223
+ should "have run the `before_all_tests` block before a test" do
224
+ spy.in_test
225
+ end
226
+ end
227
+ end
228
+
229
+ def test_should_be_able_to_run_things_after_all_tests_have_run
230
+ spy = test_spy
231
+
232
+ spy.expects(:in_test).in_sequence(order)
233
+ spy.expects(:after_all_tests).once.in_sequence(order)
234
+
235
+ Kintama.reset
236
+ Kintama.on_finish do
237
+ spy.after_all_tests
238
+ end
239
+
240
+ running_default_context "A context" do
241
+ should "have run the `before_all_tests` block before a test" do
242
+ spy.in_test
243
+ end
244
+ end
245
+ end
246
+
247
+ private
248
+
249
+ def test_spy
250
+ stub('test spy', poke: nil)
251
+ end
252
+ end