forked from jasmine/jasmine-gem
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simple Rubygems backwards compatibility
- Loading branch information
Showing
14 changed files
with
137 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module Jasmine | ||
module Dependencies | ||
|
||
class << self | ||
def rspec2? | ||
safe_gem_check("rspec", ">= 2.0") | ||
end | ||
|
||
def rails2? | ||
safe_gem_check("rails", "~> 2.3") | ||
end | ||
|
||
def rails3? | ||
safe_gem_check("rails", ">= 3.0") | ||
end | ||
|
||
private | ||
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) | ||
elsif Gem.respond_to?(:available?) | ||
Gem.available?(gem_name, version_string) | ||
end | ||
rescue Gem::LoadError | ||
false | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
require 'spec_helper' | ||
|
||
describe Jasmine::Dependencies do | ||
|
||
context "with ruby gems > 1.8" do | ||
before do | ||
Gem::Specification.should_receive(:respond_to?).with(:find_by_name).and_return(true) | ||
end | ||
|
||
context "and rspec 2" do | ||
before do | ||
Gem::Specification.should_receive(:find_by_name).with("rspec", ">= 2.0").and_raise(Gem::LoadError) | ||
end | ||
it "should return the correct results" do | ||
Jasmine::Dependencies.rspec2?.should be false | ||
end | ||
|
||
it "should not raise an error" do | ||
lambda do | ||
Jasmine::Dependencies.rspec2? | ||
end.should_not raise_error(Gem::LoadError) | ||
end | ||
end | ||
|
||
context "and rails 2" do | ||
before do | ||
Gem::Specification.should_receive(:find_by_name).with("rails", "~> 2.3").and_raise(Gem::LoadError) | ||
end | ||
it "should return the correct results" do | ||
Jasmine::Dependencies.rails2?.should be false | ||
end | ||
|
||
it "should not raise an error" do | ||
lambda do | ||
Jasmine::Dependencies.rails2? | ||
end.should_not raise_error(Gem::LoadError) | ||
end | ||
end | ||
|
||
context "and rails 3" do | ||
before do | ||
Gem::Specification.should_receive(:find_by_name).with("rails", ">= 3.0").and_raise(Gem::LoadError) | ||
end | ||
it "should return the correct results" do | ||
Jasmine::Dependencies.rails3?.should be false | ||
end | ||
|
||
it "should not raise an error" do | ||
lambda do | ||
Jasmine::Dependencies.rails3? | ||
end.should_not raise_error(Gem::LoadError) | ||
end | ||
end | ||
end | ||
|
||
context "with ruby_gems < 1.8" do | ||
before do | ||
Gem::Specification.should_receive(:respond_to?).with(:find_by_name).and_return(false) | ||
end | ||
context "and rspec 2" do | ||
it "should not break when it is not present" do | ||
Gem.should_receive(:available?).with("rspec", ">= 2.0").and_return false | ||
Jasmine::Dependencies.rspec2?.should be false | ||
end | ||
end | ||
|
||
context "and rails 2" do | ||
it "should not break when it is not present" do | ||
Gem.should_receive(:available?).with("rails", "~> 2.3").and_return false | ||
Jasmine::Dependencies.rails2?.should be false | ||
end | ||
end | ||
|
||
context "and rails 3" do | ||
it "should not break when it is not present" do | ||
Gem.should_receive(:available?).with("rails", ">= 3.0").and_return false | ||
Jasmine::Dependencies.rails3?.should be false | ||
end | ||
end | ||
end | ||
|
||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters