Dependencies Testing With Appraisal And Bundler

Dependencies Testing With Appraisal And Bundler

Revised talk after given at RubyKaigi 2013 (https://speakerdeck.com/sikachu/you-have-to-test-multiple-versions-of-your-gems-dependencies-you-used-appraisal-its-super-affective)

Presented at RedDotRubyConf 2013 on June 8, 2013.

F1c4a3bb1606cc4a61711e61e2fe6146?s=128

Prem Sichanugrist

June 08, 2013
Tweet

Transcript

  1. Dependencies Testing With Appraisal And Bundler

  2. Prem Sichanugrist @sikachu /sikachu

  3. None
  4. None
  5. None
  6. None
  7. None
  8. REDDOT Promo code: $49 off first month of Prime http://learn.thoughtbot.com

  9. None
  10. 2 hours by x

  11. Closest Ruby conference to my home™

  12. U JELLY?

  13. Appraisal

  14. I use a gem called “Appraisal” to test my gems

    against multiple versions of its dependencies. You should give it a try! #RDRC
  15. 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
  16. None
  17. Published your gem?

  18. Fully tested?

  19. None
  20. Fully tested

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

  22. ~>

  23. SemVer Semantic Versioning

  24. ~> 3.0

  25. ~> 3.0

  26. ~> 3.0

  27. People don’t follow SemVer

  28. People don’t follow SemVer Rails doesn’t

  29. None
  30. Supported Rails Versions • 3.1.x • 3.2.x

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

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

    4.0.0
  33. People install Paperclip ...

  34. “This gem doesn’t work”

  35. None
  36. Works with latest version != Works with old versions

  37. We need to test with multiple versions

  38. How?

  39. Before Bundler

  40. Uninstall and reinstall

  41. $ gem uninstall activesupport $ gem install activesupport -v 3.1.12

    $ rake $ gem install activesupport $ rake
  42. (ů `Д´)ů ~ᵲᴸᵲ

  43. 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
  44. Test in isolation

  45. Gemset

  46. rbenv (with rbenv-gemset)

  47. $ 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 # ...
  48. $ rvm @rails-3-1,@rails-3-2 do rake

  49. None
  50. 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
  51. None
  52. Multiple Gemfiles

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

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

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

  56. $ 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
  57. None
  58. None
  59. Still hard to maintain

  60. Still have to edit Gemfiles by hand

  61. Have to specify dependencies over and over

  62. Adding new dependency

  63. Adding new dependency ... edit multiple files!

  64. No easy way to test all the versions at once

  65. None
  66. “There should be a better way to do this”

  67. Appraisal

  68. Set multiple versions of dependencies in one place

  69. Merge dependencies and generate Gemfiles

  70. Setup environment for Bundler

  71. None
  72. Demo

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

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

  75. Appraisals: appraise "rails-3-1" do gem "rails", "~> 3.1.12" end appraise

    "rails-3-2" do gem "rails", "~> 3.2.13" end
  76. Rakefile: require "bundler/setup" require "appraisal" task "test" do # ...

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

    end
  78. # Generate Gemfiles $ rake appraisal:gemfiles # Install dependencies $

    rake appraisal:install
  79. # Run "test" task against all versions $ rake appraisal

    test # Run "test" task against a single version $ rake appraisal:rails-3-1 test
  80. 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
  81. Setup CI

  82. None
  83. Show that our gems are working correctly

  84. Show that our gems are working with multiple versions of

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

  86. None
  87. None
  88. None
  89. Future of Appraisal

  90. None
  91. Current Version: 0.5.2

  92. 1.0

  93. Support all Gemfile directives Already in master

  94. Already in master • source • ruby • gem •

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

    git • group • gemspec * Not tested in Appraisals file yet
  96. None
  97. Migrate away from Rake task W ork In Progress

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

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

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

  101. W ork In Progress # Install dependencies $ appraisal install

  102. W ork In Progress # Run "test" task against all

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

    versions $ appraisal rake test
  104. W ork In Progress # Run "test" task against a

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

    single version $ appraisal rails3-1 rake test
  106. W ork In Progress # Run Ruby test on a

    single file $ appraisal rails3-1 ruby -Itest test/foo_test.rb
  107. Soon™

  108. Remember

  109. None
  110. Test it against multiple versions of its dependencies*

  111. Test it against multiple versions of its dependencies* * by

    using Appraisal
  112. None
  113. None
  114. 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