Testing Multiple Versions of Ruby
When you have code that you would like to test, it is fairly simple to develop your tests to allow for it to be ran in more than one version of Ruby.
This is part of the code that I use through inspiration from the Ruby Spec project. I haven’t checked the code, so I don’t believe it is identical in functionality.
The helper.rb file is loaded with my helper file in my testing folder.
1 2 3 4 5
This allows me to do the identical thing you saw on line 63 of that link above. In other words, I can use it with a block and it just does the right thing.
Or I can use it like a query, and it will either return true or nil.
This makes it simple for me to have tests that are version specific, yet won’t fill my tests with failures just because of a version difference.
It also lets me search for those things that are specific to a version.
Ruby 2.0.0-p0 is out, and I used it to document the new to_h functionality
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
Now I can run this test alongside others, and I don’t have to worry about what version of Ruby it is testing against.
I think that I will add some functionality though. So I can specify a minimum version of Ruby, and when 3.0.0 comes out, I will know what things change based on the tests, because they will run against that version as well, while not running against previous ones.
Anyway, how do you test against different versions of Ruby?
Continue this conversation on our Google Plus post!