Skip to content

Commit 4dac295

Browse files
committed
add materials for Gem & Tests
Signed-off-by: Yury Kaliada <fut.wrk@gmail.com>
1 parent 93a60f1 commit 4dac295

File tree

6 files changed

+49
-20
lines changed

6 files changed

+49
-20
lines changed

materials/Ruby testing/minitest/benchmark-tests.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def self.bench_range
1111
def bench_time_to_next_station
1212
@train = Train.new
1313

14-
assert_performance_linear 0.9999 do |distance| # n is a range value
14+
assert_performance_linear 0.999 do |distance| # n is a range value
1515
@train.get_to_next_station(distance)
1616
end
1717
end

materials/Ruby testing/minitest/stub-tests.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ def setup
66
@train = Train.new
77
end
88

9-
def test_curent_time
10-
Time.stub :now, Time.now - 4 * 24 * 3600 do # stub goes away once the block is done
9+
def test_1pm
10+
Time.stub :now, 1PM do # stub goes away once the block is done
1111
assert_equal true, @train.will_arrive_by_the_end_of_the_day?(3 * 24 * 3600)
1212
end
1313
end

materials/Ruby testing/minitest/train.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def stop
1919
end
2020

2121
def get_to_next_station(distance)
22-
sleep 0.00002 * distance * Math.log(distance)
22+
sleep 0.00002 * distance
2323
end
2424

2525
def will_arrive_by_the_end_of_the_day?(tripDuration)

materials/Ruby testing/minitest/unit-tests.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def setup
99
end
1010

1111
def test_that_train_has_default_name
12-
assert_equal 'Uber train', @train.name
12+
assert_equal 'Uber train', @train.name
1313
end
1414

1515
def test_that_train_has_default_size

notes/11 - Ruby testing.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# Ruby testing
1+
# Starting
2+
3+
24

35

46
```

notes/6 - Gems.md

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,46 @@
1515

1616
## Гем
1717

18-
Each gem has a name, version, and platform
18+
Each gem has a name, version
1919

2020
## Составляющие
2121

2222
* Code (including tests and supporting utilities)
23+
* extconf
2324
* Documentation
2425
* gemspec
2526

27+
## Плюсы гемов в отличии от C библиотек
28+
29+
* Читаемость
30+
* Простота дополнения
31+
32+
## Как установить гем и где он окажется
33+
34+
Установить гем просто: `gem install colorize`
35+
36+
Его местонахождение определяется тем, какую систему контроля гемов вы используете.
37+
Рассмотрим rvm. Гемы окажутся в `~/.rvm/gems/ruby-2.1.5@my-gemset`.
38+
39+
Установка гема просто подразумевает под собой сохранение определенной версии гема.
40+
41+
42+
## Именование
43+
44+
* fancy_require => require 'fancy_require'
45+
* net-http-persistent => require 'net/http/persistent'
46+
* net-http-digest_auth => require 'net/http/digest_auth'
47+
* Don’t use UPPERCASE letters
48+
49+
## Версионирование
50+
```
51+
PATCH 0.0.x level changes for implementation level detail changes, such as small bug fixes
52+
MINOR 0.x.0 level changes for any backwards compatible API changes, such as new functionality/features
53+
MAJOR x.0.0 level changes for backwards incompatible API changes, such as changes that will break existing users code if they update
54+
```
55+
56+
Для просмотра документации конкретной версии не забываем включать верную версию на гитхабе.
57+
2658
## Структура
2759

2860
```
@@ -67,19 +99,6 @@ end
6799
4. `gem install ./my_gem.gem`
68100
5. `gem push hola-0.0.0.gem`
69101

70-
## Именование
71-
72-
* fancy_require => require 'fancy_require'
73-
* net-http-persistent => require 'net/http/persistent'
74-
* net-http-digest_auth => require 'net/http/digest_auth'
75-
* Don’t use UPPERCASE letters
76-
77-
## Версионирование
78-
```
79-
PATCH 0.0.x level changes for implementation level detail changes, such as small bug fixes
80-
MINOR 0.x.0 level changes for any backwards compatible API changes, such as new functionality/features
81-
MAJOR x.0.0 level changes for backwards incompatible API changes, such as changes that will break existing users code if they update
82-
```
83102

84103
## Gemfile & bundler
85104

@@ -250,6 +269,14 @@ DEPENDENCIES
250269
251270
```
252271

272+
## rubygems-bundler
273+
274+
Позволяет не писать bundle exec для каждой команды. Дело в том, что rubygems-bundler интегрирует функционал bundler-a в rubygems и заставляет ruby по дефолту запускать нужные версии гемов.
275+
276+
## RubyGems >= 2.2.0
277+
278+
В rubygems версии 2.2.0 и выше этот функционал включен по дефолту и гем rubygems-bundler уже не требуется. Используя переменную `RUBYGEMS_GEMDEPS` можно добиться того же результата что и с гемом `bundler`. Но в версии 2.2.0 не весь синтаксис Gemfile поддерживается, поэтому я бы побоялся переходить с бандлера на рубигемс прямо сейчас.
279+
253280
---
254281
# Домашнее задание
255282
Создать гем, который будет monkeypatch'ить объекты Time в руби и добавит функционал http://www.ruby-doc.org/core-2.1.4/Time.html#method-i-strftime

0 commit comments

Comments
 (0)