bundler-fixture 1.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2090727bfc13bfae0b6173146aa05fc7c237ddca
4
- data.tar.gz: ff065db51f45f0157b19ff070ac966aa389040f3
3
+ metadata.gz: 325d6cee72122a5efbdd6cae02fc8b7835387588
4
+ data.tar.gz: 4bc227d2f1ded990d61beeb4a1eda6fdd49fa61d
5
5
  SHA512:
6
- metadata.gz: 1d94a93f92acc1c3183114f4757f634bc527010f00c1275e93013f76f5894e569109ce5bce9810626cd2bf52b4b41c8e19c6c5017381393e08bd1d00abe69467
7
- data.tar.gz: 317b5b02029abe98693b78b4c7af9971c18763d671fedd7cfa3d28ae871ea1fee89fa74386f08343653557ce58d132a04b93393395b23d929cc49a83cbc8caa7
6
+ metadata.gz: 0ecabe68e5d6026e8dbe7e2bdd97212f531274753dc76bafd7a4a7ec8c5611d1d0ba111d126b98eec300909ad17cf551a27b7d02322d2b01486f8121dd496988
7
+ data.tar.gz: d7ff261ac62c34791379a361935e091b07292ac03955c7ca41e54e4f821a442d3d03d92ed21c5cb2a5c13cf91650b236598862c3efdcf43b392c1cc058223f9f
data/.travis.yml CHANGED
@@ -28,4 +28,8 @@ matrix:
28
28
  - rvm: 2.2.7
29
29
  env: BUNDLER_TEST_VERSION=1.14.6
30
30
  - rvm: 2.3.4
31
- env: BUNDLER_TEST_VERSION=1.15.0.pre.4
31
+ env: BUNDLER_TEST_VERSION=1.15.0
32
+ - rvm: 2.1.10
33
+ env: BUNDLER_TEST_VERSION=1.15.0
34
+ - rvm: 2.2.7
35
+ env: BUNDLER_TEST_VERSION=1.15.0
@@ -1,5 +1,5 @@
1
1
  module Bundler
2
2
  module Fixture
3
- VERSION = '1.4.0'
3
+ VERSION = '1.5.0'
4
4
  end
5
5
  end
@@ -5,6 +5,10 @@ require 'tmpdir'
5
5
  class BundlerFixture
6
6
  attr_reader :dir
7
7
 
8
+ def self.bundler_version_or_higher(version)
9
+ Gem::Version.new(Bundler::VERSION) >= Gem::Version.new(version)
10
+ end
11
+
8
12
  def initialize(dir: File.join(Dir.tmpdir, 'fake_project_root'), gemfile: 'Gemfile')
9
13
  @dir = dir
10
14
  @gemfile = gemfile
@@ -14,6 +18,10 @@ class BundlerFixture
14
18
  @sources.add_rubygems_remote('https://rubygems.org')
15
19
  end
16
20
 
21
+ def bundler_version_or_higher(version)
22
+ self.class.bundler_version_or_higher(version)
23
+ end
24
+
17
25
  def clean_up
18
26
  FileUtils.rmtree @dir
19
27
  end
@@ -28,19 +36,21 @@ class BundlerFixture
28
36
  source_specs: [],
29
37
  ensure_sources: true,
30
38
  update_gems: [],
31
- gemfile: nil)
39
+ gemfile: nil,
40
+ ruby_version: nil)
32
41
  @gemfile = gemfile if gemfile
33
- defn = create_definition(gem_dependencies: gem_dependencies,
34
- source_specs: source_specs,
35
- ensure_sources: ensure_sources,
36
- update_gems: update_gems)
37
- defn.lock(lockfile_filename)
42
+ dfn = create_definition(gem_dependencies: gem_dependencies,
43
+ source_specs: source_specs,
44
+ ensure_sources: ensure_sources,
45
+ update_gems: update_gems,
46
+ ruby_version: ruby_version)
47
+ dfn.lock(lockfile_filename)
38
48
  end
39
49
 
40
- def create_definition(gem_dependencies:, source_specs:, ensure_sources:, update_gems:)
50
+ def create_definition(gem_dependencies:, source_specs:, ensure_sources:, update_gems:, ruby_version: nil)
41
51
  index = Bundler::Index.new
42
52
  Array(source_specs).flatten.each { |s| index << s }
43
- if Gem::Version.new(Bundler::VERSION) >= Gem::Version.new('1.14.0')
53
+ if bundler_version_or_higher('1.14.0')
44
54
  index << Gem::Specification.new("ruby\0", Bundler::RubyVersion.system.to_gem_version_with_patchlevel)
45
55
  index << Gem::Specification.new("rubygems\0", Gem::VERSION)
46
56
  end
@@ -50,12 +60,55 @@ class BundlerFixture
50
60
  end if ensure_sources
51
61
 
52
62
  update_hash = update_gems === true ? true : {gems: Array(update_gems)}
53
- defn = Bundler::Definition.new(lockfile_filename, Array(gem_dependencies), @sources, update_hash)
54
- defn.instance_variable_set('@index', index)
63
+ ruby_version_obj = Bundler::RubyVersion.new(ruby_version, nil, nil, nil)
64
+ dfn = Bundler::Definition.new(lockfile_filename, Array(gem_dependencies), @sources, update_hash, ruby_version_obj)
65
+ dfn.instance_variable_set('@index', index)
55
66
  # reading an existing lockfile in will overwrite the hacked up sources with detected
56
67
  # ones from lockfile, so this needs to go here after the constructor is called.
57
68
  source.instance_variable_set('@specs', index)
58
- defn
69
+ dfn
70
+ end
71
+
72
+ def create_gemfile(gem_dependencies:, ruby_version: nil)
73
+ lines = []
74
+ lines << "source 'https://rubygems.org'"
75
+ Array(gem_dependencies).each do |spec|
76
+ name, requirement = case spec
77
+ when Array
78
+ spec
79
+ when Gem::Dependency, Bundler::Dependency
80
+ [spec.name, spec.requirement]
81
+ end
82
+ line = "gem '#{name}'"
83
+ if requirement
84
+ req_output = requirement_to_s(requirement)
85
+ line << ", #{req_output}" unless req_output.empty?
86
+ end
87
+ lines << line
88
+ end
89
+ lines << "ruby '#{ruby_version}'" if ruby_version
90
+ File.open(gemfile_filename, 'w') { |f| f.puts lines }
91
+ end
92
+
93
+ def requirement_to_s(req)
94
+ case req
95
+ when Gem::Requirement
96
+ req.as_list.delete_if do |r|
97
+ r == '>= 0'
98
+ end.map do |r|
99
+ "'#{r.gsub(/^= /, '')}'"
100
+ end.join(', ')
101
+ when String
102
+ "'#{req}'"
103
+ when Array
104
+ req.map { |r| "'#{r}'" }.join(', ')
105
+ else
106
+ req
107
+ end
108
+ end
109
+
110
+ def gemfile_filename
111
+ File.join(@dir, "#{@gemfile}")
59
112
  end
60
113
 
61
114
  def lockfile_filename
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bundler-fixture
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - chrismo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-18 00:00:00.000000000 Z
11
+ date: 2017-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler