Rspec Tweaks

19
Rspec Tweaks Ombu Labs, January 2016

Transcript of Rspec Tweaks

Page 1: Rspec Tweaks

Rspec TweaksOmbu Labs, January 2016

Page 2: Rspec Tweaks
Page 3: Rspec Tweaks
Page 4: Rspec Tweaks
Page 5: Rspec Tweaks
Page 6: Rspec Tweaks

Fixture Insert (0.3ms) INSERT INTO `account_types` (`name`, `country_id`, `monthly_cost`, `currency`, `created_at`, `updated_at`, `id`) VALUES ('Plus', 130, 50, 'MXN', '2016-01-18 13:24:08', '2016-01-18 13:24:08', 187940547) Fixture Insert (0.3ms) INSERT INTO `account_types` (`name`, `country_id`, `monthly_cost`, `currency`, `created_at`, `updated_at`, `id`) VALUES ('Base', 130, 30, 'MXN', '2016-01-18 13:24:08', '2016-01-18 13:24:08', 1010077272) Fixture Insert (0.3ms) INSERT INTO `account_types` (`name`, `country_id`, `monthly_cost`, `currency`, `created_at`, `updated_at`, `id`) VALUES ('Premium', 130, 10, 'MXN', '2016-01-18 13:24:08', '2016-01-18 13:24:08', 624812012) Fixture Insert (0.2ms) INSERT INTO `account_types` (`name`, `country_id`, `monthly_cost`, `currency`, `created_at`, `updated_at`, `id`) VALUES ('Plus', 40, 25000, 'CLP', '2016-01-18 13:24:08', '2016-01-18 13:24:08', 305852283) Fixture Insert (0.2ms) INSERT INTO `account_types` (`name`, `country_id`, `monthly_cost`, `currency`, `created_at`, `updated_at`, `id`) VALUES ('Base', 40, 10000, 'CLP', '2016-01-18 13:24:08', '2016-01-18 13:24:08', 42332910) Fixture Insert (0.3ms) INSERT INTO `account_types` (`name`, `country_id`, `monthly_cost`, `currency`, `created_at`, `updated_at`, `id`) VALUES ('Premium', 40, 13000, 'CLP', '2016-01-18 13:24:08', '2016-01-18 13:24:08', 897761919) Fixture Insert (0.2ms) INSERT INTO `account_types` (`name`, `country_id`, `monthly_cost`, `currency`, `created_at`, `updated_at`, `id`) VALUES ('Designer', 9, 0, 'ARS', '2016-01-18 13:24:08', '2016-01-18 13:24:08', 302242410) Fixture Insert (0.2ms) INSERT INTO `account_types` (`name`, `country_id`, `monthly_cost`, `currency`, `created_at`, `updated_at`, `id`) VALUES ('Plus', 214, 25000, 'USD', '2016-01-18 13:24:08', '2016-01-18 13:24:08', 621079293) Fixture Insert (0.2ms) INSERT INTO `account_types` (`name`, `country_id`, `monthly_cost`, `currency`, `created_at`,68, 250) Fixture Insert (0.2ms) INSERT INTO `countries` (`name`, `iso3`, `iso`, `iso_name`, `id`, `numcode`) VALUES ('Iran, Islamic Republic of', 'IRN', 'IR', 'IRAN, ISLAMIC REPUBLIC OF', 94, 364) Fixture Insert (0.2ms) INSERT INTO `countries` (`name`, `iso3`, `iso`, `iso_name`, `id`, `numcode`) VALUES ('Niue', 'NIU', 'NU', 'NIUE', 149, 570) Fixture Insert (0.2ms) INSERT INTO `countries` (`name`, `iso3`, `iso`, `iso_name`, `id`, `numcode`) VALUES ('Samoa',

332 Inserts

for a simple Controller Spec

with one User

Page 7: Rspec Tweaks

let vs instance variables

Page 8: Rspec Tweaks
Page 9: Rspec Tweaks
Page 10: Rspec Tweaks

After some refactoring …

Page 11: Rspec Tweaks
Page 12: Rspec Tweaks

use more “let”

Page 13: Rspec Tweaks

just build, don’t create!

Page 14: Rspec Tweaks

flexible use of “let”

Page 15: Rspec Tweaks

more than 65% faster!!!

Page 16: Rspec Tweaks

but still 0.54243 seconds without AR?!

Page 17: Rspec Tweaks

The logs tell me this:

which means something is creating this record o.O

Okeeeey… -_-‘

Page 18: Rspec Tweaks

Tests without AR references:

Still slow, but this is due to the file operations of our validation.

78% faster! O_O

Page 19: Rspec Tweaks

Thank you!Questions?