Skip to content

Commit

Permalink
appraisal generate is now working
Browse files Browse the repository at this point in the history
  • Loading branch information
sikachu committed Sep 19, 2013
1 parent d7471e7 commit d69021c
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 70 deletions.
8 changes: 5 additions & 3 deletions lib/appraisal/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

module Appraisal
class CLI < Thor
desc '', ''
def default
puts 'fuck yeah'
desc 'generate', 'generate a gemfile for each appraisal'
def generate
File.each do |appraisal|
appraisal.write_gemfile
end
end
end
end
41 changes: 22 additions & 19 deletions spec/acceptance/cli_spec.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
require 'spec_helper'

describe 'CLI', 'generate' do
it 'generates the gemfiles' do
build_gem 'dummy', '1.0.0'
build_gem 'dummy', '1.1.0'
build_appraisal_file <<-Appraisal.strip_heredoc
appraise '1.0.0' do
gem 'dummy', '1.1.0'
end
describe 'CLI' do
context 'appraisal generate' do
it 'generates the gemfiles' do
build_appraisal_file <<-Appraisal
appraise '1.0.0' do
gem 'dummy', '1.0.0'
end
appraise '1.1.1' do
gem 'dummy', '1.1.0'
end
Appraisal
appraise '1.1.0' do
gem 'dummy', '1.1.0'
end
Appraisal

run_simple 'appraisal generate'
run_simple 'appraisal generate'

expect_file('gemfiles/1.0.0.gemfile').to be_exists
expect_file('gemfiles/1.1.0.gemfile').to be_exists
expect_file('gemfiles/1.0.0.gemfile').content.to eq <<-gemfile.strip_heredoc
source 'https://rubygems.org'
expect_file('gemfiles/1.0.0.gemfile').to be_exists
expect_file('gemfiles/1.1.0.gemfile').to be_exists
expect_file('gemfiles/1.0.0.gemfile').to contains <<-gemfile.strip_heredoc
# This file was generated by Appraisal
gem 'dummy', '1.0.0'
gemfile
source "https://rubygems.org"
gem "appraisal", :path=>"../../"
gem "dummy", "1.0.0"
gemfile
end
end
end
11 changes: 4 additions & 7 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
require 'rubygems'
require 'bundler/setup'
require 'aruba/api'
require 'active_support/core_ext/string/strip'
require './features/support/dependency_helpers'
require './spec/support/acceptance_test_helpers'

PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..')).freeze
TMP_GEM_ROOT = File.join(PROJECT_ROOT, "tmp", "gems")

Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f }

RSpec.configure do |config|
config.include Aruba::Api
config.include AppraisalHelpers
config.include DependencyHelpers
config.include AcceptanceTestHelpers, :type => :acceptance, :example_group => {
:file_path => %r{spec\/acceptance\/}
}
end
105 changes: 105 additions & 0 deletions spec/support/acceptance_test_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
require 'rspec/expectations/expectation_target'
require 'active_support/core_ext/string/strip'
require 'active_support/concern'
require './features/support/dependency_helpers'

module AcceptanceTestHelpers
extend ActiveSupport::Concern
include Aruba::Api
include DependencyHelpers

included do
metadata[:type] = :acceptance

before :all do
initialize_aruba_instance_variables
end

before do
cleanup_artifacts
build_default_dummy_gems
unset_bundler_env_vars
ENV["GEM_PATH"] = [TMP_GEM_ROOT, ENV["GEM_PATH"]].join(":")
end

after do
restore_env
end
end

def build_appraisal_file(content)
write_file 'Appraisals', content.strip_heredoc
end

def build_gemfile(content)
write_file 'Gemfile', content.strip_heredoc
end

def expect_file(filename)
expect(filename)
end

def contains(expected)
FileContentMatcher.new(expected)
end

def be_exists
FileExistsMatcher.new
end

private

def cleanup_artifacts
FileUtils.rm_rf(current_dir)
end

def initialize_aruba_instance_variables
@announce_stdout = nil
@announce_stderr = nil
@announce_cmd = nil
@announce_dir = nil
@announce_env = nil
@aruba_timeout_seconds = 60
@aruba_io_wait_seconds = nil
end

def build_default_dummy_gems
FileUtils.rm_rf(TMP_GEM_ROOT)
FileUtils.mkdir_p(TMP_GEM_ROOT)

build_gem 'dummy', '1.0.0'
build_gem 'dummy', '1.1.0'
build_gemfile <<-Gemfile
source 'https://rubygems.org'
gem 'dummy'
gem 'appraisal', :path => '../../'
Gemfile
end

class FileExistsMatcher
include Aruba::Api

def matches?(expected)
@expected = expected
in_current_dir { File.exists?(@expected) }
end

def failure_message_for_should
"file #{@expected.inspect} does not exist.\n"
end

def failure_message_for_should_not
"file #{@expected.inspect} exists.\n"
end
end

class FileContentMatcher < RSpec::Matchers::BuiltIn::Eq
include Aruba::Api

def matches?(filename)
@actual = in_current_dir { File.read(filename) }
expected == actual
end
end
end
41 changes: 0 additions & 41 deletions spec/support/appraisal_helpers.rb

This file was deleted.

0 comments on commit d69021c

Please sign in to comment.