Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for gemspec #2

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
70 changes: 70 additions & 0 deletions features/gemspec.feature
@@ -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"

11 changes: 9 additions & 2 deletions lib/appraisal/gemfile.rb
@@ -1,9 +1,10 @@
require 'appraisal/dependency'
require 'appraisal/gemspec'

module Appraisal
# Load bundler Gemfiles and merge dependencies
class Gemfile
attr_reader :dependencies
attr_reader :dependencies, :spec

def initialize
@dependencies = {}
Expand All @@ -27,7 +28,8 @@ def source(source)

def to_s
%{source "#{@source}"\n} <<
dependencies.values.map { |dependency| dependency.to_s }.join("\n")
dependencies.values.map { |dependency| dependency.to_s }.join("\n") <<
"\n" << spec.to_s
end

def dup
Expand All @@ -36,7 +38,12 @@ def dup
dependencies.values.each do |dependency|
gemfile.gem(dependency.name, *dependency.requirements)
end
gemfile.gemspec(spec.opts)
end
end

def gemspec(opts = nil)
@spec = Gemspec.new(opts)
end
end
end
16 changes: 16 additions & 0 deletions lib/appraisal/gemspec.rb
@@ -0,0 +1,16 @@
require 'pathname'

module Appraisal
class Gemspec
attr_reader :opts
def initialize(opts = nil)
@opts = opts || {}
# figure out the right path for the gemspec
@opts[:path] ||= '.'
@opts[:path] = ::File.expand_path(@opts[:path])
end
def to_s
"gemspec(#{opts.inspect})"
end
end
end