Permalink
Browse files

Merge pull request #109 from jkeen/master

Check the running version of rails as well as the rails gem version
  • Loading branch information...
2 parents 9822f19 + f035f22 commit f8d1c443d9e68d4f7d0ddf102a87d558e342d1aa @ragaskar ragaskar committed Oct 2, 2012
Showing with 107 additions and 10 deletions.
  1. +20 −3 lib/jasmine/dependencies.rb
  2. +87 −7 spec/dependencies_spec.rb
@@ -7,15 +7,15 @@ def rspec2?
end
def rails2?
- safe_gem_check("rails", "~> 2.3")
+ safe_gem_check("rails", "~> 2.3") && running_rails2?
end
def legacy_rails?
- safe_gem_check("rails", "< 2.3.11")
+ safe_gem_check("rails", "< 2.3.11") && running_legacy_rails?
end
def rails3?
- safe_gem_check("rails", ">= 3.0")
+ safe_gem_check("rails", ">= 3.0") && running_rails3?
end
def legacy_rack?
@@ -27,6 +27,23 @@ def rails_3_asset_pipeline?
end
private
+
+ def running_legacy_rails?
+ running_rails? && (Gem::Version.new(Rails.version) < Gem::Version.new("2.3.11"))
+ end
+
+ def running_rails2?
+ running_rails? && Rails.version.to_i == 2
+ end
+
+ def running_rails3?
+ running_rails? && Rails.version.to_i == 3
+ end
+
+ def running_rails?
+ defined?(Rails) && Rails.respond_to?(:version)
+ end
+
def safe_gem_check(gem_name, version_string)
if Gem::Specification.respond_to?(:find_by_name)
Gem::Specification.find_by_name(gem_name, version_string)
@@ -29,12 +29,21 @@ module Rails
describe ".rails2?" do
subject { Jasmine::Dependencies.rails2? }
- context "when rails 2 is present" do
+ context "when rails 2 is present and running" do
before do
Gem::Specification.should_receive(:find_by_name).with("rails", "~> 2.3").and_return(true)
+ Rails.stub(:respond_to?).with(:version).and_return(true)
+ Rails.stub(:version).and_return(running_rails_version)
end
+ let(:running_rails_version) { "2.3.11" }
it { should be_true }
end
+ context "when rails 2 is present but not running" do
+ before do
+ Gem::Specification.should_receive(:find_by_name).with("rails", "~> 2.3").and_raise(Gem::LoadError)
+ end
+ it { should be_false }
+ end
context "when rails 2 is not present" do
before do
Gem::Specification.should_receive(:find_by_name).with("rails", "~> 2.3").and_raise(Gem::LoadError)
@@ -45,12 +54,21 @@ module Rails
describe ".legacy_rails?" do
subject { Jasmine::Dependencies.legacy_rails? }
- context "when rails < 2.3.11 is present" do
+ context "when rails < 2.3.11 is present and running" do
before do
Gem::Specification.should_receive(:find_by_name).with("rails", "< 2.3.11").and_return(true)
+ Rails.stub(:respond_to?).with(:version).and_return(true)
+ Rails.stub(:version).and_return(running_rails_version)
end
+ let(:running_rails_version) { "2.3.8" }
it { should be_true }
end
+ context "when rails < 2.3.11 is present but not running" do
+ before do
+ Gem::Specification.should_receive(:find_by_name).with("rails", "< 2.3.11").and_return(true)
+ end
+ it { should be_false }
+ end
context "when rails < 2.3.11 is not present" do
before do
Gem::Specification.should_receive(:find_by_name).with("rails", "< 2.3.11").and_raise(Gem::LoadError)
@@ -61,12 +79,21 @@ module Rails
describe ".rails3?" do
subject { Jasmine::Dependencies.rails3? }
- context "when rails 3 is present" do
+ context "when rails 3 is present and running" do
before do
Gem::Specification.should_receive(:find_by_name).with("rails", ">= 3.0").and_return(true)
+ Rails.stub(:respond_to?).with(:version).and_return(true)
+ Rails.stub(:version).and_return(running_rails_version)
end
+ let(:running_rails_version) { "3.2" }
it { should be_true }
end
+ context "when rails 3 is present but not running" do
+ before do
+ Gem::Specification.should_receive(:find_by_name).with("rails", ">= 3.0").and_return(true)
+ end
+ it { should be_false }
+ end
context "when rails 3 is not present" do
before do
Gem::Specification.should_receive(:find_by_name).with("rails", ">= 3.0").and_raise(Gem::LoadError)
@@ -78,9 +105,12 @@ module Rails
describe ".rails_3_asset_pipeline?" do
subject { Jasmine::Dependencies.rails_3_asset_pipeline? }
let(:application) { double(:application) }
+ let(:running_rails_version) { "3.2" }
before do
Rails.stub(:respond_to?).with(:application).and_return(respond_to_application)
Rails.stub(:application).and_return(application)
+ Rails.stub(:respond_to?).with(:version).and_return(true)
+ Rails.stub(:version).and_return(running_rails_version)
end
context "when rails 3 is present and the application pipeline is in use" do
before do
@@ -157,10 +187,26 @@ module Rails
before do
Gem.should_receive(:available?).with("rails", "~> 2.3").and_return(rails2_present)
end
- context "when rails 2 is present" do
+ context "when rails 2 is present and running" do
+ before do
+ Rails.stub(:respond_to?).with(:version).and_return(true)
+ Rails.stub(:version).and_return(running_rails_version)
+ end
+
+ let(:running_rails_version) { "2.3" }
let(:rails2_present) { true }
it { should be_true }
end
+ context "when rails 2 is present but not running" do
+ before do
+ Rails.stub(:respond_to?).with(:version).and_return(true)
+ Rails.stub(:version).and_return(running_rails_version)
+ end
+
+ let(:running_rails_version) { "3.2" }
+ let(:rails2_present) { true }
+ it { should be_false }
+ end
context "when rails 2 is not present" do
let(:rails2_present) { false }
it { should be_false }
@@ -172,10 +218,21 @@ module Rails
before do
Gem.should_receive(:available?).with("rails", "< 2.3.11").and_return(legacy_rails_present)
end
- context "when rails < 2.3.11 is present" do
+ context "when rails < 2.3.11 is present and running" do
+ before do
+ Rails.stub(:respond_to?).with(:version).and_return(true)
+ Rails.stub(:version).and_return(running_rails_version)
+ end
+ let(:running_rails_version) { "2.3.8" }
let(:legacy_rails_present) { true }
it { should be_true }
end
+
+ context "when rails < 2.3.11 is present but not running" do
+ let(:legacy_rails_present) { true }
+ it { should be_false }
+ end
+
context "when rails < 2.3.11 is not present" do
let(:legacy_rails_present) { false }
it { should be_false }
@@ -188,6 +245,11 @@ module Rails
Gem.should_receive(:available?).with("rails", ">= 3.0").and_return(rails3_present)
end
context "when rails 3 is present" do
+ before do
+ Rails.stub(:respond_to?).with(:version).and_return(true)
+ Rails.stub(:version).and_return(running_rails_version)
+ end
+ let(:running_rails_version) { "3.2" }
let(:rails3_present) { true }
it { should be_true }
end
@@ -203,27 +265,45 @@ module Rails
before do
Gem.should_receive(:available?).with("rails", ">= 3.0").and_return(rails3_present)
Rails.stub(:respond_to?).with(:application).and_return(respond_to_application)
+ Rails.stub(:respond_to?).with(:version).and_return(true)
Rails.stub(:application).and_return(application)
end
- context "when rails 3 is present and the application pipeline is in use" do
+
+ context "when rails 3 is present, running, and the application pipeline is in use" do
+ before do
+ Rails.stub(:respond_to?).with(:version).and_return(true)
+ Rails.stub(:version).and_return(running_rails_version)
+ end
let(:rails3_present) { true }
+ let(:running_rails_version) { "3.2" }
let(:respond_to_application) { true }
let(:rails_application_assets) { true }
it { should be_true }
end
- context "when rails 3 is present and the application pipeline is not in use" do
+ context "when rails 3 is present, running, and the application pipeline is not in use" do
+ before do
+ Rails.stub(:respond_to?).with(:version).and_return(true)
+ Rails.stub(:version).and_return(running_rails_version)
+ end
let(:rails3_present) { true }
+ let(:running_rails_version) { "3.2" }
let(:respond_to_application) { true }
let(:rails_application_assets) { false }
it { should be_false }
end
context "when rails 3 is present but not loaded" do
+ before do
+ Rails.stub(:respond_to?).with(:version).and_return(false)
+ end
let(:rails3_present) { true }
let(:respond_to_application) { false }
let(:rails_application_assets) { false }
it { should be_false }
end
context "when rails 3 is not present" do
+ before do
+ Rails.stub(:respond_to?).with(:version).and_return(false)
+ end
let(:rails3_present) { false }
let(:respond_to_application) { false }
let(:rails_application_assets) { false }

0 comments on commit f8d1c44

Please sign in to comment.