44
Secrets of Testing Rails 5 Apps

Ruby conf 2016 - Secrets of Testing Rails 5 Apps

Embed Size (px)

Citation preview

Page 1: Ruby conf 2016 - Secrets of Testing Rails 5 Apps

Secrets of Testing Rails 5 Apps

Page 2: Ruby conf 2016 - Secrets of Testing Rails 5 Apps

Rails Tests

Unit tests -> For models

Functional tests -> For controllers

Integration tests -> For scenarios of a particular feature

Page 3: Ruby conf 2016 - Secrets of Testing Rails 5 Apps

Change in rails 5

Unit tests -> No big change

Controller tests -> are most affected

Page 4: Ruby conf 2016 - Secrets of Testing Rails 5 Apps

What do we test in a controller test ?

Request --------------> Response

Page 5: Ruby conf 2016 - Secrets of Testing Rails 5 Apps
Page 6: Ruby conf 2016 - Secrets of Testing Rails 5 Apps

Controller tests actually lie...

Page 7: Ruby conf 2016 - Secrets of Testing Rails 5 Apps

Integration tests

Page 8: Ruby conf 2016 - Secrets of Testing Rails 5 Apps

Integration tests

Almost same as controller tests

Close to the real world

But before rails 5 they were really slow

Page 9: Ruby conf 2016 - Secrets of Testing Rails 5 Apps

Integration Controller tests are default in Rails 5

Page 10: Ruby conf 2016 - Secrets of Testing Rails 5 Apps

Functional Controller tests are soft deprecated

Page 11: Ruby conf 2016 - Secrets of Testing Rails 5 Apps

Old functional tests will continue to work for now***

Page 12: Ruby conf 2016 - Secrets of Testing Rails 5 Apps

Might be extracted in separate gem in Rails 5.1

Page 13: Ruby conf 2016 - Secrets of Testing Rails 5 Apps

BLACK BOX

Page 14: Ruby conf 2016 - Secrets of Testing Rails 5 Apps

Sprockets

Page 15: Ruby conf 2016 - Secrets of Testing Rails 5 Apps

Sprockets

Page 16: Ruby conf 2016 - Secrets of Testing Rails 5 Apps

Speeding Up Your Test Suite

Page 17: Ruby conf 2016 - Secrets of Testing Rails 5 Apps
Page 18: Ruby conf 2016 - Secrets of Testing Rails 5 Apps
Page 19: Ruby conf 2016 - Secrets of Testing Rails 5 Apps
Page 20: Ruby conf 2016 - Secrets of Testing Rails 5 Apps
Page 21: Ruby conf 2016 - Secrets of Testing Rails 5 Apps
Page 22: Ruby conf 2016 - Secrets of Testing Rails 5 Apps
Page 23: Ruby conf 2016 - Secrets of Testing Rails 5 Apps

Returns a saved User instance (writes to DB)

user = create(:user)

# Returns a User instance that's not saved (does not write to DB)

user = build(:user)

factory :user do

association posts

end

FactoryGirl.build(:user) #this creates posts in the database even though you are only building the parent object(user)

Returns an object with all defined attributes stubbed out

stub = build_stubbed(:user)

Page 24: Ruby conf 2016 - Secrets of Testing Rails 5 Apps
Page 25: Ruby conf 2016 - Secrets of Testing Rails 5 Apps
Page 26: Ruby conf 2016 - Secrets of Testing Rails 5 Apps

20 Tools and Techniques That Make You More Creative

Page 27: Ruby conf 2016 - Secrets of Testing Rails 5 Apps
Page 28: Ruby conf 2016 - Secrets of Testing Rails 5 Apps
Page 29: Ruby conf 2016 - Secrets of Testing Rails 5 Apps
Page 30: Ruby conf 2016 - Secrets of Testing Rails 5 Apps
Page 31: Ruby conf 2016 - Secrets of Testing Rails 5 Apps
Page 32: Ruby conf 2016 - Secrets of Testing Rails 5 Apps
Page 33: Ruby conf 2016 - Secrets of Testing Rails 5 Apps
Page 34: Ruby conf 2016 - Secrets of Testing Rails 5 Apps
Page 35: Ruby conf 2016 - Secrets of Testing Rails 5 Apps
Page 36: Ruby conf 2016 - Secrets of Testing Rails 5 Apps
Page 37: Ruby conf 2016 - Secrets of Testing Rails 5 Apps
Page 38: Ruby conf 2016 - Secrets of Testing Rails 5 Apps
Page 39: Ruby conf 2016 - Secrets of Testing Rails 5 Apps
Page 40: Ruby conf 2016 - Secrets of Testing Rails 5 Apps
Page 41: Ruby conf 2016 - Secrets of Testing Rails 5 Apps
Page 42: Ruby conf 2016 - Secrets of Testing Rails 5 Apps
Page 43: Ruby conf 2016 - Secrets of Testing Rails 5 Apps
Page 44: Ruby conf 2016 - Secrets of Testing Rails 5 Apps

Thank You