Quality Assurance - Based on TDD example

Agnieszka Matysek at Fractal Soft

Notes: - Agnieszka Matysek - nowe technologie w rolnictwie - 8 lat doświadczenia - team leader, mentor - współwłaściciel firmy Fractal Soft - zainteresowania: good code standard, refactoring, testing
Notes: - przykłady Ruby - pracuje i lubię ten język
Notes: - nie do opanowania, nie do ogarnięcia - strach przed zmianą - wołamy o pomoc

Quality Asurance
?
Tests

“QA and Testing both have to make software better, but QA enhances the quality via an improvement of development process and testing enhances it via finding bugs.”

Quality Asurance
>
Tests

Two examples

Test-Driven Development

TDD

Example 1

Follow your test

#### Create method ```ruby def flush? end ```
#### Add argument ```ruby def flush?(array) end ```

Add first logic

```ruby def flush?(array) true end ```

Run test

```bash $ rspec spec/lib/flush_spec.rb Randomized with seed 40116 . Finished in 0.01189 seconds (files took 0.65796 seconds to load) 1 example, 0 failures ```

CSI: NY

Triangulation based on CSI: NY series

Add more logic

```ruby def flush?(array) array.uniq.size == 1 end ```

Run tests

```bash $ rspec spec/lib/flush_spec.rb Randomized with seed 33907 .. Finished in 0.01092 seconds (files took 0.57891 seconds to load) 2 examples, 0 failures ```
#### Write code ```ruby class BaseClass def self.validates_presence_of(name) end def self.validates_numericality_of(name) end def valid? end end ```
#### Write code ```ruby class BaseClass def self.validates_presence_of(name) end def self.validates_numericality_of(name) end def valid? end def errors end end ```
#### Run test ```bash $ ruby item_test.rb Run options: --seed 35483 # Running: . Finished in 0.000730s, 1369.7898 runs/s, 12328.1085 assertions/s. 1 runs, 9 assertions, 0 failures, 0 errors, 0 skips ``` Notes: - test przechodzi - 5-10 min - działający kod - czas na refaktoring
## Small fixes
```ruby class BaseClass def self.validates_presence_of(name) end def self.validates_numericality_of(name) end def valid? @errors_list = [] @errors_list << "name can't be blank" if @name.nil? @errors_list << "price must be number" unless @price.is_a?(Integer) @errors_list.size == 0 end def errors @errors_list end end ``` Notes: - naiwna implementacja - **zaleta** - działa - **zaleta** - zrozumiała - **wada** - trudna do utrzymania - **wada** - nieadaptuje się do zmian
```ruby class BaseClass attr_reader :errors def self.validates_presence_of(name) @validators ||= [] @validators << PresenceValidator.new(name) end def self.validates_numericality_of(name) @validators ||= [] @validators << NumericallityValidator.new(name) end def valid? @errors = [] self.class.instance_variable_get(:@validators).each do |item| errors << item.error_message unless item.valid?(send(item.name)) end errors.empty? end private attr_writer :errors end ``` Notes: - elastyczny kod - ławiejsza rozszerzalność - ciągle czytelny

Running tests

How looks console when all tests passed - rainbow style.

Nyan Cat

Running test in Nyan Cat style.
Notes: - mój projekt jest inny - testy jak z oszczędzaniem - plan dalekosiężny - krótkowzroczne, instant gratification - to co zaoszczędzisz teraz, stracisz później

Gilded Rose Kata

Kata

github.com/emilybache/GildedRose-Refactoring-Kata

Fractal Soft logo

Fractal Soft

We're hiring!
Rails Girls heart

Rails Girls

CoderDojo logo
CoderDojo Poland logo
Woman on Rails logo

womanonrails.com/presentations

### Ruby Testing Tools - [Minitest](https://github.com/seattlerb/minitest) - [RSpec](https://rspec.info/) - [Capybara](https://teamcapybara.github.io/capybara/) - [Cucumber](https://cucumber.io/) - [Bacon](https://github.com/chneukirchen/bacon) - [Riot](https://github.com/thumblemonks/riot) - [Assert](https://github.com/redding/assert) - [Fix](https://github.com/fixrb/fix)
### Books - [Test Driven Development: By Example - Ken Beck](https://helion.pl/view/10301k/tddszt.htm#format/d) - [The Pragmatic Programmer: From Journeyman to Master - Andrew Hund, David Thomas](https://helion.pl/view/10301k/pragpv.htm#format/d) - [Clean Code: A Handbook of Agile Software Craftsmanship - Robert C. Martin](https://helion.pl/view/10301k/czykov.htm#format/d) - [Design Patterns in Ruby - Russ Olsen](https://helion.pl/view/10301k/rubywz.htm#format/d) - [Practical Object-Oriented Design in Ruby: An Agile Primer - Sandi Metz](https://www.amazon.com/Practical-Object-Oriented-Design-Ruby-Addison-Wesley/dp/0321721330)
### Presentations - [All the Little Things by Sandi Metz](https://www.youtube.com/watch?v=8bZh5LMaSmE) - [Nothing is Something by Sandi Metz](https://www.youtube.com/watch?v=OMPfEXIlTVE) - [Best Ruby on Rails refactoring talks](https://infinum.co/the-capsized-eight/best-ruby-on-rails-refactoring-talks) - [Are you an Egoistic Programmer? - presentation about refactoring](https://womanonrails.com/presentation-refactoring-egoistic-programmer/#1)
Woman on Rails logotype

Agnieszka Matysek

agnieszka (at) fractalsoft (dot) org