minispec 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
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,71 @@
1
+ class MinispecTest::Spies::Unit
2
+
3
+ should 'pass when correct value returned' do
4
+ o.a
5
+ expect(o).received(:a).and_returned(:a)
6
+ end
7
+
8
+ should ':fail when wrong value returned' do
9
+ o.a
10
+ expect(o).received(:a).and_returned(:b)
11
+ end
12
+
13
+ should 'pass when proc validates returned value' do
14
+ o.a
15
+ expect(o).received(:a).and_returned {|r| r == [:a]}
16
+ end
17
+
18
+ should 'yield multiple returned values when message received multiple times' do
19
+ o.a
20
+ o.a
21
+ expect(o).received(:a).and_returned {|r| r == [:a, :a]}
22
+ end
23
+
24
+ should ':fail when proc does not validate returned value' do
25
+ o.a
26
+ expect(o).received(:a).and_returned {|r| false}
27
+ end
28
+
29
+ should 'pass when returned values matches expected ones' do
30
+ o.a
31
+ o.b
32
+ expect(o).received(:a, :b).and_returned(:a, :b)
33
+ end
34
+
35
+ should 'pass when all messages returns same value' do
36
+ o.a
37
+ o.z
38
+ expect(o).received(:a, :z).and_returned(:a)
39
+ end
40
+
41
+ should ':fail when a single value expected and a at least one message does not return it' do
42
+ o.a
43
+ o.b
44
+ expect(o).received(:a, :b).and_returned(:a)
45
+ end
46
+
47
+ should ':fail when at least one message does not return what expected' do
48
+ o.a
49
+ o.b
50
+ expect(o).received(:a, :b).and_returned(:a, :x)
51
+ end
52
+
53
+ should 'pass when proc validates returned values' do
54
+ o.a
55
+ o.b
56
+ expect(o).received(:a, :b).and_returned {|a,b| a == [:a] && b == [:b]}
57
+ end
58
+
59
+ should 'yield multiple returned values when multiple messages received multiple times' do
60
+ o.a
61
+ o.a
62
+ o.b
63
+ expect(o).received(:a, :b).and_returned {|a,b| a == [:a, :a] && b == [:b]}
64
+ end
65
+
66
+ should ':fail when proc does not validate returned values' do
67
+ o.a
68
+ o.b
69
+ expect(o).received(:a, :b).and_returned {|a| false}
70
+ end
71
+ end
@@ -0,0 +1,113 @@
1
+ class MinispecTest::Spies::Unit
2
+
3
+ should 'pass when throw expected and occurred' do
4
+ o.t rescue nil
5
+ expect(o).received(:t).and_throw :s
6
+ end
7
+
8
+ should ':fail when throw expected but not occurred' do
9
+ o.a
10
+ expect(o).received(:a).and_throw :s
11
+ end
12
+
13
+ should ':fail when throw occurred but not expected' do
14
+ o.t rescue nil
15
+ expect(o).received(:t).without_throw
16
+ end
17
+
18
+ should 'pass when throw not expected and not occurred' do
19
+ o.a
20
+ expect(o).received(:a).without_throw
21
+ end
22
+
23
+ should 'pass when an expected symbol thrown' do
24
+ o.t rescue nil
25
+ expect(o).received(:t).and_throw :s
26
+ end
27
+
28
+ should ':fail when thrown an unexpected symbol' do
29
+ o.t rescue nil
30
+ expect(o).received(:t).and_throw :x
31
+ end
32
+
33
+ should 'pass when given block validates thrown symbol' do
34
+ o.t rescue nil
35
+ expect(o).received(:t).and_throw {|t| t == [:s]}
36
+ end
37
+
38
+ should ':fail when given block does not validate thrown symbol' do
39
+ o.t rescue nil
40
+ expect(o).received(:t).and_throw {false}
41
+ end
42
+
43
+ should 'pass when given block validates thrown symbols' do
44
+ o.t rescue nil
45
+ o.w rescue nil
46
+ expect(o).received(:t, :w).and_throw {|t,w| t == [:s] && w == [:s]}
47
+ end
48
+
49
+ should ':fail when given block does not validate thrown symbols' do
50
+ o.t rescue nil
51
+ o.w rescue nil
52
+ expect(o).received(:t, :w).and_throw {false}
53
+ end
54
+
55
+ should 'pass when all messages uses same expectation' do
56
+ o.t rescue nil
57
+ o.w rescue nil
58
+ expect(o).received(:t, :w).and_throw :s
59
+ end
60
+
61
+ should ':fail when all messages uses same expectation
62
+ and at least one message throws a wrong symbol' do
63
+ o.t rescue nil
64
+ o.w rescue nil
65
+ expect(o).received(:t, :w).and_throw :x
66
+ end
67
+
68
+ should ':fail when all messages uses same expectation
69
+ ad at least one message does not throw any symbol' do
70
+ o.t rescue nil
71
+ o.z
72
+ expect(o).received(:t, :z).and_throw :t
73
+ end
74
+
75
+ should 'pass when each message uses own expectation' do
76
+ o.t rescue nil
77
+ o.w rescue nil
78
+ expect(o).received(:t, :w).and_throw :s, :s
79
+ end
80
+
81
+ should ':fail when each message uses own expectation
82
+ and at least one message does not throw as expected' do
83
+ o.t rescue nil
84
+ o.w rescue nil
85
+ expect(o).received(:t, :w).and_throw :s, :x
86
+ end
87
+
88
+ should ':fail when each message uses own expectation
89
+ and at least one message does not throw at all' do
90
+ o.t rescue nil
91
+ o.z
92
+ expect(o).received(:t, :z).and_throw :t, :z
93
+ end
94
+
95
+ should ':fail when at least one throw occurred but none expected' do
96
+ o.a
97
+ o.t rescue nil
98
+ expect(o).received(:a, :t).without_throw
99
+ end
100
+
101
+ should ':fail when multiple thrown expected but none occurred' do
102
+ o.a
103
+ o.b
104
+ expect(o).received(:a, :b).and_throw :s, :s
105
+ end
106
+
107
+ should 'pass when no thrown expected and none expected' do
108
+ o.a
109
+ o.b
110
+ expect(o).received(:a, :b).without_throw
111
+ end
112
+
113
+ end
@@ -0,0 +1,101 @@
1
+ class MinispecTest::Spies::Unit
2
+
3
+ should 'pass when yield expected and occurred' do
4
+ o.y {|a,b|}
5
+ expect(o).received(:y).and_yield
6
+ end
7
+
8
+ should 'pass when yield not expected and not occurred' do
9
+ o = Class.new { def y; end }.new
10
+ proxy(o, :y)
11
+ o.y
12
+ expect(o).received(:y).without_yield
13
+ end
14
+
15
+ should ':fail when yield expected but not occurred' do
16
+ o.a
17
+ expect(o).received(:a).and_yield
18
+ end
19
+
20
+ should ':fail when yield occurred but not expected' do
21
+ o.y {|a,b|}
22
+ expect(o).received(:y).without_yield
23
+ end
24
+
25
+ should 'pass when yielded with expected arguments' do
26
+ o.y {|a, b|}
27
+ expect(o).received(:y).and_yield(1, 2)
28
+ end
29
+
30
+ should ':fail when yielded with wrong arguments' do
31
+ o.y {|a, b|}
32
+ expect(o).received(:y).and_yield(4, 5)
33
+ end
34
+
35
+ should 'pass when proc validates yielded arguments' do
36
+ o.y {|a, b|}
37
+ expect(o).received(:y).and_yield {|args| args == [[1, 2]]}
38
+ end
39
+
40
+ should ':fail when proc does not validate yielded arguments' do
41
+ o.y {|a, b|}
42
+ expect(o).received(:y).and_yield {|a,b| false}
43
+ end
44
+
45
+ should 'not raise when arity not respected and proc used' do
46
+ refute { o.y {|a|} }.raise
47
+ expect(o).received(:y)
48
+ end
49
+
50
+ should 'use same expectation for all messages' do
51
+ o.y {|a,b|}
52
+ o.x {|a,b|}
53
+ expect(o).received(:y, :x).and_yield([1, 2])
54
+ end
55
+
56
+ should 'pass when multiple yielded arguments match expected ones' do
57
+ o.y {|a,b|}
58
+ o.x {|a,b|}
59
+ expect(o).received(:y, :x).and_yield([1, 2], [1, 2])
60
+ end
61
+
62
+ should 'work well when multiple Array arguments yielded' do
63
+ o.define_singleton_method(:Y) {|&b| b.call([1, [2]])}
64
+ proxy(o, :Y)
65
+ o.Y {|a,b|}
66
+ o.x {|a,b|}
67
+ expect(o).received(:Y, :x).and_yield([[[1, [2]]]], [1, 2])
68
+ end
69
+
70
+ should 'pass when proc validates multiple yielded arguments' do
71
+ o.define_singleton_method(:Y) {|&b| b.call([1, [2]])}
72
+ proxy(o, :Y)
73
+ o.Y {|a,b|}
74
+ o.x {|a,b|}
75
+ expect(o).received(:Y, :x).and_yield {|y,x| y == [[[1, [2]]]] && x == [[1, 2]]}
76
+ end
77
+
78
+ should ':fail when multiple yielded arguments does not match expected ones' do
79
+ o.y {|a,b|}
80
+ o.x {|a,b|}
81
+ expect(o).received(:y, :x).and_yield(1, 0)
82
+ end
83
+
84
+ should ':fail when proc does not validate multiple yielded arguments' do
85
+ o.y {|a,b|}
86
+ o.x {|a,b|}
87
+ expect(o).received(:y, :x).and_yield {|*a| false}
88
+ end
89
+
90
+ should ':fail when multiple yields expected but none occurred' do
91
+ o.a
92
+ o.b
93
+ expect(o).received(:a, :b).and_yield
94
+ end
95
+
96
+ should ':fail when at least one yield occurred but none expected' do
97
+ o.a {}
98
+ o.x {|a,b|}
99
+ expect(o).received(:a, :x).without_yield
100
+ end
101
+ end
@@ -0,0 +1,98 @@
1
+ class MinispecTest
2
+ class Stubs < self
3
+ class Unit
4
+ include Minispec
5
+
6
+ it 'uses first argument as name' do
7
+ d = double(:a, :b)
8
+ is(d.inspect) == :a
9
+ end
10
+
11
+ it 'creates anonymous doubles when no args given' do
12
+ d = double
13
+ does(d.inspect) =~ /#<Object/
14
+ end
15
+
16
+ it 'uses first argument as name and rest as stubs' do
17
+ d = double(:a, :b, :c)
18
+ is(d.inspect) == :a
19
+ refute(d).respond_to?(:a)
20
+ does(d).respond_to?(:b)
21
+ does(d).respond_to?(:c)
22
+ end
23
+
24
+ it 'uses hashes for stubs' do
25
+ a = double(:a, b: :c)
26
+ is(a.b) == :c
27
+ end
28
+
29
+ it 'uses given block for returned value' do
30
+ a = double(:a, :b) {:c}
31
+ is(a.b) == :c
32
+ end
33
+
34
+ it 'creates public stubs' do
35
+ d = double(:a, :b)
36
+ does(d.public_methods).include?(:b)
37
+ end
38
+
39
+ it 'creates private stubs' do
40
+ d = double
41
+ private_stub(d, :a)
42
+ does(d.private_methods).include?(:a)
43
+ does { d.a }.raise? NoMethodError, /private method\W+a/
44
+ end
45
+
46
+ it 'creates protected stubs' do
47
+ d = double
48
+ protected_stub(d, :a)
49
+ does(d.protected_methods).include?(:a)
50
+ does { d.a }.raise? NoMethodError, /protected method\W+a/
51
+ end
52
+
53
+ it 'defines chained stubs' do
54
+ @a = nil
55
+ d = double(:chained, 'a.b.c') {|*a| @a = true; a}
56
+
57
+ does(d).respond_to?(:a)
58
+ d.a
59
+ is(@a).nil?
60
+
61
+ does(d.a).respond_to?(:b)
62
+ d.a.b
63
+ is(@a).nil?
64
+
65
+ does(d.a.b).respond_to?(:c)
66
+ expect(d.a.b.c(:x, :y)).to_contain :x, :y
67
+ is(@a).true?
68
+ end
69
+
70
+ it 'plays well with expectations' do
71
+ d = double(:dbl, :a)
72
+ expect(d).to_receive(:a)
73
+ d.a
74
+ end
75
+
76
+ class SomeError < ArgumentError; end
77
+ it 'plays well with raise expectations' do
78
+ d = double(:dbl, :a) { raise SomeError }
79
+ expect(d).to_receive(:a).and_raise SomeError
80
+ d.a rescue nil
81
+ end
82
+
83
+ it 'plays well with throw expectations' do
84
+ d = double(:dbl, :a) { throw :ArgumentError }
85
+ expect(d).to_receive(:a).and_throw :ArgumentError
86
+ d.a rescue nil
87
+ end
88
+
89
+ it 'plays well with yield expectations' do
90
+ d = double(:dbl, :a) { |&b| b.call :x }
91
+ expect(d).to_receive(:a).and_yield :x
92
+ d.a {|a|}
93
+ end
94
+ end
95
+
96
+ define_tests(Unit)
97
+ end
98
+ end
@@ -0,0 +1,27 @@
1
+ class MinispecTest
2
+ class Expectations < self
3
+
4
+ class O
5
+ def a(*a); :a; end
6
+ def b(*a); :b; end
7
+ def c(*a); :c; end
8
+ def d; :d; end
9
+ def e; raise(ArgumentError, 'some blah'); end
10
+ def r; raise(ArgumentError, 'some blah'); end
11
+ def t; throw(:s); end
12
+ def w; throw(:s); end
13
+ def x(&b); yield(1, 2); end
14
+ def y(&b); yield(1, 2); end
15
+ def z; :a; end
16
+ end
17
+
18
+ class Unit
19
+ include Minispec
20
+ continue_on_failures true
21
+ let(:o) { O.new }
22
+ end
23
+
24
+ Dir[File.expand_path('../expectations/*.rb', __FILE__)].each {|f| require(f)}
25
+ define_tests(Unit)
26
+ end
27
+ end
@@ -0,0 +1,197 @@
1
+ class MinispecTest
2
+ class Mocks < self
3
+ class Unit
4
+ include Minispec
5
+
6
+ let(:o) { Object.new }
7
+
8
+ it 'creates a stub that returns nil' do
9
+ mock(o, :a)
10
+ is(o.a).nil?
11
+ end
12
+
13
+ it 'creates a stub that returns a value' do
14
+ mock(o, :a) {:a}
15
+ is(o.a) == :a
16
+ end
17
+
18
+ it 'is mocking using a Hash' do
19
+ mock(o, a: :x, b: :y)
20
+ does(o).respond_to?(:a)
21
+ is(o.a) == :x
22
+ does(o).respond_to?(:b)
23
+ is(o.b) == :y
24
+ end
25
+
26
+ it 'raise ArgumentError when using constraints on Hash mocks' do
27
+ does { mock(o, a: :b).with(1) {1} }.raise?(ArgumentError, /can not be used/i)
28
+ # though error raised, methods should be successfully mocked
29
+ assert(o.a) == :b
30
+ end
31
+
32
+ it ':fails if expectation not met' do
33
+ mock(o, :a)
34
+ end
35
+
36
+ it 'calls various stubs depending on given args' do
37
+ mock(o, :a){0}
38
+ mock(o, :a).with(1) {1}
39
+ mock(o, :a).with(2) {2}
40
+ is(o.a) == 0
41
+ is(o.a(1)) == 1
42
+ is(o.a(2)) == 2
43
+ end
44
+
45
+ it 'is mocking private methods' do
46
+ private_mock(o, :a)
47
+ does(o.private_methods).include?(:a)
48
+ does { o.a }.raise? NoMethodError, /private method\W+a/
49
+ o.send(:a)
50
+ end
51
+
52
+ it 'mocking private methods using a Hash' do
53
+ private_mock(o, a: :b)
54
+ does(o.private_methods).include?(:a)
55
+ does { o.a }.raise? NoMethodError, /private method\W+a/
56
+ assert(o.send(:a)) == :b
57
+ end
58
+
59
+ it 'is mocking protected methods' do
60
+ protected_mock(o, :a)
61
+ does(o.protected_methods).include?(:a)
62
+ does { o.a }.raise? NoMethodError, /protected method\W+a/
63
+ o.send(:a)
64
+ end
65
+
66
+ it 'mocking protected methods using a Hash' do
67
+ protected_mock(o, a: :b)
68
+ does(o.protected_methods).include?(:a)
69
+ does { o.a }.raise? NoMethodError, /protected method\W+a/
70
+ assert(o.send(:a)) == :b
71
+ end
72
+
73
+ it 'keeps the visibility of existing methods' do
74
+ o = Class.new do
75
+ def a; end
76
+ protected
77
+ def b; p :blah; end
78
+ private
79
+ def c; end
80
+ end.new
81
+
82
+ mock(o, :a)
83
+ o.send(:a)
84
+ does(o.public_methods).include?(:a)
85
+
86
+ mock(o, :b)
87
+ o.send(:b)
88
+ does(o.protected_methods).include?(:b)
89
+
90
+ mock(o, :c)
91
+ o.send(:c)
92
+ does(o.private_methods).include?(:c)
93
+ end
94
+
95
+ it 'uses `with_any` with a block to define a catchall return' do
96
+ mock(o, :a).
97
+ with(1) { :one }.
98
+ with_any { :A }
99
+ assert(o.a) == :A
100
+ assert(o.a(:blah)) == :A
101
+ assert(o.a(1)) == :one
102
+ end
103
+
104
+ it 'uses `with_any` with a value to define a catchall return' do
105
+ mock(o, :a).
106
+ with(1) { :one }.
107
+ with_any(:A)
108
+ assert(o.a) == :A
109
+ assert(o.a(:blah)) == :A
110
+ assert(o.a(1)) == :one
111
+ end
112
+
113
+ it 'is mocking multiple methods at once' do
114
+ mocks(o, :a, :b)
115
+ does(o).respond_to?(:a)
116
+ does(o).respond_to?(:b)
117
+ o.a
118
+ o.b
119
+ end
120
+
121
+ it 'is mocking multiple methods at once and :fail if a least one message not received' do
122
+ mocks(o, :a, :b)
123
+ o.a
124
+ # o.b intentionally commented
125
+ end
126
+
127
+ it 'uses given block for all mocks' do
128
+ mocks(o, :a, :b) {:x}
129
+ assert(o.a) == :x
130
+ assert(o.b) == :x
131
+ end
132
+
133
+ it 'uses same constraints for all mocks' do
134
+ mocks(o, :a, :b).
135
+ with(1) {:one}.
136
+ with(2) {:two}.
137
+ with_any(:any)
138
+
139
+ assert(o.a) == :any
140
+ assert(o.a(:what, :ever)) == :any
141
+
142
+ assert(o.b) == :any
143
+ assert(o.b(:blah)) == :any
144
+
145
+ assert(o.a(1)) == :one
146
+ assert(o.b(1)) == :one
147
+
148
+ assert(o.a(2)) == :two
149
+ assert(o.b(2)) == :two
150
+ o.a
151
+ o.b
152
+ end
153
+
154
+ it 'defines multiple private stubs' do
155
+ private_mocks(o, :a, :b)
156
+ does(o.private_methods).include?(:a)
157
+ does(o.private_methods).include?(:b)
158
+ does { o.a }.raise? NoMethodError, /private method\W+a/
159
+ does { o.b }.raise? NoMethodError, /private method\W+b/
160
+ o.send(:a)
161
+ o.send(:b)
162
+ end
163
+
164
+ it 'defines multiple protected stubs' do
165
+ protected_mocks(o, :a, :b)
166
+ does(o.protected_methods).include?(:a)
167
+ does(o.protected_methods).include?(:b)
168
+ does { o.a }.raise? NoMethodError, /protected method\W+a/
169
+ does { o.b }.raise? NoMethodError, /protected method\W+b/
170
+ o.send(:a)
171
+ o.send(:b)
172
+ end
173
+
174
+ it 'enforces public visibility on protected methods' do
175
+ o = Class.new do
176
+ protected
177
+ def a; end
178
+ end.new
179
+ does { o.a }.raise? NoMethodError, /protected method\W+a/
180
+ public_mock(o, :a) { :a }
181
+ assert(o.a) == :a
182
+ end
183
+
184
+ it 'enforces public visibility on private methods' do
185
+ o = Class.new do
186
+ private
187
+ def a; end
188
+ end.new
189
+ does { o.a }.raise? NoMethodError, /private method\W+a/
190
+ public_mock(o, :a) { :a }
191
+ assert(o.a) == :a
192
+ end
193
+ end
194
+
195
+ define_tests(Unit)
196
+ end
197
+ end