bundler-fixture 1.0.0 → 1.1.0
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 +4 -4
- data/README.md +1 -1
- data/lib/bundler/fixture.rb +32 -15
- data/lib/bundler/fixture/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 328c063e3081afbff01115411e74caa3211e8a29
|
4
|
+
data.tar.gz: adca5bb74103d747276fdf1b0a4125992b92b83f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0de9cc4828b61f5a1e80a49e9e43679018effb35a5d792dd4b6a59f505ad368008549a5a5225c091c0d98ce9244526eb79be8a8e3bc263132294e1e4f3e99a8
|
7
|
+
data.tar.gz: 03d183d243225dc0534ab62eb125776f411a1af423fc4c493520fe294fe64daedf789daa3e67cedf06fe492a1cbfe6663c32f8ad96d0ec8696699ba109629a61
|
data/README.md
CHANGED
@@ -25,7 +25,7 @@ Or install it yourself as:
|
|
25
25
|
require 'bundler/fixture'
|
26
26
|
|
27
27
|
bf = BundlerFixture.new(dir: Dir.tmpdir)
|
28
|
-
bf.create_lockfile(
|
28
|
+
bf.create_lockfile(gem_dependencies: bf.create_dependency('foo', '1.4.5'))
|
29
29
|
|
30
30
|
`BundlerFixture` takes the gem specs and builds an index with the contents, and sets up other dependencies so a `Gemfile.lock` can be built reflecting the dependency tree in all of the passed specs with `Bundler::Definition`. This ensures `Bundler::LockfileParser` will be able to parse the file successfully, handy for testing your own code that's working programatically with its output.
|
31
31
|
|
data/lib/bundler/fixture.rb
CHANGED
@@ -6,31 +6,47 @@ class BundlerFixture
|
|
6
6
|
def initialize(dir: File.join(Dir.tmpdir, 'fake_project_root'))
|
7
7
|
@dir = dir
|
8
8
|
FileUtils.makedirs @dir
|
9
|
+
|
10
|
+
@sources = Bundler::SourceList.new
|
11
|
+
@sources.add_rubygems_remote('https://rubygems.org')
|
9
12
|
end
|
10
13
|
|
11
14
|
def clean_up
|
12
15
|
FileUtils.rmtree @dir
|
13
16
|
end
|
14
17
|
|
15
|
-
|
16
|
-
|
18
|
+
# @param [Gem::Specification] gem_dependencies This simulates gem requirements in Gemfile.
|
19
|
+
# @param [Gem::Specification] source_specs This simulates gems in the source index.
|
20
|
+
# @param [boolean] ensure_sources Default is true, makes sure a source exists for each gem_dependency.
|
21
|
+
# Set this to false to require sending in sources in @param source_specs.
|
22
|
+
def create_lockfile(gem_dependencies:, source_specs: [], ensure_sources: true)
|
17
23
|
index = Bundler::Index.new
|
18
|
-
|
19
|
-
|
20
|
-
index << g
|
21
|
-
deps << Bundler::DepProxy.new(Bundler::Dependency.new(g.name, g.version), g.platform)
|
22
|
-
end
|
23
|
-
spec_set = Bundler::Resolver.resolve(deps, index)
|
24
|
+
Array(source_specs).each { |s| index << s }
|
25
|
+
source.instance_variable_set('@specs', index)
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
-
|
27
|
+
Array(gem_dependencies).each do |dep|
|
28
|
+
index << create_spec(dep.name, dep.requirement.requirements.first.last)
|
29
|
+
end if ensure_sources
|
28
30
|
|
29
|
-
|
30
|
-
defn = Bundler::Definition.new(gemfile_fn, deps.map(&:dep), sources, true)
|
31
|
+
defn = Bundler::Definition.new(lockfile_filename, Array(gem_dependencies), @sources, {})
|
31
32
|
defn.instance_variable_set('@index', index)
|
32
|
-
defn.
|
33
|
-
|
33
|
+
defn.lock(lockfile_filename)
|
34
|
+
end
|
35
|
+
|
36
|
+
def lockfile_filename
|
37
|
+
File.join(@dir, 'Gemfile.lock')
|
38
|
+
end
|
39
|
+
|
40
|
+
def lockfile_contents
|
41
|
+
File.read(lockfile_filename)
|
42
|
+
end
|
43
|
+
|
44
|
+
def create_dependency(name, *requirements)
|
45
|
+
Bundler::Dependency.new(name, requirements, {'source' => source})
|
46
|
+
end
|
47
|
+
|
48
|
+
def source
|
49
|
+
@sources.all_sources.first
|
34
50
|
end
|
35
51
|
|
36
52
|
def create_spec(name, version, dependencies={})
|
@@ -38,6 +54,7 @@ class BundlerFixture
|
|
38
54
|
s.name = name
|
39
55
|
s.version = Gem::Version.new(version)
|
40
56
|
s.platform = 'ruby'
|
57
|
+
s.source = source
|
41
58
|
dependencies.each do |name, requirement|
|
42
59
|
s.add_dependency name, requirement
|
43
60
|
end
|
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
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- chrismo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|