Skip to content

Commit f308860

Browse files
committed
Setup ginger scenarios so we can test this gem against multiple versions of active record.
1 parent 3e6c5b4 commit f308860

22 files changed

+478
-1
lines changed

.ginger

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1

Rakefile

+11-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ begin
1414

1515
gem.add_dependency 'activerecord', '>= 2.0.0'
1616
gem.add_development_dependency "rspec", ">= 1.2.9"
17+
18+
gem.files.exclude 'vendor/ginger'
1719
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
1820
end
1921
Jeweler::GemcutterTasks.new
@@ -38,7 +40,15 @@ end
3840

3941
task :spec => :check_dependencies if defined?(Jeweler)
4042

41-
task :default => :spec
43+
desc 'Run ginger tests'
44+
task :ginger do
45+
$LOAD_PATH << File.join(*%w[vendor ginger lib])
46+
ARGV.clear
47+
ARGV << 'spec'
48+
load File.join(*%w[vendor ginger bin ginger])
49+
end
50+
51+
task :default => :ginger
4252

4353
require 'rake/rdoctask'
4454
Rake::RDocTask.new do |rd|

ginger_scenarios.rb

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
require 'ginger'
2+
3+
def create_scenario(version)
4+
scenario = Ginger::Scenario.new("Rails #{version}")
5+
scenario[/^active_?record$/] = version
6+
scenario[/^active_?support$/] = version
7+
scenario
8+
end
9+
10+
Ginger.configure do |config|
11+
config.aliases["active_record"] = "activerecord"
12+
config.aliases["active_support"] = "activesupport"
13+
14+
%w(
15+
2.3.5 2.3.4 2.3.3 2.3.2
16+
2.2.3 2.2.2
17+
2.1.2 2.1.1 2.1.0
18+
2.0.5 2.0.4 2.0.2 2.0.1 2.0.0
19+
).each do |version|
20+
config.scenarios << create_scenario(version)
21+
end
22+
end

spec/nulldb_spec.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
require 'rubygems'
22
require 'spec'
3+
$LOAD_PATH << File.join(File.dirname(__FILE__), *%w[.. vendor ginger lib])
4+
require 'ginger'
35
require 'active_record'
46
$: << File.join(File.dirname(__FILE__), "..", "lib")
57

vendor/ginger/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ginger*.gem

vendor/ginger/LICENCE

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2008 Pat Allan
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

vendor/ginger/README.textile

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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/

vendor/ginger/Rakefile

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require 'rubygems'
2+
3+
require 'tasks/distribution'
4+
require 'tasks/testing'
5+
6+
task :default => :spec

vendor/ginger/VERSION

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.2.0

vendor/ginger/bin/ginger

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env ruby
2+
3+
require 'rubygems'
4+
require 'ginger'
5+
require 'rake'
6+
7+
if ARGV.length == 0
8+
puts <<-USAGE
9+
ginger #{Ginger::Version::String}
10+
Use ginger to run specs for each scenario defined. Scenarios must be set out in
11+
a file called ginger_scenarios.rb wherever this tool is run. Once they're
12+
defined, then you can run this tool and provide the rake task that would
13+
normally be called.
14+
15+
Examples:
16+
ginger spec
17+
ginger test
18+
ginger spec:models
19+
USAGE
20+
exit 0
21+
end
22+
23+
file_path = File.join Dir.pwd, ".ginger"
24+
25+
File.delete(file_path) if File.exists?(file_path)
26+
27+
scenarios = Ginger::Configuration.instance.scenarios
28+
puts "No Ginger Scenarios defined" if scenarios.empty?
29+
30+
scenarios.each_with_index do |scenario, index|
31+
puts <<-SCENARIO
32+
33+
-------------------
34+
Ginger Scenario: #{scenario.name || index+1}
35+
-------------------
36+
SCENARIO
37+
38+
File.open('.ginger', 'w') { |f| f.write index.to_s }
39+
40+
system("rake #{ARGV.join(" ")}") || # Standard
41+
system("rake.bat #{ARGV.join(" ")}") || # Windows
42+
raise('Missing: rake or rake.bat. You might want to fix that.')
43+
end
44+
45+
File.delete(file_path) if File.exists?(file_path)

vendor/ginger/ginger.gemspec

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Generated by jeweler
2+
# DO NOT EDIT THIS FILE DIRECTLY
3+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4+
# -*- encoding: utf-8 -*-
5+
6+
Gem::Specification.new do |s|
7+
s.name = %q{ginger}
8+
s.version = "1.2.0"
9+
10+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11+
s.authors = ["Pat Allan"]
12+
s.date = %q{2009-11-27}
13+
s.default_executable = %q{ginger}
14+
s.description = %q{Run rake tasks multiple times with different gem versions.}
15+
s.email = %q{[email protected]}
16+
s.executables = ["ginger"]
17+
s.extra_rdoc_files = [
18+
"README.textile"
19+
]
20+
s.files = [
21+
"LICENCE",
22+
"README.textile",
23+
"bin/ginger",
24+
"lib/ginger.rb",
25+
"lib/ginger/configuration.rb",
26+
"lib/ginger/kernel.rb",
27+
"lib/ginger/scenario.rb"
28+
]
29+
s.homepage = %q{http://github.com/freelancing_god/ginger/tree}
30+
s.rdoc_options = ["--charset=UTF-8"]
31+
s.require_paths = ["lib"]
32+
s.rubygems_version = %q{1.3.5}
33+
s.summary = %q{Run rake tasks multiple times with different gem versions.}
34+
s.test_files = [
35+
"spec/ginger",
36+
"spec/ginger/configuration_spec.rb",
37+
"spec/ginger/kernel_spec.rb",
38+
"spec/ginger/scenario_spec.rb",
39+
"spec/ginger_spec.rb",
40+
"spec/spec_helper.rb"
41+
]
42+
43+
if s.respond_to? :specification_version then
44+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
45+
s.specification_version = 3
46+
47+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
48+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
49+
s.add_development_dependency(%q<yard>, [">= 0"])
50+
else
51+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
52+
s.add_dependency(%q<yard>, [">= 0"])
53+
end
54+
else
55+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
56+
s.add_dependency(%q<yard>, [">= 0"])
57+
end
58+
end
59+

vendor/ginger/lib/ginger.rb

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
require 'rubygems'
2+
require 'ginger/configuration'
3+
require 'ginger/scenario'
4+
require 'ginger/kernel'
5+
6+
module Ginger
7+
def self.configure(&block)
8+
yield Ginger::Configuration.instance
9+
end
10+
end
11+
12+
Kernel.send(:include, Ginger::Kernel)
13+
14+
Ginger::Configuration.detect_scenario_file
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
require 'singleton'
2+
3+
module Ginger
4+
class Configuration
5+
include Singleton
6+
7+
attr_accessor :scenarios, :aliases
8+
9+
def initialize
10+
@scenarios = []
11+
@aliases = {}
12+
end
13+
14+
def self.detect_scenario_file
15+
['.','spec','test'].each do |path|
16+
require "#{path}/ginger_scenarios" and break if File.exists?("#{path}/ginger_scenarios.rb")
17+
end
18+
end
19+
end
20+
end

vendor/ginger/lib/ginger/kernel.rb

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
module Ginger
2+
module Kernel
3+
def self.included(base)
4+
base.class_eval do
5+
def require_with_ginger(req)
6+
unless scenario = ginger_scenario
7+
require_without_ginger(req)
8+
return
9+
end
10+
11+
if scenario.version(req)
12+
gem ginger_gem_name(req)
13+
end
14+
15+
require_without_ginger(req)
16+
end
17+
18+
alias_method :require_without_ginger, :require
19+
alias_method :require, :require_with_ginger
20+
21+
def gem_with_ginger(gem_name, *version_requirements)
22+
unless scenario = ginger_scenario
23+
gem_without_ginger(gem_name, *version_requirements)
24+
return
25+
end
26+
27+
if version_requirements.length == 0 &&
28+
version = scenario.version(gem_name)
29+
version_requirements << "= #{version}"
30+
end
31+
32+
gem_without_ginger(gem_name, *version_requirements)
33+
end
34+
35+
alias_method :gem_without_ginger, :gem
36+
alias_method :gem, :gem_with_ginger
37+
38+
private
39+
40+
def ginger_scenario
41+
return nil unless File.exists?(".ginger")
42+
43+
scenario = nil
44+
File.open('.ginger') { |f| scenario = f.read }
45+
return nil unless scenario
46+
47+
Ginger::Configuration.instance.scenarios[scenario.to_i]
48+
end
49+
50+
def ginger_gem_name(gem_name)
51+
Ginger::Configuration.instance.aliases[gem_name] || gem_name
52+
end
53+
end
54+
end
55+
end
56+
end

vendor/ginger/lib/ginger/scenario.rb

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
module Ginger
2+
class Scenario < Hash
3+
attr_accessor :name
4+
5+
def initialize(name=nil)
6+
@name = name
7+
end
8+
9+
def add(gem, version)
10+
self[gem] = version
11+
end
12+
13+
def version(gem)
14+
self.keys.each do |key|
15+
case key
16+
when String
17+
return self[key] if gem == key
18+
when Regexp
19+
return self[key] if gem =~ key
20+
end
21+
end
22+
23+
return nil
24+
end
25+
26+
def gems
27+
self.keys
28+
end
29+
end
30+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require File.dirname(__FILE__) + '/../spec_helper'
2+
3+
describe Ginger::Configuration do
4+
it "should be a singleton class" do
5+
Ginger::Configuration.should respond_to(:instance)
6+
end
7+
end
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require File.dirname(__FILE__) + '/../spec_helper'
2+
3+
describe "Ginger::Kernel" do
4+
it "should description" do
5+
#
6+
end
7+
end

0 commit comments

Comments
 (0)