minispec 0.0.1

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 (83) hide show
  1. checksums.yaml +7 -0
  2. data/.pryrc +2 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE +22 -0
  5. data/README.md +2140 -0
  6. data/Rakefile +11 -0
  7. data/bin/minispec +4 -0
  8. data/lib/minispec.rb +175 -0
  9. data/lib/minispec/api.rb +2 -0
  10. data/lib/minispec/api/class.rb +195 -0
  11. data/lib/minispec/api/class/after.rb +49 -0
  12. data/lib/minispec/api/class/around.rb +54 -0
  13. data/lib/minispec/api/class/before.rb +101 -0
  14. data/lib/minispec/api/class/helpers.rb +116 -0
  15. data/lib/minispec/api/class/let.rb +44 -0
  16. data/lib/minispec/api/class/tests.rb +33 -0
  17. data/lib/minispec/api/instance.rb +158 -0
  18. data/lib/minispec/api/instance/mocks/doubles.rb +36 -0
  19. data/lib/minispec/api/instance/mocks/mocks.rb +319 -0
  20. data/lib/minispec/api/instance/mocks/spies.rb +17 -0
  21. data/lib/minispec/api/instance/mocks/stubs.rb +105 -0
  22. data/lib/minispec/helpers.rb +1 -0
  23. data/lib/minispec/helpers/array.rb +56 -0
  24. data/lib/minispec/helpers/booleans.rb +108 -0
  25. data/lib/minispec/helpers/generic.rb +24 -0
  26. data/lib/minispec/helpers/mocks/expectations.rb +29 -0
  27. data/lib/minispec/helpers/mocks/spies.rb +36 -0
  28. data/lib/minispec/helpers/raise.rb +44 -0
  29. data/lib/minispec/helpers/throw.rb +29 -0
  30. data/lib/minispec/mocks.rb +11 -0
  31. data/lib/minispec/mocks/expectations.rb +77 -0
  32. data/lib/minispec/mocks/stubs.rb +178 -0
  33. data/lib/minispec/mocks/validations.rb +80 -0
  34. data/lib/minispec/mocks/validations/amount.rb +63 -0
  35. data/lib/minispec/mocks/validations/arguments.rb +161 -0
  36. data/lib/minispec/mocks/validations/caller.rb +43 -0
  37. data/lib/minispec/mocks/validations/order.rb +47 -0
  38. data/lib/minispec/mocks/validations/raise.rb +111 -0
  39. data/lib/minispec/mocks/validations/return.rb +74 -0
  40. data/lib/minispec/mocks/validations/throw.rb +91 -0
  41. data/lib/minispec/mocks/validations/yield.rb +141 -0
  42. data/lib/minispec/proxy.rb +201 -0
  43. data/lib/minispec/reporter.rb +185 -0
  44. data/lib/minispec/utils.rb +139 -0
  45. data/lib/minispec/utils/differ.rb +325 -0
  46. data/lib/minispec/utils/pretty_print.rb +51 -0
  47. data/lib/minispec/utils/raise.rb +123 -0
  48. data/lib/minispec/utils/throw.rb +140 -0
  49. data/minispec.gemspec +27 -0
  50. data/test/mocks/expectations/amount.rb +67 -0
  51. data/test/mocks/expectations/arguments.rb +126 -0
  52. data/test/mocks/expectations/caller.rb +55 -0
  53. data/test/mocks/expectations/generic.rb +35 -0
  54. data/test/mocks/expectations/order.rb +46 -0
  55. data/test/mocks/expectations/raise.rb +166 -0
  56. data/test/mocks/expectations/return.rb +71 -0
  57. data/test/mocks/expectations/throw.rb +113 -0
  58. data/test/mocks/expectations/yield.rb +109 -0
  59. data/test/mocks/spies/amount.rb +68 -0
  60. data/test/mocks/spies/arguments.rb +57 -0
  61. data/test/mocks/spies/generic.rb +61 -0
  62. data/test/mocks/spies/order.rb +38 -0
  63. data/test/mocks/spies/raise.rb +158 -0
  64. data/test/mocks/spies/return.rb +71 -0
  65. data/test/mocks/spies/throw.rb +113 -0
  66. data/test/mocks/spies/yield.rb +101 -0
  67. data/test/mocks/test__doubles.rb +98 -0
  68. data/test/mocks/test__expectations.rb +27 -0
  69. data/test/mocks/test__mocks.rb +197 -0
  70. data/test/mocks/test__proxies.rb +61 -0
  71. data/test/mocks/test__spies.rb +43 -0
  72. data/test/mocks/test__stubs.rb +427 -0
  73. data/test/proxified_asserts.rb +34 -0
  74. data/test/setup.rb +53 -0
  75. data/test/test__around.rb +58 -0
  76. data/test/test__assert.rb +510 -0
  77. data/test/test__before_and_after.rb +117 -0
  78. data/test/test__before_and_after_all.rb +71 -0
  79. data/test/test__helpers.rb +197 -0
  80. data/test/test__raise.rb +104 -0
  81. data/test/test__skip.rb +41 -0
  82. data/test/test__throw.rb +103 -0
  83. metadata +196 -0
@@ -0,0 +1,117 @@
1
+ class MinispecTest
2
+ class Hooks < self
3
+
4
+ BEFORE, AFTER = {}, {}
5
+ EXPECTED = {
6
+ [:*] => [:jazz, :blues, :rhythm_and_blues],
7
+ jazz: [[:*], [:jazz]],
8
+ blues: [[:*], [/blues/], [/blues/, {:except=>/rhythm/}]],
9
+ rhythm_and_blues: [[:*], [/blues/]]
10
+ }.freeze
11
+
12
+ class Before
13
+ include Minispec
14
+
15
+ before do |test, matcher|
16
+ update_status(test, matcher)
17
+ update_status(matcher, test)
18
+ end
19
+
20
+ before :jazz do |test, matcher|
21
+ update_status(test, matcher)
22
+ end
23
+
24
+ before /blues/ do |test, matcher|
25
+ update_status(test, matcher)
26
+ end
27
+
28
+ before /blues/, except: /rhythm/ do |test, matcher|
29
+ update_status(test, matcher)
30
+ end
31
+
32
+ test :jazz do
33
+ end
34
+
35
+ test :blues do
36
+ end
37
+
38
+ test :rhythm_and_blues do
39
+ end
40
+
41
+ private
42
+ def update_status test, matcher
43
+ (BEFORE[test] ||= []).push(matcher)
44
+ end
45
+ end
46
+ msrun(Before)
47
+
48
+ class After
49
+ include Minispec
50
+
51
+ after do |test, matcher|
52
+ update_status(test, matcher)
53
+ update_status(matcher, test)
54
+ end
55
+
56
+ after :jazz do |test, matcher|
57
+ update_status(test, matcher)
58
+ end
59
+
60
+ after /blues/ do |test, matcher|
61
+ update_status(test, matcher)
62
+ end
63
+
64
+ after /blues/, except: /rhythm/ do |test, matcher|
65
+ update_status(test, matcher)
66
+ end
67
+
68
+ test :jazz do
69
+ end
70
+
71
+ test :blues do
72
+ end
73
+
74
+ test :rhythm_and_blues do
75
+ end
76
+
77
+ private
78
+ def update_status test, matcher
79
+ (AFTER[test] ||= []).push(matcher)
80
+ end
81
+ end
82
+ msrun(After)
83
+
84
+ def test_before_any
85
+ assert_equal BEFORE[[:*]], EXPECTED[[:*]]
86
+ end
87
+
88
+ def test_after_any
89
+ assert_equal AFTER[[:*]], EXPECTED[[:*]]
90
+ end
91
+
92
+ def test_before_jazz
93
+ assert_equal BEFORE[:jazz], EXPECTED[:jazz]
94
+ end
95
+
96
+ def test_after_jazz
97
+ assert_equal AFTER[:jazz], EXPECTED[:jazz]
98
+ end
99
+
100
+ def test_before_blues
101
+ assert_equal BEFORE[:blues], EXPECTED[:blues]
102
+ end
103
+
104
+ def test_after_blues
105
+ assert_equal AFTER[:blues], EXPECTED[:blues]
106
+ end
107
+
108
+ def test_before_rhythm_and_blues
109
+ assert_equal BEFORE[:rhythm_and_blues], EXPECTED[:rhythm_and_blues]
110
+ end
111
+
112
+ def test_after_rhythm_and_blues
113
+ assert_equal AFTER[:rhythm_and_blues], EXPECTED[:rhythm_and_blues]
114
+ end
115
+
116
+ end
117
+ end
@@ -0,0 +1,71 @@
1
+ class MinispecTest
2
+ class BeforeAllTest < self
3
+
4
+ X, Y = [], []
5
+ module BeforeAll
6
+ include Minispec
7
+
8
+ before_all do
9
+ X << self.class
10
+ end
11
+ end
12
+
13
+ class BeforeAllInherited
14
+ include BeforeAll
15
+ end
16
+
17
+ def test_inherited_boot
18
+ msrun(BeforeAllInherited)
19
+ assert X.include?(BeforeAllInherited)
20
+ end
21
+
22
+ class BeforeAllInheritedAndOverriden
23
+ include BeforeAll
24
+
25
+ before_all do
26
+ Y << self.class
27
+ end
28
+ end
29
+
30
+ def test_override_inherited_boot
31
+ msrun(BeforeAllInheritedAndOverriden)
32
+ refute X.include?(BeforeAllInheritedAndOverriden)
33
+ assert Y.include?(BeforeAllInheritedAndOverriden)
34
+ end
35
+ end
36
+
37
+ class AfterAllTest < self
38
+
39
+ X, Y = [], []
40
+ module AfterAll
41
+ include Minispec
42
+
43
+ after_all do
44
+ X << self.class
45
+ end
46
+ end
47
+
48
+ class AfterAllInherited
49
+ include AfterAll
50
+ end
51
+
52
+ def test_inherited_after_all
53
+ msrun(AfterAllInherited)
54
+ assert X.include?(AfterAllInherited)
55
+ end
56
+
57
+ class AfterAllInheritedAndOverriden
58
+ include AfterAll
59
+
60
+ after_all do
61
+ Y << self.class
62
+ end
63
+ end
64
+
65
+ def test_override_inherited_after_all
66
+ msrun(AfterAllInheritedAndOverriden)
67
+ refute X.include?(AfterAllInheritedAndOverriden)
68
+ assert Y.include?(AfterAllInheritedAndOverriden)
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,197 @@
1
+ class MinispecTest
2
+ class Helpers < self
3
+
4
+ class TrueTest
5
+ include Minispec
6
+
7
+ testing :true? do
8
+ is(true).true?
9
+ end
10
+ should ':fail' do
11
+ is(:blah).true?
12
+ end
13
+ end
14
+ define_tests(TrueTest)
15
+
16
+ class PositiveTest
17
+ include Minispec
18
+
19
+ testing :positive? do
20
+ is(true).positive?
21
+ is(:something).positive?
22
+ is('anything').positive?
23
+ end
24
+ should ':fail when nil' do
25
+ is(nil).positive?
26
+ end
27
+ should ':fail when false' do
28
+ is(false).positive?
29
+ end
30
+ end
31
+ define_tests(PositiveTest)
32
+
33
+ class FalseTest
34
+ include Minispec
35
+
36
+ testing :false? do
37
+ is(false).false?
38
+ end
39
+ should ':fail' do
40
+ is(:blah).false?
41
+ end
42
+ end
43
+ define_tests(FalseTest)
44
+
45
+ class FalsyTest
46
+ include Minispec
47
+
48
+ testing :nil do
49
+ is(nil).falsy?
50
+ end
51
+ testing :false do
52
+ is(false).falsy?
53
+ end
54
+ should ':fail' do
55
+ is(:something).falsy?
56
+ end
57
+ end
58
+ define_tests(FalsyTest)
59
+
60
+ class ArrayTest
61
+ include Minispec
62
+
63
+ testing :same_elements do
64
+ a1 = [1, 2, :a, :b, :c]
65
+ a2 = [:b, 1, :c, 2, :a]
66
+ assert(a1).has.same_elements_as a2
67
+ end
68
+ should 'raise if non-Array given' do
69
+ does { assert('').has.same_elements '' }.raise? ArgumentError, /Array\?/
70
+ end
71
+ should 'raise if right array missing' do
72
+ does { assert([]).has.same_elements }.raise? ArgumentError
73
+ end
74
+ should ':fail if arrays size vary' do
75
+ assert([1]).has.same_elements [1,2]
76
+ end
77
+ should ':fail if arrays elements vary' do
78
+ assert([:a, :b]).has.same_elements [:x, :y]
79
+ end
80
+ end
81
+ define_tests(ArrayTest)
82
+
83
+ class ContainTest
84
+ include Minispec
85
+
86
+ should 'work with integers' do
87
+ does([1, 2, 5, 6]).contain? 1, 2
88
+ end
89
+ should 'work with floats' do
90
+ does([1.2, 2]).contain? 1.2
91
+ end
92
+ should 'work with strings' do
93
+ does([1.2, '2', 5, 4]).contain? '2', 4
94
+ end
95
+ should 'work with regexps' do
96
+ does([1.2, 'abc', 8, 9]).contain? /b/, 9
97
+ end
98
+ should ':fail if no element found' do
99
+ does([1, 2]).contain? :a
100
+ end
101
+ should ':fail if no element matched' do
102
+ does([:a, :b]).contain? /x/
103
+ end
104
+ should 'raise if non-Array given' do
105
+ does { assert(:blah).contain? :blah }.raise? ArgumentError
106
+ end
107
+ end
108
+ define_tests(ContainTest)
109
+
110
+ class ContainAnyTest
111
+ include Minispec
112
+
113
+ should 'work with integers' do
114
+ does([1, 2, 5, 6]).contain_any? 1, 8
115
+ end
116
+ should 'work with floats' do
117
+ does([4, 2]).contain_any? 2
118
+ end
119
+ should 'work with strings' do
120
+ does([1.2, '2', 5, 4]).contain_any? '2', 4
121
+ end
122
+ should 'work with regexps' do
123
+ does([1.2, 'abc', 8]).contain_any? /b/, 9
124
+ end
125
+ should ':fail if no element found' do
126
+ does([1, 2]).contain_any? :a
127
+ end
128
+ should ':fail if no element matched' do
129
+ does([:a, :b]).contain_any? /x/
130
+ end
131
+ should 'raise if non-Array given' do
132
+ does { assert(:blah).contain_any? :blah }.raise? ArgumentError
133
+ end
134
+ end
135
+ define_tests(ContainAnyTest)
136
+
137
+ class SilentTest
138
+ include Minispec
139
+
140
+ should 'pass' do
141
+ is { '' }.silent?
142
+ end
143
+
144
+ should ':fail because of stdout' do
145
+ assert { puts 'something' }.is_silent
146
+ end
147
+
148
+ should ':fail because of stderr' do
149
+ assert { warn 'something' }.is_silent
150
+ end
151
+
152
+ should 'pass when it is not silent and not expected to' do
153
+ assert { puts 'something' }.is_not.silent
154
+ end
155
+
156
+ should ':fail when it is silent but not expected to' do
157
+ assert { }.is_not.silent
158
+ end
159
+ end
160
+ define_tests(SilentTest)
161
+
162
+ class LeftBlockTest
163
+ include Minispec
164
+
165
+ helper :blank? do |block|
166
+ is(&block).empty?
167
+ end
168
+
169
+ should 'pass' do
170
+ is { '' }.blank?
171
+ end
172
+
173
+ should ':fail' do
174
+ is { '-' }.blank?
175
+ end
176
+ end
177
+ define_tests(LeftBlockTest)
178
+
179
+ class RightBlockTest
180
+ include Minispec
181
+
182
+ helper :any_value? do |obj, block|
183
+ assert(obj).any?(&block)
184
+ end
185
+
186
+ should 'pass' do
187
+ has([1, 2]).any_value? {|v| v > 1}
188
+ end
189
+
190
+ should ':fail' do
191
+ has([1, 2]).any_value? {|v| v > 5}
192
+ end
193
+ end
194
+ define_tests(RightBlockTest)
195
+
196
+ end
197
+ end
@@ -0,0 +1,104 @@
1
+ class MinispecTest
2
+ class Raise < self
3
+
4
+ class Unit
5
+ include Minispec
6
+ continue_on_failures true
7
+
8
+ begin
9
+ should 'pass when error raised and expected' do
10
+ does { blah }.raise_error?
11
+ end
12
+
13
+ should ':fail when error expected but NOT raised' do
14
+ does { :blah }.raise_error?
15
+ end
16
+
17
+ should 'pass when NO error expected and NO error raised' do
18
+ refute { }.raise_error
19
+ end
20
+
21
+ should ':fail when error raised but NOT expected' do
22
+ refute { Blah }.raise_error
23
+ end
24
+ should ':fail when error raised but NOT expected - alternative syntax' do
25
+ assure { Blah }.does_not.raise_error
26
+ end
27
+ end
28
+
29
+ begin
30
+ should 'pass when raised error type match expected error type' do
31
+ expect { Blah }.to_raise_error NameError
32
+ end
33
+
34
+ should ':fail when raised error type match expected error type but negation used' do
35
+ refute { Blah }.raise NameError
36
+ assure { Blah }.does_not.raise NameError
37
+ end
38
+
39
+ should ':fail when raised error type DOES NOT match expected error type' do
40
+ does { Blah }.raise_error? StandardError
41
+ end
42
+ end
43
+
44
+ begin # error message as first argument
45
+ should 'pass when raised error message is equal to expected one' do
46
+ does { Blah }.raise_error? 'uninitialized constant MinispecTest::Raise::Unit::Blah'
47
+ end
48
+
49
+ should ':fail when raised error message is NOT equal to expected one' do
50
+ does { Blah }.raise_error? 'Blah'
51
+ end
52
+
53
+ should 'pass when raised error message match expected error message' do
54
+ does { Blah }.raise_error? /uninitialized constant/
55
+ end
56
+
57
+ should ':fail when raised error message match expected error message but negation used' do
58
+ refute { Blah }.raise_error /uninitialized constant/
59
+ assure { Blah }.does_not.raise /uninitialized constant/
60
+ end
61
+
62
+ should ':fail when raised error message DOES NOT match expected error message' do
63
+ does { Blah }.raise_error? 'something that Ruby would never throw'
64
+ end
65
+ end
66
+
67
+ begin # error message as second argument
68
+ should 'pass when raised error matches expected one' do
69
+ does { Blah }.raise_error? NameError, /uninitialized constant/
70
+ end
71
+
72
+ should ':fail when raised error match expected error but negation used' do
73
+ refute { Blah }.raise_error? NameError, /uninitialized constant/
74
+ assure { Blah }.does_not.raise NameError, /uninitialized constant/
75
+ end
76
+
77
+ should ':fail when type matching and message DOES NOT' do
78
+ does { Blah }.raise_error? NameError, 'something that Ruby would never throw'
79
+ end
80
+
81
+ should ':fail when message matching and type DOES NOT' do
82
+ does { Blah }.raise_error? ArgumentError, 'Blah'
83
+ end
84
+ end
85
+
86
+ begin # using a block to validate raised error
87
+ should 'pass when given block validates raised error' do
88
+ e_class = NameError
89
+ expect { Blah }.to_raise {|e| e.class == e_class }
90
+ end
91
+
92
+ should ':fail when given block does not validate raised error' do
93
+ expect { Blah }.to_raise {false}
94
+ end
95
+ end
96
+
97
+ should 'raise ArgumentError when both arguments and block given' do
98
+ does { expect { }.to_raise(NameError) {} }.raise? ArgumentError
99
+ end
100
+ end
101
+
102
+ define_tests(Unit)
103
+ end
104
+ end