Slide 1

Slide 1 text

Dependencies Testing With Appraisal And Bundler

Slide 2

Slide 2 text

Prem Sichanugrist @sikachu /sikachu

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

REDDOT Promo code: $49 off first month of Prime http://learn.thoughtbot.com

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

2 hours by x

Slide 11

Slide 11 text

Closest Ruby conference to my home™

Slide 12

Slide 12 text

U JELLY?

Slide 13

Slide 13 text

Appraisal

Slide 14

Slide 14 text

I use a gem called “Appraisal” to test my gems against multiple versions of its dependencies. You should give it a try! #RDRC

Slide 15

Slide 15 text

I use a gem called “Appraisal” to test my gems against multiple versions of its dependencies. You should give it a try! #RDRC http://git.io/i-love-appraisal

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

Published your gem?

Slide 18

Slide 18 text

Fully tested?

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

Fully tested

Slide 21

Slide 21 text

add_dependency("activerecord", "~> 3.0")

Slide 22

Slide 22 text

~>

Slide 23

Slide 23 text

SemVer Semantic Versioning

Slide 24

Slide 24 text

~> 3.0

Slide 25

Slide 25 text

~> 3.0

Slide 26

Slide 26 text

~> 3.0

Slide 27

Slide 27 text

People don’t follow SemVer

Slide 28

Slide 28 text

People don’t follow SemVer Rails doesn’t

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

Supported Rails Versions • 3.1.x • 3.2.x

Slide 31

Slide 31 text

Supported Rails Versions • 3.1.x • 3.2.x • 4.0.0

Slide 32

Slide 32 text

Supported Rails Versions • 3.0.x • 3.1.x • 3.2.x • 4.0.0

Slide 33

Slide 33 text

People install Paperclip ...

Slide 34

Slide 34 text

“This gem doesn’t work”

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

Works with latest version != Works with old versions

Slide 37

Slide 37 text

We need to test with multiple versions

Slide 38

Slide 38 text

How?

Slide 39

Slide 39 text

Before Bundler

Slide 40

Slide 40 text

Uninstall and reinstall

Slide 41

Slide 41 text

$ gem uninstall activesupport $ gem install activesupport -v 3.1.12 $ rake $ gem install activesupport $ rake

Slide 42

Slide 42 text

(ů `Д´)ů ~ᵲᴸᵲ

Slide 43

Slide 43 text

Why was this so bad? • Time consuming • Can’t test against multiple versions at once • Doesn’t handle dependency of dependency • Dependency hell • $ rm -Rf $GEM_HOME

Slide 44

Slide 44 text

Test in isolation

Slide 45

Slide 45 text

Gemset

Slide 46

Slide 46 text

rbenv (with rbenv-gemset)

Slide 47

Slide 47 text

$ rvm gemset create rails-3-2 $ rvm gemset use rails-3-2 $ gem install rails -v 3.2.13 $ rake $ rvm gemset create rails-3-1 $ rvm gemset use rails-3-1 $ gem install rails -v 3.1.12 $ rake # ...

Slide 48

Slide 48 text

$ rvm @rails-3-1,@rails-3-2 do rake

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

This is good, but ... • Waste of space; gems are not shared • Contributors need to use Ruby manager that supports Gemset • May need to have bootstrap script to setup gemsets

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

Multiple Gemfiles

Slide 53

Slide 53 text

!"" Gemfile !"" rails-3-1.gemfile !"" rails-3-2.gemfile ...

Slide 54

Slide 54 text

rails-3-1.gemfile: source "https://rubygems.org" gem "rails", "~> 3.1.12" gem "rspec"

Slide 55

Slide 55 text

rails-3-2.gemfile: source "https://rubygems.org" gem "rails", "~> 3.2.13" gem "rspec"

Slide 56

Slide 56 text

$ bundle install --gemfile=rails-3-2.gemfile $ export BUNDLE_GEMFILE=rails-3-2.gemfile $ bundle exec rake $ bundle install --gemfile=rails-3-1.gemfile $ export BUNDLE_GEMFILE=rails-3-1.gemfile $ bundle exec rake

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

Still hard to maintain

Slide 60

Slide 60 text

Still have to edit Gemfiles by hand

Slide 61

Slide 61 text

Have to specify dependencies over and over

Slide 62

Slide 62 text

Adding new dependency

Slide 63

Slide 63 text

Adding new dependency ... edit multiple files!

Slide 64

Slide 64 text

No easy way to test all the versions at once

Slide 65

Slide 65 text

No content

Slide 66

Slide 66 text

“There should be a better way to do this”

Slide 67

Slide 67 text

Appraisal

Slide 68

Slide 68 text

Set multiple versions of dependencies in one place

Slide 69

Slide 69 text

Merge dependencies and generate Gemfiles

Slide 70

Slide 70 text

Setup environment for Bundler

Slide 71

Slide 71 text

No content

Slide 72

Slide 72 text

Demo

Slide 73

Slide 73 text

Gemfile: source "https://rubygems.org" gem "rails" gem "rspec" gem "appraisal"

Slide 74

Slide 74 text

Gemfile: source "https://rubygems.org" gemspec

Slide 75

Slide 75 text

Appraisals: appraise "rails-3-1" do gem "rails", "~> 3.1.12" end appraise "rails-3-2" do gem "rails", "~> 3.2.13" end

Slide 76

Slide 76 text

Rakefile: require "bundler/setup" require "appraisal" task "test" do # ... end

Slide 77

Slide 77 text

Rakefile: require "bundler/setup" require "appraisal" task "test" do # ... end

Slide 78

Slide 78 text

# Generate Gemfiles $ rake appraisal:gemfiles # Install dependencies $ rake appraisal:install

Slide 79

Slide 79 text

# Run "test" task against all versions $ rake appraisal test # Run "test" task against a single version $ rake appraisal:rails-3-1 test

Slide 80

Slide 80 text

Appraisal • Allow you to set dependencies in a single place • Generate sub-Gemfiles for you • Install multiple versions of dependencies • Setup Bundler to use the correct version of dependency

Slide 81

Slide 81 text

Setup CI

Slide 82

Slide 82 text

No content

Slide 83

Slide 83 text

Show that our gems are working correctly

Slide 84

Slide 84 text

Show that our gems are working with multiple versions of dependency

Slide 85

Slide 85 text

.travis.yml: gemfile: - gemfiles/rails_3_1.gemfile - gemfiles/rails_3_2.gemfile

Slide 86

Slide 86 text

No content

Slide 87

Slide 87 text

No content

Slide 88

Slide 88 text

No content

Slide 89

Slide 89 text

Future of Appraisal

Slide 90

Slide 90 text

No content

Slide 91

Slide 91 text

Current Version: 0.5.2

Slide 92

Slide 92 text

1.0

Slide 93

Slide 93 text

Support all Gemfile directives Already in master

Slide 94

Slide 94 text

Already in master • source • ruby • gem • git • group • gemspec

Slide 95

Slide 95 text

Already in master • source • ruby • gem • git • group • gemspec * Not tested in Appraisals file yet

Slide 96

Slide 96 text

No content

Slide 97

Slide 97 text

Migrate away from Rake task W ork In Progress

Slide 98

Slide 98 text

W ork In Progress # Generate Gemfiles $ rake appraisal:gemfiles

Slide 99

Slide 99 text

W ork In Progress # Generate Gemfiles $ appraisal [generate]

Slide 100

Slide 100 text

W ork In Progress # Install dependencies $ rake appraisal:install

Slide 101

Slide 101 text

W ork In Progress # Install dependencies $ appraisal install

Slide 102

Slide 102 text

W ork In Progress # Run "test" task against all versions $ rake appraisal test

Slide 103

Slide 103 text

W ork In Progress # Run "test" task against all versions $ appraisal rake test

Slide 104

Slide 104 text

W ork In Progress # Run "test" task against a single version $ rake appraisal:rails-3-1 test

Slide 105

Slide 105 text

W ork In Progress # Run "test" task against a single version $ appraisal rails3-1 rake test

Slide 106

Slide 106 text

W ork In Progress # Run Ruby test on a single file $ appraisal rails3-1 ruby -Itest test/foo_test.rb

Slide 107

Slide 107 text

Soon™

Slide 108

Slide 108 text

Remember

Slide 109

Slide 109 text

No content

Slide 110

Slide 110 text

Test it against multiple versions of its dependencies*

Slide 111

Slide 111 text

Test it against multiple versions of its dependencies* * by using Appraisal

Slide 112

Slide 112 text

No content

Slide 113

Slide 113 text

No content

Slide 114

Slide 114 text

Thank you! Prem Sichanugrist (@sikachu) Tweet your love: http://git.io/i-love-appraisal http://learn.thoughtbot.com – Promo code: REDDOT $49 off first month of Prime I also have some stickers