Permalink
Browse files

Merge: Simpler rspec/rails detection

  • Loading branch information...
2 parents 85ffb09 + 9ed2ffe commit 2b8ae93f9e950b410fe3cb99796b1d82e35b0a69 @ragaskar ragaskar committed Oct 26, 2011
View
@@ -1,2 +1,3 @@
source "http://rubygems.org"
+gem "ci_reporter", :git => "git://github.com/nicksieger/ci_reporter.git", :ref => "af8674c7bddc338fad228c566a03e3b8188d8a22"
gemspec
View
@@ -4,8 +4,7 @@ require "bundler"
Bundler.setup
Bundler::GemHelper.install_tasks
-require "lib/jasmine"
-
+require "jasmine"
if Jasmine::Dependencies.rspec2?
require 'rspec'
require 'rspec/core/rake_task'
@@ -10,11 +10,11 @@
<script type="text/javascript" src="lib/jasmine-1.1.0.rc1/jasmine.js"></script>
<script type="text/javascript" src="lib/jasmine-1.1.0.rc1/jasmine-html.js"></script>
- <!-- include source files here... -->
+ <!-- include spec files here... -->
<script type="text/javascript" src="spec/SpecHelper.js"></script>
<script type="text/javascript" src="spec/PlayerSpec.js"></script>
- <!-- include spec files here... -->
+ <!-- include source files here... -->
<script type="text/javascript" src="src/Player.js"></script>
<script type="text/javascript" src="src/Song.js"></script>
View
@@ -29,7 +29,12 @@ Gem::Specification.new do |s|
end
s.add_development_dependency 'rake-tasks'
elsif ENV['RAILS_VERSION'] == 'pojs-rspec2'
- s.add_development_dependency 'rspec', '>= 2.5.0'
+ if ENV["RUBY_VERSION"] =~ /1\.8\.6/
+ #2.7.0 uses reduce vs inject, non 1.8.6 compatible
+ s.add_development_dependency 'rspec', '2.6.0'
+ else
+ s.add_development_dependency 'rspec', '>= 2.5.0'
+ end
s.add_development_dependency 'rake-tasks'
s.add_development_dependency 'rack', "1.1" if ENV["RUBY_VERSION"] =~ /1\.8\.6/
elsif ENV['RAILS_VERSION'] == 'rails2'
@@ -4,7 +4,7 @@
require 'jasmine'
jasmine_config_overrides = File.expand_path(File.join(File.dirname(__FILE__), 'jasmine_config.rb'))
require jasmine_config_overrides if File.exist?(jasmine_config_overrides)
-if Jasmine::rspec2?
+if Jasmine::Dependencies.rspec2?
require 'rspec'
else
require 'spec'
@@ -15,7 +15,7 @@
should_stop = false
-if Jasmine::rspec2?
+if Jasmine::Dependencies.rspec2?
RSpec.configuration.after(:suite) do
spec_builder.stop if should_stop
end
@@ -29,4 +29,4 @@
spec_builder.start
should_stop = true
-spec_builder.declare_suites
+spec_builder.declare_suites
View
@@ -1,7 +1,7 @@
jasmine_files = ['base',
+ 'dependencies',
'config',
'server',
- "dependencies_#{Jasmine::RUBYGEMS_VERSION}",
'selenium_driver',
'spec_builder',
'command_line_tool']
@@ -11,3 +11,5 @@
end
require File.join('jasmine', "railtie") if Jasmine::Dependencies.rails3?
+
+
@@ -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
@@ -1,26 +0,0 @@
-module Jasmine
- module Dependencies
-
- def self.rspec2?
- Gem::Specification::find_by_name "rspec", ">= 2.0"
- rescue Gem::LoadError
- false
- end
-
- def self.rails2?
- begin
- Gem::Specification::find_by_name "rails", "~> 2.3"
- rescue Gem::LoadError
- false
- end
- end
-
- def self.rails3?
- begin
- Gem::Specification::find_by_name "rails", ">= 3.0"
- rescue Gem::LoadError
- false
- end
- end
- end
-end
@@ -1,16 +0,0 @@
-module Jasmine
- module Dependencies
-
- def self.rspec2?
- Gem.available? "rspec", ">= 2.0"
- end
-
- def self.rails2?
- Gem.available? "rails", "~> 2.3"
- end
-
- def self.rails3?
- Gem.available? "rails", ">= 3.0"
- end
- end
-end
View
@@ -1,5 +1,3 @@
module Jasmine
- VERSION = "1.1.1"
-
- RUBYGEMS_VERSION = Gem::Version.create(Gem::VERSION) >= Gem::Version.create("1.8") ? "pos18" : "pre18"
+ VERSION = "1.1.2"
end
View
@@ -0,0 +1,86 @@
+require 'spec_helper'
+
+#rspec 1 fails to stub respond_to
+if Jasmine::Dependencies.rspec2?
+ 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
+
+end
@@ -1,31 +0,0 @@
-if Jasmine::RUBYGEMS_VERSION == "pos18"
- require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "lib", "jasmine", "dependencies_pos18"))
-
- describe Jasmine do
-
- describe "Gem version indentification" do
- context "of rspec 2" do
- it "should not break when it is not present" do
- Gem::Specification.should_receive(:find_by_name).with("rspec", ">= 2.0").twice().and_raise(Gem::LoadError)
- Jasmine::Dependencies.rspec2?.should be false
- Jasmine::Dependencies.rspec2?.should_not raise_error(Gem::LoadError)
- end
- end
-
- context "of rails 2" do
- it "should not break when it is not present" do
- Gem::Specification.should_receive(:find_by_name).with("rails", "~> 2.3").twice().and_raise(Gem::LoadError)
- Jasmine::Dependencies.rails2?.should be false
- Jasmine::Dependencies.rails2?.should_not raise_error(Gem::LoadError)
- end
- end
-
- context "of rails 3"
- it "should not break when it is not present" do
- Gem::Specification.should_receive(:find_by_name).with("rails", ">= 3.0").twice().and_raise(Gem::LoadError)
- Jasmine::Dependencies.rails3?.should be false
- Jasmine::Dependencies.rails3?.should_not raise_error(Gem::LoadError)
- end
- end
- end
-end
@@ -1,29 +0,0 @@
-if Jasmine::RUBYGEMS_VERSION == "pre18"
- require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "lib", "jasmine", "dependencies_pre18"))
-
- describe Jasmine do
-
- describe "Gem version indentification" do
- context "of 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 "of 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 "of 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
-end
View
@@ -6,7 +6,6 @@
Bundler.setup(:default, :development)
$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "../lib")))
-
require "jasmine"
if Jasmine::Dependencies.rspec2?
@@ -15,6 +14,7 @@
require 'spec'
end
+
def create_rails(name)
if Jasmine::Dependencies.rails3?
`rails new #{name}`

0 comments on commit 2b8ae93

Please sign in to comment.