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,55 @@
1
+ class MinispecTest::Expectations::Unit
2
+
3
+ should 'pass when caller matches given String' do
4
+ expect(o).to_receive(:a).with_caller([__FILE__, __LINE__ + 1]*':')
5
+ o.a
6
+ end
7
+ should ':fail when caller does NOT matches given String' do
8
+ expect(o).to_receive(:a).with_caller('blah')
9
+ o.a
10
+ end
11
+
12
+ should 'pass when caller validated by given Proc' do
13
+ expect(o).to_receive(:a).with_caller {|callers| callers[0].find {|l| l =~ /#{__FILE__}/}}
14
+ o.a
15
+ end
16
+ should ':fail when caller NOT validated by given Proc' do
17
+ expect(o).to_receive(:a).with_caller { false }
18
+ o.a
19
+ end
20
+
21
+ should 'pass when all callers matches given String' do
22
+ expect(o).to_receive(:a, :b).with_caller(__FILE__)
23
+ o.a
24
+ o.b
25
+ end
26
+ should ':fail when at least one caller does NOT match given String' do
27
+ expect(o).to_receive(:a, :b).with_caller('blah')
28
+ o.a
29
+ o.b
30
+ end
31
+
32
+ should 'pass when all callers validated by given Proc' do
33
+ expect(o).to_receive(:a, :b).with_caller do |a,b|
34
+ a[0].any? {|l| l =~ /#{__FILE__}/} && b[0].any? {|l| l =~ /#{__FILE__}/}
35
+ end
36
+ o.a
37
+ o.b
38
+ end
39
+ should ':fail when at least one caller NOT validated by given Proc' do
40
+ expect(o).to_receive(:a, :b).with_caller { false }
41
+ o.a
42
+ o.b
43
+ end
44
+
45
+ should 'pass when each caller matches its String' do
46
+ expect(o).to_receive(:a, :b).with_caller(__FILE__, [__FILE__, __LINE__ + 2]*':')
47
+ o.a
48
+ o.b
49
+ end
50
+ should ':fail when at least one caller does NOT match its String' do
51
+ expect(o).to_receive(:a, :b).with_caller(__FILE__, 'blah')
52
+ o.a
53
+ o.b
54
+ end
55
+ end
@@ -0,0 +1,35 @@
1
+ class MinispecTest::Expectations::Unit
2
+
3
+ should 'pass if message received' do
4
+ expect(o).to_receive(:a)
5
+ o.a
6
+ end
7
+
8
+ should ':fail if message not received' do
9
+ expect(o).to_receive(:a)
10
+ end
11
+
12
+ should 'pass when no message expected and none received' do
13
+ expect(o).to_not.receive(:a)
14
+ end
15
+
16
+ should ':fail when message received but not expected' do
17
+ expect(o).to_not.receive(:a)
18
+ o.a
19
+ end
20
+
21
+ should 'pass when no messages expected and none received' do
22
+ expect(o).to_not.receive(:a, :b)
23
+ end
24
+
25
+ should ':fail when at least one message received but not expected' do
26
+ expect(o).to_not.receive(:a, :b)
27
+ o.a
28
+ end
29
+
30
+ should ':fail when all messages received but not expected' do
31
+ expect(o).to_not.receive(:a, :b)
32
+ o.a
33
+ o.b
34
+ end
35
+ end
@@ -0,0 +1,46 @@
1
+ class MinispecTest::Expectations::Unit
2
+
3
+ should 'pass when messages received in expected order' do
4
+ expect(o).to_receive(:a, :b, :c).ordered
5
+ o.a
6
+ o.b
7
+ o.c
8
+ end
9
+
10
+ should 'pass when middle messages missing' do
11
+ expect(o).to_receive(:a, :c).ordered
12
+ o.a
13
+ # b intentionally not called to make sure it iterates only through expected messages
14
+ o.c
15
+ end
16
+
17
+ should ':fail when messages received in wrong order' do
18
+ expect(o).to_receive(:a, :b).ordered
19
+ o.b
20
+ o.c
21
+ o.a
22
+ end
23
+
24
+ should 'pass when same sequence repeated n times' do
25
+ expect(o).to_receive(:a, :b).ordered(2)
26
+ o.a
27
+ o.b
28
+ o.a
29
+ o.b
30
+ end
31
+
32
+ should ':fail when expected sequence not respected' do
33
+ expect(o).to_receive(:a, :b).ordered(2)
34
+ o.a
35
+ o.b
36
+ o.a
37
+ end
38
+
39
+ should ':fail when used with a single expected message' do
40
+ expect { expect(o).to_receive(:a).ordered }.raise(ArgumentError, /multiple/i)
41
+ end
42
+
43
+ should ':fail when a non-Integer given' do
44
+ expect { expect(o).to_receive(:a, :b).ordered('2') }.to_raise(ArgumentError, /integer/i)
45
+ end
46
+ end
@@ -0,0 +1,166 @@
1
+ class MinispecTest::Expectations
2
+ class Unit
3
+
4
+ begin # single expectation
5
+ should 'pass when raise expected and occurred' do
6
+ expect(o).to_receive(:r).and_raise
7
+ o.r rescue nil
8
+ end
9
+
10
+ should 'pass when raise not expected and not occurred' do
11
+ expect(o).to_receive(:a).without_raise
12
+ o.a
13
+ end
14
+
15
+ should ':fail when raise expected but not occurred' do
16
+ expect(o).to_receive(:a).and_raise
17
+ o.a
18
+ end
19
+
20
+ should ':fail when raise occurred but not expected' do
21
+ expect(o).to_receive(:r).without_raise
22
+ o.r rescue nil
23
+ end
24
+
25
+ should 'pass when raised an expected error' do
26
+ expect(o).to_receive(:r).and_raise(ArgumentError)
27
+ o.r rescue nil
28
+ end
29
+
30
+ should ':fail when raised an unexpected error' do
31
+ expect(o).to_receive(:r).and_raise(RuntimeError)
32
+ o.r rescue nil
33
+ o.r rescue nil
34
+ end
35
+
36
+ should 'pass when raised an expected message' do
37
+ expect(o).to_receive(:r).and_raise(ArgumentError, 'some blah')
38
+ o.r rescue nil
39
+ end
40
+
41
+ should 'pass when raised message matches expected one' do
42
+ expect(o).to_receive(:r).and_raise(ArgumentError, /blah/)
43
+ o.r rescue nil
44
+ end
45
+
46
+ should ':fail when raised an unexpected message' do
47
+ expect(o).to_receive(:r).and_raise(ArgumentError, 'another blah')
48
+ o.r rescue nil
49
+ end
50
+
51
+ should ':fail when raised message does not match expected one' do
52
+ expect(o).to_receive(:r).and_raise(ArgumentError, /x/)
53
+ o.r rescue nil
54
+ end
55
+
56
+ should 'pass when given block validates raised exception' do
57
+ expect(o).to_receive(:r).and_raise {|r| r.any? {|x| x.class == ArgumentError}}
58
+ o.r rescue nil
59
+ end
60
+
61
+ should ':fail when given block does not validate raised exception' do
62
+ expect(o).to_receive(:r).and_raise {false}
63
+ o.r rescue nil
64
+ end
65
+ end
66
+
67
+ begin # multiple expectations
68
+
69
+ should 'pass when one expectation used for all messages' do
70
+ expect(o).to_receive(:e, :r).and_raise(ArgumentError)
71
+ o.e rescue nil
72
+ o.r rescue nil
73
+ end
74
+ should 'pass when one expectation used for all messages and error matching used' do
75
+ expect(o).to_receive(:e, :r).and_raise([ArgumentError, 'some blah'])
76
+ o.e rescue nil
77
+ o.r rescue nil
78
+ end
79
+
80
+ should ':fail when one expectation used for all messages and type does not match' do
81
+ expect(o).to_receive(:e, :r).and_raise(Exception)
82
+ o.e rescue nil
83
+ o.r rescue nil
84
+ end
85
+
86
+ should ':fail when one expectation used for all messages, type matches but message does not' do
87
+ expect(o).to_receive(:e, :r).and_raise([ArgumentError, 'some error'])
88
+ o.e rescue nil
89
+ o.r rescue nil
90
+ end
91
+
92
+ should ':fail when one expectation used for all messages
93
+ and at least one message does not raise at all' do
94
+ expect(o).to_receive(:a, :r).and_raise(ArgumentError)
95
+ o.a
96
+ o.r rescue nil
97
+ end
98
+
99
+ should 'pass when each message uses own expectation' do
100
+ expect(o).to_receive(:e, :r).and_raise(ArgumentError, ArgumentError)
101
+ o.e rescue nil
102
+ o.r rescue nil
103
+ end
104
+
105
+ should ':fail when each message uses own expectation
106
+ and at least message does not raise as expected' do
107
+ expect(o).to_receive(:e, :r).and_raise(ArgumentError, Exception)
108
+ o.e rescue nil
109
+ o.r rescue nil
110
+ end
111
+
112
+ should ':fail when each message uses own expectation
113
+ and at least message does not raise at all' do
114
+ expect(o).to_receive(:a, :r).and_raise(ArgumentError, Exception)
115
+ o.a
116
+ o.r rescue nil
117
+ end
118
+
119
+ should 'pass when each message uses own expectation and error matching used' do
120
+ expect(o).to_receive(:e, :r).and_raise([ArgumentError, /blah/], [ArgumentError, /blah/])
121
+ o.e rescue nil
122
+ o.r rescue nil
123
+ end
124
+
125
+ should ':fail when each message uses own expectation and error matching used
126
+ and at least one message does not raise as expected' do
127
+ expect(o).to_receive(:e, :r).and_raise([ArgumentError, /blah/], [ArgumentError, /doh/])
128
+ o.e rescue nil
129
+ o.r rescue nil
130
+ end
131
+
132
+ should ':fail when at least one raise occurred but none expected' do
133
+ expect(o).to_receive(:a, :r).without_raise
134
+ o.a
135
+ o.r rescue nil
136
+ end
137
+
138
+ should ':fail when multiple raises expected but none occurred' do
139
+ expect(o).to_receive(:a, :b).and_raise
140
+ o.a
141
+ o.b
142
+ end
143
+
144
+ should 'pass when no raises expected and none occurred' do
145
+ expect(o).to_receive(:a, :b).without_raise
146
+ o.a
147
+ o.b
148
+ end
149
+
150
+ should 'pass when given block validates raised exceptions' do
151
+ expect(o).to_receive(:r, :e).and_raise do |r,e|
152
+ r.any? {|x| x.class == ArgumentError} &&
153
+ e.any? {|x| x.class == ArgumentError}
154
+ end
155
+ o.r rescue nil
156
+ o.e rescue nil
157
+ end
158
+
159
+ should ':fail when given block does not validate raised exceptions' do
160
+ expect(o).to_receive(:r, :e).and_raise {false}
161
+ o.r rescue nil
162
+ o.e rescue nil
163
+ end
164
+ end
165
+ end
166
+ end
@@ -0,0 +1,71 @@
1
+ class MinispecTest::Expectations::Unit
2
+
3
+ should 'pass when correct value returned' do
4
+ expect(o).to_receive(:a).and_return(:a)
5
+ o.a
6
+ end
7
+
8
+ should ':fail when wrong value returned' do
9
+ expect(o).to_receive(:a).and_return(:b)
10
+ o.a
11
+ end
12
+
13
+ should 'pass when proc validates returned value' do
14
+ expect(o).to_receive(:a).and_return {|r| r[0] == :a}
15
+ o.a
16
+ end
17
+
18
+ should 'yield multiple returned values when message received multiple times' do
19
+ expect(o).to_receive(:a).and_return {|r| r[0] == :a && r[1] == :a}
20
+ o.a
21
+ o.a
22
+ end
23
+
24
+ should ':fail when proc does not validate returned value' do
25
+ expect(o).to_receive(:a).and_return {false}
26
+ o.a
27
+ end
28
+
29
+ should 'pass when returned values matches expected ones' do
30
+ expect(o).to_receive(:a, :b).and_return(:a, :b)
31
+ o.a
32
+ o.b
33
+ end
34
+
35
+ should 'pass when all messages returns same value' do
36
+ expect(o).to_receive(:a, :z).and_return(:a)
37
+ o.a
38
+ o.z
39
+ end
40
+
41
+ should ':fail when a single value expected and a at least one message does not return it' do
42
+ expect(o).to_receive(:a, :b).and_return(:a)
43
+ o.a
44
+ o.b
45
+ end
46
+
47
+ should ':fail when at least one message returns a unexpected value' do
48
+ expect(o).to_receive(:a, :b).and_return(:a, :x)
49
+ o.a
50
+ o.b
51
+ end
52
+
53
+ should 'pass when proc validates returned values' do
54
+ expect(o).to_receive(:a, :b).and_return {|a,b| a[0] == :a && b[0] == :b}
55
+ o.a
56
+ o.b
57
+ end
58
+
59
+ should 'yield multiple returned values when multiple messages received multiple times' do
60
+ expect(o).to_receive(:a, :b).and_return {|a,b| a[0] == :a && a[1] == :a && b[0] == :b}
61
+ o.a
62
+ o.a
63
+ o.b
64
+ end
65
+
66
+ should ':fail when proc does not validate returned values' do
67
+ expect(o).to_receive(:a, :b).and_return {false}
68
+ o.a
69
+ o.b
70
+ end
71
+ end
@@ -0,0 +1,113 @@
1
+ class MinispecTest::Expectations::Unit
2
+
3
+ should 'pass when throw expected and occurred' do
4
+ expect(o).to_receive(:t).and_throw(:s)
5
+ o.t rescue nil
6
+ end
7
+
8
+ should ':fail when throw expected but not occurred' do
9
+ expect(o).to_receive(:a).and_throw(:s)
10
+ o.a
11
+ end
12
+
13
+ should ':fail when throw occurred but not expected' do
14
+ expect(o).to_receive(:t).without_throw
15
+ o.t rescue nil
16
+ end
17
+
18
+ should 'pass when throw not expected and not occurred' do
19
+ expect(o).to_receive(:a).without_throw
20
+ o.a
21
+ end
22
+
23
+ should 'pass when an expected symbol thrown' do
24
+ expect(o).to_receive(:t).and_throw :s
25
+ o.t rescue nil
26
+ end
27
+
28
+ should ':fail when thrown an unexpected symbol' do
29
+ expect(o).to_receive(:t).and_throw :x
30
+ o.t rescue nil
31
+ end
32
+
33
+ should 'pass when given block validates thrown symbol' do
34
+ expect(o).to_receive(:t).and_throw {|t| t[0] == :s}
35
+ o.t rescue nil
36
+ end
37
+
38
+ should ':fail when given block does not validate thrown symbol' do
39
+ expect(o).to_receive(:t).and_throw {false}
40
+ o.t rescue nil
41
+ end
42
+
43
+ should 'pass when given block validates thrown symbols' do
44
+ expect(o).to_receive(:t, :w).and_throw {|t,w| t[0] == :s && w[0] == :s}
45
+ o.t rescue nil
46
+ o.w rescue nil
47
+ end
48
+
49
+ should ':fail when given block does not validate thrown symbols' do
50
+ expect(o).to_receive(:t, :w).and_throw {false}
51
+ o.t rescue nil
52
+ o.w rescue nil
53
+ o.w rescue nil
54
+ end
55
+
56
+ should 'pass when all messages uses same expectation' do
57
+ expect(o).to_receive(:t, :w).and_throw :s
58
+ o.t rescue nil
59
+ o.w rescue nil
60
+ end
61
+
62
+ should ':fail when all messages uses same expectation
63
+ and at least one message throws a wrong symbol' do
64
+ expect(o).to_receive(:t, :w).and_throw :x
65
+ o.t rescue nil
66
+ o.w rescue nil
67
+ end
68
+
69
+ should ':fail when all messages uses same expectation
70
+ ad at least one message does not throw any symbol' do
71
+ expect(o).to_receive(:t, :z).and_throw :t
72
+ o.t rescue nil
73
+ o.z rescue nil
74
+ end
75
+
76
+ should 'pass when each message uses own expectation' do
77
+ expect(o).to_receive(:t, :w).and_throw :s, :s
78
+ o.t rescue nil
79
+ o.w rescue nil
80
+ end
81
+
82
+ should ':fail when each message uses own expectation
83
+ and at least one message does not throw as expected' do
84
+ expect(o).to_receive(:t, :w).and_throw :s, :x
85
+ o.t rescue nil
86
+ o.w rescue nil
87
+ end
88
+
89
+ should ':fail when each message uses own expectation
90
+ and at least one message does not throw at all' do
91
+ expect(o).to_receive(:t, :z).and_throw :s, :z
92
+ o.t rescue nil
93
+ o.z
94
+ end
95
+
96
+ should ':fail when at least one throw occurred but none expected' do
97
+ expect(o).to_receive(:a, :t).without_throw
98
+ o.a
99
+ o.t rescue nil
100
+ end
101
+
102
+ should ':fail when multiple thrown expected but none occurred' do
103
+ expect(o).to_receive(:a, :b).and_throw :s, :s
104
+ o.a
105
+ o.b
106
+ end
107
+
108
+ should 'pass when no thrown expected and none expected' do
109
+ expect(o).to_receive(:a, :b).without_throw
110
+ o.a
111
+ o.b
112
+ end
113
+ end