Recently I wrote a Rails engine gem password_required. One of the first problems I ran into was not knowing what versions of Rails it would work with, so I kept the dependency rigid, “~> 4.1.6”. That of course alienated anyone working from the 4.0.x branch. I looked around at different packages to see how they handle this, and here is the solution I landed on.
First, ditch your Gemfile.lock and add it to your .gitignore, it will give you headaches when trying to bundle different versions of Rails for testing.
Next the following is found in my Gemfile..
|
And you will need to alter your specfile…
|
This lets you do the following to test against rails 4.0 :
|
The code could be better for this but you get the point. If you are using Travis to test this makes it pretty simple, here is my travis file env.
|
Probably the biggest pain I had in this whole process was some of the errors I
had to deal with in my spec/dummy
rails testbed. Since I started with 4.1
there were boilerplate problems I ran into when trying to use 4.0. Here were
the changes I had to make
|
|
I tried briefly to go back as far as rails 3.2 but had a lot of issues so I stuck with 4.0 + for now. Hopefully this is helpful to anyone else who is looking to support multiple branches of rails in their gem.