|
| 1 | +Ginger is a small gem that allows you to test your projects using multiple versions of gem libraries. The idea is from "Ian White's garlic":http://github.com/ianwhite/garlic/tree - hence the related name of this - but my approach is a bit different, since I don't test my plugins from within a rails application. Maybe they can be merged at some point - I just hacked this up quickly to fit my needs. |
| 2 | + |
| 3 | +To get it all working, you need to do four things. The first is, of course, to install this gem. |
| 4 | + |
| 5 | +<pre><code>sudo gem install ginger --source=http://gemcutter.org</code></pre> |
| 6 | + |
| 7 | +Next, add the following line of code to your @spec_helper.rb@ file (or equivalent): |
| 8 | + |
| 9 | +<pre><code>require 'ginger'</code></pre> |
| 10 | + |
| 11 | +You'll want to put it as high up as possible - in particular, before any @require@ calls to libraries you want to cover multiple versions of. |
| 12 | + |
| 13 | +Step number three is creating the sets of scenarios in a file called @ginger_scenarios.rb@, which should go in the root, spec or test directory of your project. Here's an example, showing off the syntax possibilities. |
| 14 | + |
| 15 | +<pre><code>require 'ginger' |
| 16 | + |
| 17 | +Ginger.configure do |config| |
| 18 | + config.aliases["active_record"] = "activerecord" |
| 19 | + |
| 20 | + ar_1_2_6 = Ginger::Scenario.new |
| 21 | + ar_1_2_6[/^active_?record$/] = "1.15.6" |
| 22 | + |
| 23 | + ar_2_0_2 = Ginger::Scenario.new |
| 24 | + ar_2_0_2[/^active_?record$/] = "2.0.2" |
| 25 | + |
| 26 | + ar_2_1_1 = Ginger::Scenario.new |
| 27 | + ar_2_1_1[/^active_?record$/] = "2.1.1" |
| 28 | + |
| 29 | + config.scenarios << ar_1_2_6 << ar_2_0_2 << ar_2_1_1 |
| 30 | +end</code></pre> |
| 31 | + |
| 32 | +Above, I've added three different scenarios, for three different versions of ActiveRecord. I also added an alias, as people sometimes use the underscore, and sometimes don't. The gem's name has no underscore though, so the _value_ of the alias matches the gem name (whereas the key would be alternative usage). |
| 33 | + |
| 34 | +You can have multiple gems set in each scenario - and you don't have to use regular expressions, you can just use straight strings. |
| 35 | + |
| 36 | +<pre><code>sphinx_scenario = Ginger::Scenario.new |
| 37 | +sphinx_scenario["riddle"] = "0.9.8" |
| 38 | +sphinx_scenario["thinking_sphinx"] = "0.9.8"</code></pre> |
| 39 | + |
| 40 | +Don't forget to add them to @config@'s scenarios collection, else they're not saved anywhere. |
| 41 | + |
| 42 | +To better discern different defined scenarios you can create them with a name. The name will be output when the scenario runs as the title. |
| 43 | + |
| 44 | +<pre><code>sphinx_scenario = Ginger::Scenario.new('Thinking Sphinx 0.9.8')</code></pre> |
| 45 | + |
| 46 | +And finally, you'll want to run the tests or specs for each scenario. This is done using the @ginger@ CLI tool, which parrots whatever parameters you give it onto @rake@. So just do something like: |
| 47 | + |
| 48 | +<pre><code>ginger spec |
| 49 | +ginger test |
| 50 | +ginger spec:unit</code></pre> |
| 51 | + |
| 52 | +h2. Contributors |
| 53 | + |
| 54 | +* "Adam Meehan":http://duckpunching.com/ |
| 55 | +* "Darragh Curran":http://peelmeagrape.net/ |
0 commit comments