appraisal 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 18c8641eb507a5a88d169b42f0b7f30c2aac144b
4
- data.tar.gz: 5cb6384b487d939ff578c4f7e65c436632a6bd60
3
+ metadata.gz: 902024f31f3dd843bcc2b0756bce28c81c93cc3e
4
+ data.tar.gz: 0f3be37d8d7f30686971857371723cacd89dd1b0
5
5
  SHA512:
6
- metadata.gz: 8d1db3a083df8492fff63e046d57bdb05fbe24779e2b3c0262a0cfdb58c72cbeec1598a26eee03eed46ccdb1e99e64770e9f076afd2f76018471572d6593dc25
7
- data.tar.gz: 0823f36867e229073caad10ae47ccb0cc3d2c3660832e7414e167b77809c3c960ea2a8faeed301f84f7470a2a0c389c7e7d142ab9ee9930b99abfc97d1975b81
6
+ metadata.gz: 084bc598430ce3fac142d1ce4f00e59f7d612e1be8da20a18c33d12d6ecb9caac991b88431e2975b38427e8a3162d7f6d1101ebcefd5572a4db4772a8e523e50
7
+ data.tar.gz: 282c02041c422bb54cafadcc59a7315e4ee87392cccedb0c302f03ab197e08c1803ee0a9a92f98b2ef6330b312bfbcb5a411468f33a9f92fc0d2f89ed8d3e603
@@ -1,9 +1,12 @@
1
+ sudo: false
2
+
1
3
  before_install: gem install bundler
2
4
 
3
5
  rvm:
4
- - 1.9.3
5
- - 2.0.0
6
- - 2.1.2
6
+ - 1.9
7
+ - 2.0
8
+ - 2.1
9
+ - 2.2
7
10
  - rbx-2
8
11
  - jruby-19mode
9
12
  - ruby-head
@@ -49,16 +49,23 @@ module Appraisal
49
49
  def write_gemfile
50
50
  ::File.open(gemfile_path, "w") do |file|
51
51
  signature = "# This file was generated by Appraisal"
52
- file.puts([signature, gemfile.to_s].reject {|s| s.empty? }.join("\n\n"))
52
+ file.puts([signature, gemfile.to_s].join("\n\n"))
53
53
  end
54
54
  end
55
55
 
56
56
  def install(job_size = 1)
57
- Command.new(check_command + ' || ' + install_command(job_size)).run
57
+ command = [
58
+ check_command,
59
+ "||",
60
+ install_command(job_size)
61
+ ].flatten.join(" ")
62
+
63
+ Command.new(command).run
58
64
  end
59
65
 
60
66
  def update(gems = [])
61
- Command.new(update_command(gems)).run
67
+ command, env = update_command(gems)
68
+ Command.new(command, env: env).run
62
69
  end
63
70
 
64
71
  def gemfile_path
@@ -83,17 +90,18 @@ module Appraisal
83
90
 
84
91
  def check_command
85
92
  gemfile_option = "--gemfile='#{gemfile_path}'"
86
- ['bundle', 'check', gemfile_option].join(' ')
93
+ ['bundle', 'check', gemfile_option]
87
94
  end
88
95
 
89
96
  def install_command(job_size)
90
97
  gemfile_option = "--gemfile='#{gemfile_path}'"
91
- ['bundle', 'install', gemfile_option, bundle_parallel_option(job_size)].compact.join(' ')
98
+ ['bundle', 'install', gemfile_option, bundle_parallel_option(job_size)].compact
92
99
  end
93
100
 
94
101
  def update_command(gems)
95
- gemfile_config = "BUNDLE_GEMFILE='#{gemfile_path}'"
96
- [gemfile_config, 'bundle', 'update', *gems].compact.join(' ')
102
+ env = { "BUNDLE_GEMFILE" => gemfile_path }
103
+ command = ['bundle', 'update', *gems].compact
104
+ [command, env]
97
105
  end
98
106
 
99
107
  def gemfile_root
@@ -75,10 +75,10 @@ module Appraisal
75
75
  matching_appraisal = File.new.appraisals.detect { |appraisal| appraisal.name == name.to_s }
76
76
 
77
77
  if matching_appraisal
78
- Command.new(args.join(' '), matching_appraisal.gemfile_path).run
78
+ Command.new(args, gemfile: matching_appraisal.gemfile_path).run
79
79
  else
80
80
  File.each do |appraisal|
81
- Command.new(ARGV.join(' '), appraisal.gemfile_path).run
81
+ Command.new(ARGV, gemfile: appraisal.gemfile_path).run
82
82
  end
83
83
  end
84
84
  end
@@ -1,28 +1,23 @@
1
+ require "shellwords"
2
+
1
3
  module Appraisal
2
4
  # Executes commands with a clean environment
3
5
  class Command
4
6
  BUNDLER_ENV_VARS = %w(RUBYOPT BUNDLE_PATH BUNDLE_BIN_PATH BUNDLE_GEMFILE).freeze
5
7
 
6
- def self.from_args(gemfile)
7
- ARGV.shift
8
- command = ([$0] + ARGV).join(' ')
9
- new(command, gemfile)
10
- end
8
+ attr_reader :command, :env, :gemfile, :original_env
11
9
 
12
- def initialize(command, gemfile = nil)
10
+ def initialize(command, options = {})
11
+ @gemfile = options[:gemfile]
12
+ @env = options.fetch(:env, {})
13
+ @command = command_starting_with_bundle(command)
13
14
  @original_env = {}
14
- @gemfile = gemfile
15
- if command =~ /^(bundle|BUNDLE_GEMFILE)/
16
- @command = command
17
- else
18
- @command = "bundle exec #{command}"
19
- end
20
15
  end
21
16
 
22
17
  def run
23
18
  announce
24
19
  with_clean_env do
25
- unless Kernel.system(@command)
20
+ unless Kernel.system(env, command_as_string)
26
21
  exit(1)
27
22
  end
28
23
  end
@@ -30,14 +25,14 @@ module Appraisal
30
25
 
31
26
  def exec
32
27
  announce
33
- with_clean_env { Kernel.exec(@command) }
28
+ with_clean_env { Kernel.exec(env, command_as_string) }
34
29
  end
35
30
 
36
31
  private
37
32
 
38
33
  def with_clean_env
39
34
  unset_bundler_env_vars
40
- ENV['BUNDLE_GEMFILE'] = @gemfile
35
+ ENV['BUNDLE_GEMFILE'] = gemfile
41
36
  ENV['APPRAISAL_INITIALIZED'] = '1'
42
37
  yield
43
38
  ensure
@@ -45,22 +40,46 @@ module Appraisal
45
40
  end
46
41
 
47
42
  def announce
48
- if @gemfile
49
- puts ">> BUNDLE_GEMFILE=#{@gemfile} #{@command}"
43
+ if gemfile
44
+ puts ">> BUNDLE_GEMFILE=#{gemfile} #{command_as_string}"
50
45
  else
51
- puts ">> #{@command}"
46
+ puts ">> #{command_as_string}"
52
47
  end
53
48
  end
54
49
 
55
50
  def unset_bundler_env_vars
56
51
  BUNDLER_ENV_VARS.each do |key|
57
- @original_env[key] = ENV[key]
52
+ original_env[key] = ENV[key]
58
53
  ENV[key] = nil
59
54
  end
60
55
  end
61
56
 
62
57
  def restore_env
63
- @original_env.each { |key, value| ENV[key] = value }
58
+ original_env.each { |key, value| ENV[key] = value }
59
+ end
60
+
61
+ def command_starts_with_bundle?(original_command)
62
+ if original_command.is_a?(Array)
63
+ original_command.first =~ /^bundle/
64
+ else
65
+ original_command =~ /^bundle/
66
+ end
67
+ end
68
+
69
+ def command_starting_with_bundle(original_command)
70
+ if command_starts_with_bundle?(original_command)
71
+ original_command
72
+ else
73
+ %w(bundle exec) + original_command
74
+ end
75
+ end
76
+
77
+ def command_as_string
78
+ if command.is_a?(Array)
79
+ Shellwords.join(command)
80
+ else
81
+ command
82
+ end
64
83
  end
65
84
  end
66
85
  end
@@ -12,15 +12,36 @@ module Appraisal
12
12
  end
13
13
 
14
14
  def to_s
15
- if no_requirements?
16
- gem_name
17
- else
18
- "#{gem_name}, #{Utils.format_arguments(requirements)}"
19
- end
15
+ formatted_output Utils.format_arguments(path_prefixed_requirements)
16
+ end
17
+
18
+ # :nodoc:
19
+ def for_dup
20
+ formatted_output Utils.format_arguments(requirements)
20
21
  end
21
22
 
22
23
  private
23
24
 
25
+ def path_prefixed_requirements
26
+ requirements.map do |requirement|
27
+ if requirement.is_a?(Hash)
28
+ if requirement[:path]
29
+ requirement[:path] = Utils.prefix_path(requirement[:path])
30
+ end
31
+
32
+ if requirement[:git]
33
+ requirement[:git] = Utils.prefix_path(requirement[:git])
34
+ end
35
+ end
36
+
37
+ requirement
38
+ end
39
+ end
40
+
41
+ def formatted_output(output_requirements)
42
+ [gem_name, output_requirements].compact.join(", ")
43
+ end
44
+
24
45
  def gem_name
25
46
  %{gem "#{name}"}
26
47
  end
@@ -13,5 +13,10 @@ module Appraisal
13
13
  def to_s
14
14
  @dependencies.values.map(&:to_s).join("\n")
15
15
  end
16
+
17
+ # :nodoc:
18
+ def for_dup
19
+ @dependencies.values.map(&:for_dup).join("\n")
20
+ end
16
21
  end
17
22
  end
@@ -10,6 +10,9 @@ module Appraisal
10
10
  class Gemfile
11
11
  attr_reader :dependencies
12
12
 
13
+ PARTS = %w(source ruby_version git_sources path_sources dependencies groups
14
+ platforms gemspec)
15
+
13
16
  def initialize
14
17
  @sources = []
15
18
  @ruby_version = nil
@@ -38,13 +41,23 @@ module Appraisal
38
41
  @groups[names].run(&block)
39
42
  end
40
43
 
41
- alias_method :groups, :group
44
+ # :nodoc:
45
+ def groups(*names, &block)
46
+ $stderr.puts <<-WARNING.gsub(/\n\s+/, " ").strip
47
+ Warning: `#groups` is deprecated and will be removed in 2.0.0.
48
+ Please use `#group` instead.
49
+ WARNING
50
+
51
+ group(*names, &block)
52
+ end
42
53
 
43
54
  def platforms(*names, &block)
44
55
  @platforms[names] ||= Platform.new(names)
45
56
  @platforms[names].run(&block)
46
57
  end
47
58
 
59
+ alias_method :platform, :platforms
60
+
48
61
  def source(source)
49
62
  @sources << source
50
63
  end
@@ -64,60 +77,67 @@ module Appraisal
64
77
  end
65
78
 
66
79
  def to_s
67
- [source_entry,
68
- ruby_version_entry,
69
- git_sources_entry,
70
- path_sources_entry,
71
- dependencies_entry,
72
- groups_entry,
73
- platforms_entry,
74
- gemspec_entry].reject{ |s| s.nil? || s.empty? }.join("\n\n").strip
80
+ Utils.join_parts PARTS.map { |part| send("#{part}_entry") }
75
81
  end
76
82
 
77
83
  def dup
78
- gemfile = Gemfile.new
79
- gemfile.run(to_s)
80
- gemfile
84
+ Gemfile.new.tap do |gemfile|
85
+ gemfile.run(
86
+ Utils.join_parts PARTS.map { |part| send("#{part}_entry_for_dup") }
87
+ )
88
+ end
81
89
  end
82
90
 
83
91
  def gemspec(options = {})
84
92
  @gemspec = Gemspec.new(options)
85
93
  end
86
94
 
87
- protected
95
+ private
88
96
 
89
97
  def source_entry
90
98
  @sources.map { |source| "source #{source.inspect}" }.join("\n")
91
99
  end
92
100
 
101
+ alias_method :source_entry_for_dup, :source_entry
102
+
93
103
  def ruby_version_entry
94
104
  if @ruby_version
95
105
  "ruby #{@ruby_version.inspect}"
96
106
  end
97
107
  end
98
108
 
99
- def git_sources_entry
100
- @git_sources.values.map(&:to_s).join("\n\n")
101
- end
109
+ alias_method :ruby_version_entry_for_dup, :ruby_version_entry
102
110
 
103
- def path_sources_entry
104
- @path_sources.values.map(&:to_s).join("\n\n")
105
- end
111
+ [:dependencies, :gemspec].each do |method_name|
112
+ class_eval <<-METHODS, __FILE__, __LINE__
113
+ private
106
114
 
107
- def dependencies_entry
108
- @dependencies.to_s
109
- end
115
+ def #{method_name}_entry
116
+ if @#{method_name}
117
+ @#{method_name}.to_s
118
+ end
119
+ end
110
120
 
111
- def groups_entry
112
- @groups.values.map(&:to_s).join("\n\n")
121
+ def #{method_name}_entry_for_dup
122
+ if @#{method_name}
123
+ @#{method_name}.for_dup
124
+ end
125
+ end
126
+ METHODS
113
127
  end
114
128
 
115
- def platforms_entry
116
- @platforms.values.map(&:to_s).join("\n\n")
117
- end
129
+ [:git_sources, :path_sources, :platforms, :groups].each do |method_name|
130
+ class_eval <<-METHODS, __FILE__, __LINE__
131
+ private
132
+
133
+ def #{method_name}_entry
134
+ @#{method_name}.values.map(&:to_s).join("\n\n")
135
+ end
118
136
 
119
- def gemspec_entry
120
- @gemspec.to_s
137
+ def #{method_name}_entry_for_dup
138
+ @#{method_name}.values.map(&:for_dup).join("\n\n")
139
+ end
140
+ METHODS
121
141
  end
122
142
  end
123
143
  end
@@ -13,18 +13,17 @@ module Appraisal
13
13
  "gemspec #{Utils.format_string(exported_options)}"
14
14
  end
15
15
 
16
+ # :nodoc:
17
+ def for_dup
18
+ "gemspec #{Utils.format_string(@options)}"
19
+ end
20
+
16
21
  private
17
22
 
18
23
  def exported_options
19
- # Check to see if this is an absolute path
20
- if @options[:path] =~ /^(?:\/|\S:)/ || @options[:path] == '../'
21
- @options
22
- else
23
- # Remove leading ./ from path, if any
24
- cleaned_path = @options[:path].gsub(/(^|\/)\.\/?/, '\1')
25
- exported_path = ::File.join("..", cleaned_path)
26
- @options.merge(:path => exported_path)
27
- end
24
+ @options.merge(
25
+ path: Utils.prefix_path(@options[:path])
26
+ )
28
27
  end
29
28
  end
30
29
  end
@@ -20,6 +20,18 @@ module Appraisal
20
20
  def to_s
21
21
  dependencies = @dependencies.to_s.strip.gsub(/^/, ' ')
22
22
 
23
+ if @options.empty?
24
+ "git #{Utils.prefix_path(@source).inspect} do\n#{dependencies}\nend"
25
+ else
26
+ "git #{Utils.prefix_path(@source).inspect}, #{Utils.format_string(@options)} do\n" +
27
+ "#{dependencies}\nend"
28
+ end
29
+ end
30
+
31
+ # :nodoc:
32
+ def for_dup
33
+ dependencies = @dependencies.for_dup.strip.gsub(/^/, ' ')
34
+
23
35
  if @options.empty?
24
36
  "git #{@source.inspect} do\n#{dependencies}\nend"
25
37
  else
@@ -6,6 +6,7 @@ module Appraisal
6
6
  def initialize(group_names)
7
7
  @dependencies = DependencyList.new
8
8
  @group_names = group_names
9
+ @gemspec = nil
9
10
  end
10
11
 
11
12
  def run(&block)
@@ -16,9 +17,55 @@ module Appraisal
16
17
  @dependencies.add(name, requirements)
17
18
  end
18
19
 
20
+ def gemspec(options = {})
21
+ @gemspec = Gemspec.new(options)
22
+ end
23
+
19
24
  def to_s
20
- "group #{Utils.format_arguments(@group_names)} do\n" +
21
- @dependencies.to_s.strip.gsub(/^/, ' ') + "\nend"
25
+ formatted_output dependencies_list
26
+ end
27
+
28
+ # :nodoc:
29
+ def for_dup
30
+ formatted_output dependencies_list_for_dup
31
+ end
32
+
33
+ private
34
+
35
+ def dependencies_list
36
+ Utils.join_parts([
37
+ dependencies_entry,
38
+ gemspec_entry
39
+ ]).gsub(/^/, " ")
40
+ end
41
+
42
+ def dependencies_list_for_dup
43
+ Utils.join_parts([
44
+ dependencies_entry,
45
+ gemspec_entry_for_dup
46
+ ]).gsub(/^/, " ")
47
+ end
48
+
49
+ def formatted_output(output_dependencies)
50
+ <<-OUTPUT.strip
51
+ group #{Utils.format_arguments(@group_names)} do
52
+ #{output_dependencies}
53
+ end
54
+ OUTPUT
55
+ end
56
+
57
+ def dependencies_entry
58
+ @dependencies.to_s
59
+ end
60
+
61
+ def gemspec_entry
62
+ @gemspec.to_s
63
+ end
64
+
65
+ def gemspec_entry_for_dup
66
+ if @gemspec
67
+ @gemspec.for_dup
68
+ end
22
69
  end
23
70
  end
24
71
  end
@@ -20,6 +20,18 @@ module Appraisal
20
20
  def to_s
21
21
  dependencies = @dependencies.to_s.strip.gsub(/^/, ' ')
22
22
 
23
+ if @options.empty?
24
+ "path #{Utils.prefix_path(@source).inspect} do\n#{dependencies}\nend"
25
+ else
26
+ "path #{Utils.prefix_path(@source).inspect}, #{Utils.format_string(@options)} do\n" +
27
+ "#{dependencies}\nend"
28
+ end
29
+ end
30
+
31
+ # :nodoc:
32
+ def for_dup
33
+ dependencies = @dependencies.for_dup.strip.gsub(/^/, ' ')
34
+
23
35
  if @options.empty?
24
36
  "path #{@source.inspect} do\n#{dependencies}\nend"
25
37
  else
@@ -21,5 +21,8 @@ module Appraisal
21
21
  @dependencies.to_s.strip.gsub(/^/, ' ') +
22
22
  "\nend"
23
23
  end
24
+
25
+ # :nodoc:
26
+ alias_method :for_dup, :to_s
24
27
  end
25
28
  end
@@ -23,7 +23,22 @@ module Appraisal
23
23
  end
24
24
 
25
25
  def self.format_arguments(arguments)
26
- arguments.map { |object| format_string(object, false) }.join(', ')
26
+ unless arguments.empty?
27
+ arguments.map { |object| format_string(object, false) }.join(', ')
28
+ end
29
+ end
30
+
31
+ def self.join_parts(parts)
32
+ parts.reject(&:nil?).reject(&:empty?).join("\n\n").strip
33
+ end
34
+
35
+ def self.prefix_path(path)
36
+ if path !~ /^(?:\/|\S:)/ && path !~ /^\S+:\/\// && path !~ /^\S+@\S+:/
37
+ cleaned_path = path.gsub(/(^|\/)\.(?:\/|$)/, "\\1")
38
+ ::File.join("..", cleaned_path)
39
+ else
40
+ path
41
+ end
27
42
  end
28
43
  end
29
44
  end
@@ -1,3 +1,3 @@
1
1
  module Appraisal
2
- VERSION = '1.0.2'.freeze
2
+ VERSION = '1.0.3'.freeze
3
3
  end
@@ -68,12 +68,12 @@ describe 'Appraisals file Bundler DSL compatibility' do
68
68
 
69
69
  ruby "1.8.7"
70
70
 
71
- git "../gems/egg" do
71
+ git "../../gems/egg" do
72
72
  gem "egg"
73
73
  gem "porched_egg"
74
74
  end
75
75
 
76
- path "../gems/waffle" do
76
+ path "../../gems/waffle" do
77
77
  gem "waffle"
78
78
  gem "chocolate_waffle"
79
79
  end
@@ -14,6 +14,7 @@ describe 'CLI appraisal (with arguments)' do
14
14
 
15
15
  run 'appraisal install'
16
16
  write_file 'test.rb', 'puts "Running: #{$dummy_version}"'
17
+ write_file 'test with spaces.rb', 'puts "Running: #{$dummy_version}"'
17
18
  end
18
19
 
19
20
  it 'sets APPRAISAL_INITIALIZED environment variable' do
@@ -44,4 +45,12 @@ describe 'CLI appraisal (with arguments)' do
44
45
  expect(output).to include 'Running: 1.1.0'
45
46
  end
46
47
  end
48
+
49
+ context 'when one of the arguments contains spaces' do
50
+ it 'preserves those spaces' do
51
+ command = 'appraisal 1.0.0 ruby -rbundler/setup -rdummy "test with spaces.rb"'
52
+ output = run(command)
53
+ expect(output).to include 'Running: 1.0.0'
54
+ end
55
+ end
47
56
  end
@@ -52,11 +52,11 @@ describe 'Gemfile DSL compatibility' do
52
52
 
53
53
  ruby "#{RUBY_VERSION}"
54
54
 
55
- git "../gems/egg" do
55
+ git "../../gems/egg" do
56
56
  gem "egg"
57
57
  end
58
58
 
59
- path "../gems/orange_juice" do
59
+ path "../../gems/orange_juice" do
60
60
  gem "orange_juice"
61
61
  end
62
62
 
@@ -82,11 +82,11 @@ describe 'Gemfile DSL compatibility' do
82
82
 
83
83
  ruby "#{RUBY_VERSION}"
84
84
 
85
- git "../gems/egg" do
85
+ git "../../gems/egg" do
86
86
  gem "egg"
87
87
  end
88
88
 
89
- path "../gems/orange_juice" do
89
+ path "../../gems/orange_juice" do
90
90
  gem "orange_juice"
91
91
  end
92
92
 
@@ -136,4 +136,37 @@ describe 'Gemfile DSL compatibility' do
136
136
  expect(content_of "gemfiles/1.1.0.gemfile").to include('gem "bacon", "1.1.0"')
137
137
  expect(content_of "gemfiles/1.2.0.gemfile").to include('gem "bacon", "1.2.0"')
138
138
  end
139
+
140
+ it "supports gemspec in the group block" do
141
+ build_gem "bacon", "1.0.0"
142
+ build_gemspec
143
+
144
+ build_gemfile <<-Gemfile
145
+ gem "appraisal", path: #{PROJECT_ROOT.inspect}
146
+
147
+ group :plugin do
148
+ gemspec
149
+ end
150
+ Gemfile
151
+
152
+ build_appraisal_file <<-Appraisals
153
+ appraise "1.0.0" do
154
+ gem "bacon", "1.0.0"
155
+ end
156
+ Appraisals
157
+
158
+ run "bundle install --local"
159
+ run "appraisal generate"
160
+
161
+ expect(content_of "gemfiles/1.0.0.gemfile").to eq <<-gemfile.strip_heredoc
162
+ # This file was generated by Appraisal
163
+
164
+ gem "appraisal", :path => #{PROJECT_ROOT.inspect}
165
+ gem "bacon", "1.0.0"
166
+
167
+ group :plugin do
168
+ gemspec :path => "../"
169
+ end
170
+ gemfile
171
+ end
139
172
  end
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
  require 'appraisal/appraisal'
3
3
  require 'tempfile'
4
- require 'active_support/core_ext/kernel/reporting'
5
4
 
6
5
  describe Appraisal::Appraisal do
7
6
  it "converts spaces to underscores in the gemfile path" do
@@ -30,6 +29,8 @@ describe Appraisal::Appraisal do
30
29
  end
31
30
 
32
31
  context 'parallel installation' do
32
+ include StreamHelpers
33
+
33
34
  before do
34
35
  @appraisal = Appraisal::Appraisal.new('fake', 'fake')
35
36
  allow(@appraisal).to receive(:gemfile_path).and_return("/home/test/test directory")
@@ -3,6 +3,8 @@ require 'appraisal/gemfile'
3
3
  require 'active_support/core_ext/string/strip'
4
4
 
5
5
  describe Appraisal::Gemfile do
6
+ include StreamHelpers
7
+
6
8
  it "supports gemfiles without sources" do
7
9
  gemfile = Appraisal::Gemfile.new
8
10
  expect(gemfile.to_s.strip).to eq ''
@@ -43,6 +45,38 @@ describe Appraisal::Gemfile do
43
45
  GEMFILE
44
46
  end
45
47
 
48
+ it 'supports groups syntax, but with deprecation warning' do
49
+ gemfile = Appraisal::Gemfile.new
50
+
51
+ warning = capture(:stderr) do
52
+ gemfile.groups :development, :test do
53
+ gem "one"
54
+ end
55
+ end
56
+
57
+ expect(gemfile.to_s).to eq <<-GEMFILE.strip_heredoc.strip
58
+ group :development, :test do
59
+ gem "one"
60
+ end
61
+ GEMFILE
62
+
63
+ expect(warning).to match(/deprecated/)
64
+ end
65
+
66
+ it 'supports platform syntax' do
67
+ gemfile = Appraisal::Gemfile.new
68
+
69
+ gemfile.platform :jruby do
70
+ gem "one"
71
+ end
72
+
73
+ expect(gemfile.to_s).to eq <<-GEMFILE.strip_heredoc.strip
74
+ platforms :jruby do
75
+ gem "one"
76
+ end
77
+ GEMFILE
78
+ end
79
+
46
80
  it 'supports platforms syntax' do
47
81
  gemfile = Appraisal::Gemfile.new
48
82
 
@@ -84,4 +118,171 @@ describe Appraisal::Gemfile do
84
118
  end
85
119
  end
86
120
  end
121
+
122
+ context "relative path handling" do
123
+ context "in :path option" do
124
+ it "handles dot path" do
125
+ gemfile = Appraisal::Gemfile.new
126
+ gemfile.gem "bacon", path: "."
127
+
128
+ expect(gemfile.to_s).to eq %(gem "bacon", :path => "../")
129
+ end
130
+
131
+ it "handles relative path" do
132
+ gemfile = Appraisal::Gemfile.new
133
+ gemfile.gem "bacon", path: "../bacon"
134
+
135
+ expect(gemfile.to_s).to eq %(gem "bacon", :path => "../../bacon")
136
+ end
137
+
138
+ it "handles absolute path" do
139
+ gemfile = Appraisal::Gemfile.new
140
+ gemfile.gem "bacon", path: "/tmp"
141
+
142
+ expect(gemfile.to_s).to eq %(gem "bacon", :path => "/tmp")
143
+ end
144
+ end
145
+
146
+ context "in :git option" do
147
+ it "handles dot git path" do
148
+ gemfile = Appraisal::Gemfile.new
149
+ gemfile.gem "bacon", git: "."
150
+
151
+ expect(gemfile.to_s).to eq %(gem "bacon", :git => "../")
152
+ end
153
+
154
+ it "handles relative git path" do
155
+ gemfile = Appraisal::Gemfile.new
156
+ gemfile.gem "bacon", git: "../bacon"
157
+
158
+ expect(gemfile.to_s).to eq %(gem "bacon", :git => "../../bacon")
159
+ end
160
+
161
+ it "handles absolute git path" do
162
+ gemfile = Appraisal::Gemfile.new
163
+ gemfile.gem "bacon", git: "/tmp"
164
+
165
+ expect(gemfile.to_s).to eq %(gem "bacon", :git => "/tmp")
166
+ end
167
+
168
+ it "handles git uri" do
169
+ gemfile = Appraisal::Gemfile.new
170
+ gemfile.gem "bacon", git: "git@github.com:bacon/bacon.git"
171
+
172
+ expect(gemfile.to_s).
173
+ to eq %(gem "bacon", :git => "git@github.com:bacon/bacon.git")
174
+ end
175
+ end
176
+
177
+ context "in path block" do
178
+ it "handles dot path" do
179
+ gemfile = Appraisal::Gemfile.new
180
+
181
+ gemfile.path "." do
182
+ gem "bacon"
183
+ end
184
+
185
+ expect(gemfile.to_s).to eq <<-gemfile.strip_heredoc.strip
186
+ path "../" do
187
+ gem "bacon"
188
+ end
189
+ gemfile
190
+ end
191
+
192
+ it "handles relative path" do
193
+ gemfile = Appraisal::Gemfile.new
194
+
195
+ gemfile.path "../bacon" do
196
+ gem "bacon"
197
+ end
198
+
199
+ expect(gemfile.to_s).to eq <<-gemfile.strip_heredoc.strip
200
+ path "../../bacon" do
201
+ gem "bacon"
202
+ end
203
+ gemfile
204
+ end
205
+
206
+ it "handles absolute path" do
207
+ gemfile = Appraisal::Gemfile.new
208
+
209
+ gemfile.path "/tmp" do
210
+ gem "bacon"
211
+ end
212
+
213
+ expect(gemfile.to_s).to eq <<-gemfile.strip_heredoc.strip
214
+ path "/tmp" do
215
+ gem "bacon"
216
+ end
217
+ gemfile
218
+ end
219
+ end
220
+
221
+ context "in git block" do
222
+ it "handles dot git path" do
223
+ gemfile = Appraisal::Gemfile.new
224
+
225
+ gemfile.git "." do
226
+ gem "bacon"
227
+ end
228
+
229
+ expect(gemfile.to_s).to eq <<-gemfile.strip_heredoc.strip
230
+ git "../" do
231
+ gem "bacon"
232
+ end
233
+ gemfile
234
+ end
235
+
236
+ it "handles relative git path" do
237
+ gemfile = Appraisal::Gemfile.new
238
+
239
+ gemfile.git "../bacon" do
240
+ gem "bacon"
241
+ end
242
+
243
+ expect(gemfile.to_s).to eq <<-gemfile.strip_heredoc.strip
244
+ git "../../bacon" do
245
+ gem "bacon"
246
+ end
247
+ gemfile
248
+ end
249
+
250
+ it "handles absolute git path" do
251
+ gemfile = Appraisal::Gemfile.new
252
+
253
+ gemfile.git "/tmp" do
254
+ gem "bacon"
255
+ end
256
+
257
+ expect(gemfile.to_s).to eq <<-gemfile.strip_heredoc.strip
258
+ git "/tmp" do
259
+ gem "bacon"
260
+ end
261
+ gemfile
262
+ end
263
+
264
+ it "handles git uri" do
265
+ gemfile = Appraisal::Gemfile.new
266
+
267
+ gemfile.git "git@github.com:bacon/bacon.git" do
268
+ gem "bacon"
269
+ end
270
+
271
+ expect(gemfile.to_s).to eq <<-gemfile.strip_heredoc.strip
272
+ git "git@github.com:bacon/bacon.git" do
273
+ gem "bacon"
274
+ end
275
+ gemfile
276
+ end
277
+ end
278
+
279
+ context "in gemspec directive" do
280
+ it "handles gemspec path" do
281
+ gemfile = Appraisal::Gemfile.new
282
+ gemfile.gemspec path: "."
283
+
284
+ expect(gemfile.to_s).to eq %(gemspec :path => "../")
285
+ end
286
+ end
287
+ end
87
288
  end
@@ -20,5 +20,41 @@ describe Appraisal::Utils do
20
20
  ':foo, :bar => { :baz => "ball" }'
21
21
  )
22
22
  end
23
+
24
+ it "returns nil if arguments is empty" do
25
+ arguments = []
26
+
27
+ expect(Appraisal::Utils.format_arguments(arguments)).
28
+ to eq(nil)
29
+ end
30
+ end
31
+
32
+ describe ".prefix_path" do
33
+ it "prepends two dots in front of relative path" do
34
+ expect(Appraisal::Utils.prefix_path("test")).to eq "../test"
35
+ end
36
+
37
+ it "replaces single dot with two dots" do
38
+ expect(Appraisal::Utils.prefix_path(".")).to eq "../"
39
+ end
40
+
41
+ it "ignores absolute path" do
42
+ expect(Appraisal::Utils.prefix_path("/tmp")).to eq "/tmp"
43
+ end
44
+
45
+ it "strips out './' from path" do
46
+ expect(Appraisal::Utils.prefix_path("./tmp/./appraisal././")).
47
+ to eq "../tmp/appraisal./"
48
+ end
49
+
50
+ it "does not prefix Git uri" do
51
+ expect(Appraisal::Utils.prefix_path("git@github.com:bacon/bacon.git")).
52
+ to eq "git@github.com:bacon/bacon.git"
53
+ expect(Appraisal::Utils.prefix_path("git://github.com/bacon/bacon.git")).
54
+ to eq "git://github.com/bacon/bacon.git"
55
+ expect(
56
+ Appraisal::Utils.prefix_path("https://github.com/bacon/bacon.git")
57
+ ).to eq("https://github.com/bacon/bacon.git")
58
+ end
23
59
  end
24
60
  end
@@ -1,6 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'bundler/setup'
3
- require './spec/support/acceptance_test_helpers'
3
+ require_relative 'support/acceptance_test_helpers'
4
+ require_relative 'support/stream_helpers'
4
5
 
5
6
  PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..')).freeze
6
7
  TMP_GEM_ROOT = File.join(PROJECT_ROOT, "tmp", "gems")
@@ -149,6 +149,10 @@ module AcceptanceTestHelpers
149
149
  `#{command}`.tap do |output|
150
150
  exitstatus = $?.exitstatus
151
151
 
152
+ if ENV["VERBOSE"]
153
+ puts output
154
+ end
155
+
152
156
  if raise_on_error && exitstatus != 0
153
157
  raise RuntimeError, <<-error_message.strip_heredoc
154
158
  Command #{command.inspect} exited with status #{exitstatus}. Output:
@@ -0,0 +1,20 @@
1
+ require "tempfile"
2
+
3
+ module StreamHelpers
4
+ def capture(stream)
5
+ stream = stream.to_s
6
+ captured_stream = Tempfile.new(stream)
7
+ stream_io = eval("$#{stream}")
8
+ origin_stream = stream_io.dup
9
+ stream_io.reopen(captured_stream)
10
+
11
+ yield
12
+
13
+ stream_io.rewind
14
+ return captured_stream.read
15
+ ensure
16
+ captured_stream.close
17
+ captured_stream.unlink
18
+ stream_io.reopen(origin_stream)
19
+ end
20
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appraisal
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Ferris
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-08-22 00:00:00.000000000 Z
12
+ date: 2015-03-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -133,11 +133,11 @@ files:
133
133
  - spec/appraisal/dependency_list_spec.rb
134
134
  - spec/appraisal/file_spec.rb
135
135
  - spec/appraisal/gemfile_spec.rb
136
- - spec/appraisal/gemspec_spec.rb
137
136
  - spec/appraisal/utils_spec.rb
138
137
  - spec/spec_helper.rb
139
138
  - spec/support/acceptance_test_helpers.rb
140
139
  - spec/support/dependency_helpers.rb
140
+ - spec/support/stream_helpers.rb
141
141
  homepage: http://github.com/thoughtbot/appraisal
142
142
  licenses:
143
143
  - MIT
@@ -158,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
158
  version: '0'
159
159
  requirements: []
160
160
  rubyforge_project:
161
- rubygems_version: 2.2.2
161
+ rubygems_version: 2.4.6
162
162
  signing_key:
163
163
  specification_version: 4
164
164
  summary: Find out what your Ruby gems are worth
@@ -178,8 +178,8 @@ test_files:
178
178
  - spec/appraisal/dependency_list_spec.rb
179
179
  - spec/appraisal/file_spec.rb
180
180
  - spec/appraisal/gemfile_spec.rb
181
- - spec/appraisal/gemspec_spec.rb
182
181
  - spec/appraisal/utils_spec.rb
183
182
  - spec/spec_helper.rb
184
183
  - spec/support/acceptance_test_helpers.rb
185
184
  - spec/support/dependency_helpers.rb
185
+ - spec/support/stream_helpers.rb
@@ -1,22 +0,0 @@
1
- require 'spec_helper'
2
- require 'appraisal/gemspec'
3
-
4
- describe Appraisal::Gemspec do
5
- describe '#to_s' do
6
- context 'when path is an absolute path' do
7
- it 'returns the path as-is' do
8
- gemspec = Appraisal::Gemspec.new(path: '/tmp')
9
-
10
- expect(gemspec.to_s).to eq 'gemspec :path => "/tmp"'
11
- end
12
- end
13
-
14
- context 'when path contains "./"' do
15
- it 'strips out "./"' do
16
- gemspec = Appraisal::Gemspec.new(path: './tmp/./appraisal././')
17
-
18
- expect(gemspec.to_s).to eq 'gemspec :path => "../tmp/appraisal./"'
19
- end
20
- end
21
- end
22
- end