-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_classes.rb
More file actions
264 lines (202 loc) · 3.7 KB
/
test_classes.rb
File metadata and controls
264 lines (202 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
require 'digest/md5'
class Fibonacci
def fib(n)
return 0 if (n == 0)
return 1 if (n == 1)
return 1 if (n == 2)
return fib(n - 1) + fib(n - 2)
end
def self.say_hello
"hello"
end
end
class Meme
def i_can_has_cheezburger?
"OHAI!"
end
def will_it_blend?
"YES!"
end
end
class TestClassMethodMissing
def method_missing(method, *args, &block)
if (method == :handled_by_method_missing)
return "YOU GOT ME!!!!"
else
super(method, *args, &block)
end
end
end
class TestClass1
SOME_CONSTANT = 'Yes this is a constant'
def initialize(message)
@message = message
end
def set_block(&block)
@block = block
end
def call_block
@block.call(@message)
end
def message
@message
end
def just_returns_true
true
end
def print_message
puts @message
end
def invoke_class
@message.print_message
end
def something_is_wrong
fail StandardError
end
def return_self(message)
message
end
end
class TestClass2
def initialize(message, message2)
@message = {message: message}
end
def print_message
puts @message[:message]
end
def test(object)
object
end
end
class TestClass3
def initialize(testclass1, testclass2)
@class1 = testclass1
@class2 = testclass2
end
def show_messages
@class1.print_message
@class2.print_message
"awesome!!!"
end
def change_message(message)
"#{message}!"
end
def swap_hash(j, &block)
h = []
j.each do |k,v|
h << block.call(v,k)
end
h
end
def check_proc
@class2.call(1,2,3)
end
end
class TestClass4
def initialize(&block)
@message = block.call
end
def message
@message
end
def to_s
@message
end
end
class TestClass5
def test_method
fibonacci = Fibonacci.new
fibonacci.fib(5)
end
def test_method2
fibonacci = Fibonacci.new
fibonacci.fib(9)
end
def self.class_test_method
fibonacci = Fibonacci.new
fibonacci.fib(6)
end
end
class TestMockSubClass
def initialize
@val = 1
end
def test_method
"a return string"
end
def increment_val
@val += 1
@val
end
def return_hash(message)
{val: @val, str: "hello world", message: message}
end
end
class TestClassForMocks
def initialize
@test_class2 = TestMockSubClass.new
end
def message(params1)
@params1 = params1
end
def method_with_assign=(params2)
@params2 = "#{params2}!"
@params2
end
def method_with_usage
@test_class2.test_method
end
def method_with_usage2
results = []
results << @test_class2.increment_val
results << @test_class2.increment_val
results << @test_class2.increment_val
results << @test_class2.increment_val
results
end
def method_with_usage4
@test_class2.test_method
@test_class2.test_method
@test_class2.test_method
end
def method_with_usage3(message)
@test_class2.return_hash(message)
end
end
class ClassUsedByTestClass
def stubbed_method
"Hello Glorious world"
end
end
class AnotherClassUsedByTestClass
def get_message
"HI THERE!!!!"
end
end
class TestClassForAutoStub
def initialize
@class_to_be_used = ClassUsedByTestClass.new
@class_to_be_used2 = AnotherClassUsedByTestClass.new
end
def method_that_uses_the_class_to_stub
@class_to_be_used
@class_to_be_used2
return_values = []
return_values << @class_to_be_used.stubbed_method
return_values << @class_to_be_used2.get_message
return_values
end
end
class TestClassR1
SOME_CONSTANT = "CONST"
def hello
end
end
class TestClassR2
def hello_again
"hi"
end
def pass_message(message)
"#{message} #{TestClassR1::SOME_CONSTANT}"
end
end