Permalink
Browse files

Add support for `gemspec` in the Gemfile

I've modified a patch from @josephholsten to make it work as expected.

Closes #1,#2
  • Loading branch information...
josephholsten authored and sikachu committed Jan 10, 2011
1 parent c84e72e commit f5c385ac5b03fafbc1fbcae6cbf521b089564b26
Showing with 114 additions and 2 deletions.
  1. +70 −0 features/gemspec.feature
  2. +21 −2 lib/appraisal/gemfile.rb
  3. +23 −0 lib/appraisal/gemspec.rb
View
@@ -0,0 +1,70 @@
+Feature: appraisals using an existing gemspec
+
+Background:
+ Given a directory named "gemspecced"
+ When I cd to "gemspecced"
+ And I write to "gemspecced.gemspec" with:
+ """
+ Gem::Specification.new do |s|
+ s.name = %q{gemspecced}
+ s.version = '0.1'
+ s.summary = %q{featureful!}
+
+ s.add_runtime_dependency('mocha')
+ s.add_development_dependency('factory_girl', '1.3.2')
+ end
+ """
+ And a directory named "specdir"
+ And I write to "specdir/gemspecced.gemspec" with:
+ """
+ Gem::Specification.new do |s|
+ s.name = %q{gemspecced}
+ s.version = '0.1'
+ s.summary = %q{featureful!}
+
+ s.add_runtime_dependency('mocha')
+ s.add_development_dependency('factory_girl', '1.3.0')
+ end
+ """
+ And I write to "Appraisals" with:
+ """
+ appraise "stock" do
+ gem "shoulda", "2.11.3"
+ end
+ """
+ When I write to "Rakefile" with:
+ """
+ require 'rubygems'
+ require 'bundler/setup'
+ require 'appraisal'
+ task :version do
+ require 'factory_girl'
+ puts "Loaded #{Factory::VERSION}"
+ end
+ """
+
+@disable-bundler
+Scenario: run a gem in the gemspec
+ And I write to "Gemfile" with:
+ """
+ source "http://rubygems.org"
+ gemspec
+ """
+ When I add "appraisal" from this project as a dependency
+ When I successfully run "rake appraisal:install --trace"
+ When I run "rake appraisal version --trace"
+ Then the output should contain "Loaded 1.3.2"
+
+
+@disable-bundler
+Scenario: run a gem in the gemspec via path
+ And I write to "Gemfile" with:
+ """
+ source "http://rubygems.org"
+ gemspec :path => './specdir'
+ """
+ When I add "appraisal" from this project as a dependency
+ When I successfully run "rake appraisal:install --trace"
+ When I run "rake appraisal version --trace"
+ Then the output should contain "Loaded 1.3.0"
+
View
@@ -1,4 +1,5 @@
require 'appraisal/dependency'
+require 'appraisal/gemspec'
module Appraisal
# Load bundler Gemfiles and merge dependencies
@@ -26,8 +27,7 @@ def source(source)
end
def to_s
- %{source "#{@source}"\n} <<
- dependencies.values.map { |dependency| dependency.to_s }.join("\n")
+ [source_entry, dependencies_entry, gemspec_entry].join("\n\n")
end
def dup
@@ -36,7 +36,26 @@ def dup
dependencies.values.each do |dependency|
gemfile.gem(dependency.name, *dependency.requirements)
end
+ gemfile.gemspec(@gemspec.options) if @gemspec
end
end
+
+ def gemspec(options = {})
+ @gemspec = Gemspec.new(options)
+ end
+
+ protected
+
+ def source_entry
+ %(source "#{@source}")
+ end
+
+ def dependencies_entry
+ dependencies.values.map { |dependency| dependency.to_s }.join("\n")
+ end
+
+ def gemspec_entry
+ @gemspec.to_s
+ end
end
end
View
@@ -0,0 +1,23 @@
+require 'pathname'
+
+module Appraisal
+ class Gemspec
+ attr_reader :options
+
+ def initialize(options = {})
+ @options = options
+
+ # figure out the right path for the gemspec
+ @options[:path] ||= '.'
+ @options[:path] = ::File.expand_path(@options[:path])
+ end
+
+ def exists?
+ Dir[::File.join(@options[:path], "*.gemspec")].size > 0
+ end
+
+ def to_s
+ "gemspec(#{@options.inspect})" if exists?
+ end
+ end
+end

0 comments on commit f5c385a

Please sign in to comment.