rabbit-slide-giosakti-201710-self-testing-code-ruby 2017.10.16.2 → 2017.10.16.3
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.
- checksums.yaml +4 -4
- data/config.yaml +1 -1
- data/pdf/201710-self-testing-code-ruby-201710-self-testing-code-ruby.pdf +0 -0
- data/self-testing-code-ruby.rab +168 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67641773ea0ae2e2df24a6e8c903bd0e8949af8c
|
4
|
+
data.tar.gz: 03bd50cc432e5d83990bb3aac2d1ddc78f7f8d4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 174dc1f065155cc99ee04b9e2a129d8cfd9ae177c391360e59b0edbb735f74a6089b17f68aed0027a47bc5862d01e56c5154fd962a441a48ae14756715f8b89f
|
7
|
+
data.tar.gz: 58ab452b078f9f726e290d657f95164bc214f9a165cc881a5b7a9d3d77d7e80e981670c1eb4ef3bae303390c548d2d22440e0ee54a193c4bfcb734444ead5bfa
|
data/config.yaml
CHANGED
Binary file
|
data/self-testing-code-ruby.rab
CHANGED
@@ -137,7 +137,7 @@ Now write just enough code to make it pass
|
|
137
137
|
end
|
138
138
|
end
|
139
139
|
|
140
|
-
= TDD with RSpec (3)
|
140
|
+
= TDD with RSpec (3) cont'd
|
141
141
|
|
142
142
|
Now write just enough code to make it pass
|
143
143
|
|
@@ -167,6 +167,173 @@ Run the example and the test shall pass
|
|
167
167
|
|
168
168
|
(('tag:center'))Repeat with new features
|
169
169
|
|
170
|
+
= RSpec API
|
171
|
+
|
172
|
+
(('tag:center'))Some important RSpec APIs
|
173
|
+
|
174
|
+
== properties
|
175
|
+
: hide-title
|
176
|
+
true
|
177
|
+
|
178
|
+
= Basic Matchers
|
179
|
+
# rouge ruby
|
180
|
+
|
181
|
+
# equality
|
182
|
+
expect('x'+'y').to eq('xy') # a == b
|
183
|
+
expect('x'+'y').to eql('xy') # a.eql?(b)
|
184
|
+
expect('x'+'y').not_to be('xy') # a.equal?(b)
|
185
|
+
|
186
|
+
# strings
|
187
|
+
expect('abcd').to include('bc')
|
188
|
+
expect('abcd').to start_with 'ab'
|
189
|
+
expect('abcd').to end_with 'cd'
|
190
|
+
expect('abcd').to match /[a-z]+/
|
191
|
+
|
192
|
+
# collections
|
193
|
+
expect([1, 2, 3]).to include(1, 3)
|
194
|
+
expect([1, 2, 3]).to contain_exactly(3, 2, 1) # order not important
|
195
|
+
expect({ a: 1, b: 2 }).to include(b: 2)
|
196
|
+
|
197
|
+
= Basic Matchers cont'd
|
198
|
+
|
199
|
+
# rouge ruby
|
200
|
+
|
201
|
+
# booleans and nil
|
202
|
+
expect(true).to be true
|
203
|
+
expect(false).to be false
|
204
|
+
expect('abc').to be_truthy
|
205
|
+
expect(nil).to be_falsey
|
206
|
+
expect(nil).to be_nil
|
207
|
+
|
208
|
+
# numeric
|
209
|
+
expect(5).to be > 4
|
210
|
+
expect(5).to be >= 4
|
211
|
+
expect(5).to be < 6
|
212
|
+
expect(5).to be <= 6
|
213
|
+
expect(5).to be_between(4, 6).exclusive
|
214
|
+
expect(5).to be_between(5, 6).inclusive
|
215
|
+
expect(4.99).to be_within(0.02).of(5)
|
216
|
+
|
217
|
+
# errors (exceptions)
|
218
|
+
expect{ 5 / 0 }.to raise_error(ZeroDivisionError)
|
219
|
+
expect{ 5 / 0 }.to raise_error("divided by 0")
|
220
|
+
expect{ 5 / 0 }.to raise_error(ZeroDivisionError, "divided by 0")
|
221
|
+
|
222
|
+
= Predicate Matchers
|
223
|
+
|
224
|
+
Predicate matchers are a little DSL for calling predicate methods. Predicate methods are methods that:
|
225
|
+
|
226
|
+
* return a boolean value; and
|
227
|
+
* have a name that ends with ?
|
228
|
+
|
229
|
+
= Predicate Matchers cont'd
|
230
|
+
|
231
|
+
# rouge ruby
|
232
|
+
|
233
|
+
# array
|
234
|
+
expect([]).to be_empty # [].empty?
|
235
|
+
|
236
|
+
# hash
|
237
|
+
expect({a: 1}).to have_key(:a) # {a: 1}.has_key?(:a)
|
238
|
+
expect({a: 1}).to have_value(1) # {a: 1}.has_value?(1)
|
239
|
+
|
240
|
+
# object
|
241
|
+
expect(5).not_to be_nil # 'hi'.nil?
|
242
|
+
expect(5).to be_instance_of Fixnum # 5.instance_of?(Fixnum)
|
243
|
+
expect(5).to be_kind_of Numeric # 5.kind_of?(Numeric)
|
244
|
+
|
245
|
+
= Predicate Matchers cont'd
|
246
|
+
|
247
|
+
Predicate matchers work on all objects, including custom classes
|
248
|
+
|
249
|
+
= Exercises
|
250
|
+
|
251
|
+
(('tag:center'))Now let's do some exercises...
|
252
|
+
|
253
|
+
== properties
|
254
|
+
: hide-title
|
255
|
+
true
|
256
|
+
|
257
|
+
= TDD Exercises (1)
|
258
|
+
|
259
|
+
Create a Sentence from Words\n
|
260
|
+
|
261
|
+
Without using "Array#each" iterator, create a method that will return a sentence when given an array of words.
|
262
|
+
|
263
|
+
# rouge ruby
|
264
|
+
|
265
|
+
create_sentence(["hello", "world"])
|
266
|
+
# will return: "hello world"
|
267
|
+
|
268
|
+
= TDD Exercises (2)
|
269
|
+
|
270
|
+
Find Palindromes
|
271
|
+
|
272
|
+
Write a method that receives two positive integers "m" and "n" and returns an array of "n" palindrome numbers after "m" (including "m" itself).
|
273
|
+
|
274
|
+
# rouge ruby
|
275
|
+
|
276
|
+
find_palindrome(100, 2)
|
277
|
+
# will return [101, 111]
|
278
|
+
|
279
|
+
find_palindrome(22, 3)
|
280
|
+
# will return [22, 33, 44]
|
281
|
+
|
282
|
+
= TDD Exercises (3)
|
283
|
+
|
284
|
+
Descending Order
|
285
|
+
|
286
|
+
Create a method that receives an integer as an argument and rearrange it to generate biggest possible value.
|
287
|
+
|
288
|
+
# rouge ruby
|
289
|
+
|
290
|
+
descending(21445) # will return 54421
|
291
|
+
descending(145263) # will return 654321
|
292
|
+
descending(1254859723) # will return 9875543221
|
293
|
+
|
294
|
+
= TDD Exercises (4)
|
295
|
+
|
296
|
+
Deep Count
|
297
|
+
|
298
|
+
Create a method called deep_count that will return the number of elements in an array, including the number of elements of its sub arrays.
|
299
|
+
|
300
|
+
= TDD Exercises (4) cont'd
|
301
|
+
|
302
|
+
# rouge ruby
|
303
|
+
|
304
|
+
deep_count([]) # will return 0
|
305
|
+
deep_count([1, 2, 3]) # will return 3
|
306
|
+
|
307
|
+
deep_count(["x", "y", ["z"]])
|
308
|
+
# will return 3 elements ("x", "y", ["z"]) in main array
|
309
|
+
# plus 1 element ("z") in sub array
|
310
|
+
# total = 4 elements
|
311
|
+
|
312
|
+
deep_count([1, 2, [3, 4, [5]]])
|
313
|
+
# total = 7 elements
|
314
|
+
|
315
|
+
deep_count([[[[[[[[[]]]]]]]]])
|
316
|
+
# total = 8 elements
|
317
|
+
|
318
|
+
= TDD Exercises (5)
|
319
|
+
|
320
|
+
Letter Count
|
321
|
+
|
322
|
+
Create a method that receives a string as its argument and returns a hash that shows the number of occurrence of each letter in that string.
|
323
|
+
|
324
|
+
= TDD Exercises (5) cont'd
|
325
|
+
|
326
|
+
# rouge ruby
|
327
|
+
|
328
|
+
letter_count("gojek")
|
329
|
+
# will return {:g=>1, :o=>1, :j=>1, :e=>1, :k=>1}
|
330
|
+
|
331
|
+
letter_count("kolla")
|
332
|
+
# will return {:k=>1, :o=>1, :l=>2, :a=>1}
|
333
|
+
|
334
|
+
letter_count("scholarship")
|
335
|
+
# will return {:s=>2, :c=>1, :h=>2, :o=>1, :l=>1, :a=>1, :r=>1, :i=>1, :p=>1}
|
336
|
+
|
170
337
|
= Thanks
|
171
338
|
|
172
339
|
(('tag:center'))Thanks
|