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
@@ -1,80 +0,0 @@
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_use_a_single_instance_of_the_subject_within_a_test
39
- c = context "x" do
40
- subject { Array.new }
41
- should "allow me to poke around with subject like it was a variable" do
42
- subject << 1
43
- assert_equal [1], subject
44
- end
45
- should "now be empty again" do
46
- assert subject.empty?
47
- end
48
- end
49
- c.run
50
- assert c.passed?
51
- end
52
-
53
- def test_should_allow_negation_of_matchers
54
- c = context "x" do
55
- subject { 123 }
56
- should_not EqualMatcher.new(123)
57
- end
58
- c.run
59
- assert !c.passed?
60
- assert_match /^Didn't expect 123, but got it anyway/, c.failures.first.failure_message
61
- end
62
-
63
- module MatcherExtension
64
- def be_equal_to(expected)
65
- EqualMatcher.new(expected)
66
- end
67
- end
68
-
69
- def test_should_allow_definition_of_matchers_in_contexts
70
- Kintama.extend(MatcherExtension)
71
- c = context "x" do
72
- subject { 'abc' }
73
- should be_equal_to('abc')
74
- should_not be_equal_to('def')
75
- end
76
- c.run
77
- assert c.passed?
78
- assert_equal ["should be equal to \"abc\"", "should not be equal to \"def\""], c.tests.map { |t| t.name }
79
- end
80
- end
@@ -1,176 +0,0 @@
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
@@ -1,20 +0,0 @@
1
- require 'test_helper'
2
-
3
- class PendingTest < Test::Unit::TestCase
4
-
5
- def test_should_pass_any_pending_tests
6
- c = context "Given a context" do
7
- test "that is not implemented"
8
- end
9
- c.run
10
- assert c.passed?
11
- end
12
-
13
- def test_should_ignore_empty_contexts
14
- c = context "Given an empty context" do
15
- context "should ignore this"
16
- end
17
- c.run
18
- assert c.passed?
19
- end
20
- end
@@ -1,107 +0,0 @@
1
- require 'test_helper'
2
-
3
- class SetupTest < Test::Unit::TestCase
4
-
5
- def test_should_allow_setup_to_provide_instance_variables
6
- x = context "Given something" do
7
- setup do
8
- @name = "james"
9
- end
10
- should "work" do
11
- assert_equal "james", @name
12
- end
13
- end
14
- x.run
15
- assert x.passed?
16
- end
17
-
18
- def test_should_run_setup_before_every_test
19
- x = context "Given something" do
20
- setup do
21
- @name = "james"
22
- end
23
- should "work" do
24
- @name += " is awesome"
25
- assert_equal "james is awesome", @name
26
- end
27
- should "also work" do
28
- @name += " is the best"
29
- assert_equal "james is the best", @name
30
- end
31
- end
32
- x.run
33
- assert x.passed?, x.failures.join(", ")
34
- end
35
-
36
- def test_should_allow_call_all_setup_methods_when_running_tests_in_a_nested_context
37
- x = context "Given something" do
38
- setup do
39
- @name = "james"
40
- end
41
- context "and another thing" do
42
- setup do
43
- @name += " is amazing"
44
- end
45
- should "work" do
46
- assert_equal "james is amazing", @name
47
- end
48
- end
49
- end
50
- x.run
51
- assert x.passed?
52
- end
53
-
54
- def test_should_only_run_necessary_setups_where_tests_at_different_nestings_exist
55
- x = context "Given something" do
56
- setup do
57
- @name = "james"
58
- end
59
- context "and another thing" do
60
- setup do
61
- @name += " is amazing"
62
- end
63
- should "work" do
64
- assert_equal "james is amazing", @name
65
- end
66
- end
67
- should "work" do
68
- assert_equal "james", @name
69
- end
70
- end
71
- x.run
72
- assert x.passed?
73
- end
74
-
75
- def test_should_run_setup_defined_on_kintama_itself_before_other_setups
76
- Kintama.setup do
77
- @thing = 'well then'
78
- end
79
- c = context "Given a context" do
80
- setup do
81
- assert_equal 'well then', @thing
82
- @thing = 'now then'
83
- end
84
- should "have run the setup defined in the default behaviour" do
85
- assert_equal 'now then', @thing
86
- end
87
- end
88
- c.run
89
- assert c.passed?, "@thing was not defined!"
90
- end
91
-
92
- def test_should_allow_multiple_setups_to_be_registered
93
- Kintama.setup do
94
- @thing = 1
95
- end
96
- Kintama.setup do
97
- @thing += 1
98
- end
99
- c = context "Given multiple setups" do
100
- should "run them all" do
101
- assert_equal 2, @thing
102
- end
103
- end
104
- c.run
105
- assert c.passed?, "both setups didn't run - #{c.failures.inspect}"
106
- end
107
- end
@@ -1,94 +0,0 @@
1
- require "test_helper"
2
-
3
- class StartAndFinishTest < Test::Unit::TestCase
4
-
5
- def test_should_call_any_on_start_block_when_running_a_context
6
- $ran = 0
7
- c = context "A context with a startup block" do
8
- on_start { $ran += 1 }
9
- should "have run the on_start block" do
10
- end
11
- end
12
- c.run
13
- assert_equal 1, $ran
14
- end
15
-
16
- def test_should_only_call_on_start_block_once_when_running_a_context
17
- $ran = 0
18
- c = context "A context with a startup block" do
19
- on_start { $ran += 1 }
20
- should "have run the on_start block" do
21
- end
22
- should "not run that block again" do
23
- end
24
- end
25
- c.run
26
- assert_equal 1, $ran
27
- end
28
-
29
- def test_should_only_call_on_start_block_before_any_test
30
- $ran = 0
31
- c = context "A context with a startup block" do
32
- on_start { $ran += 1 }
33
- should "have run the on_start block" do
34
- assert_equal 1, $ran
35
- end
36
- should "not run that block again" do
37
- assert_equal 1, $ran
38
- end
39
- end
40
- c.run
41
- assert c.passed?
42
- end
43
-
44
- def test_should_call_any_on_finish_block_when_running_a_context
45
- $ran = 0
46
- c = context "A context with a startup block" do
47
- should "have run the on_start block" do
48
- end
49
- on_finish { $ran += 1 }
50
- end
51
- c.run
52
- assert_equal 1, $ran
53
- end
54
-
55
- def test_should_only_call_on_finish_block_once_when_running_a_context
56
- $ran = 0
57
- c = context "A context with a startup block" do
58
- should "have run the on_start block" do
59
- end
60
- should "not run that block again" do
61
- end
62
- on_finish { $ran += 1 }
63
- end
64
- c.run
65
- assert_equal 1, $ran
66
- end
67
-
68
- def test_should_only_call_on_finish_block_after_all_tests
69
- $ran = 0
70
- c = context "A context with a startup block" do
71
- should "have run the on_start block" do
72
- assert_equal 0, $ran
73
- end
74
- should "not run that block again" do
75
- assert_equal 0, $ran
76
- end
77
- on_finish { $ran += 1 }
78
- end
79
- c.run
80
- assert c.passed?
81
- end
82
-
83
- def test_should_be_able_to_use_rspec_like_aliases
84
- $ran = 0
85
- c = context "A context with a startup block" do
86
- before_all { $ran += 1 }
87
- should "have run the on_start block" do
88
- end
89
- after_all { $ran += 1 }
90
- end
91
- c.run
92
- assert_equal 2, $ran
93
- end
94
- end