bundler-fixture 1.0.0 → 1.1.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: 75221a464952c7a7e15ed2f89fd1e92f6a4e3ef7
4
- data.tar.gz: 6c9bce77f8597ed4ef05581978cc44e6e3cb7eb4
3
+ metadata.gz: 328c063e3081afbff01115411e74caa3211e8a29
4
+ data.tar.gz: adca5bb74103d747276fdf1b0a4125992b92b83f
5
5
  SHA512:
6
- metadata.gz: 508ec05c652c3b9049d59662f8b7b5a995786207907cb6148d6c5fae464bdc27afccf959e14ade30d364434301ed4889d5c0c949804df85a91edee145213c49e
7
- data.tar.gz: a580b2642fe0718185a7d5f7b2db23b1ce7908e70d49d6981cef6a35cf049f1e43cf0629533e7ab26f1f746d0b6c69592c17b1553711059a2061ba899ea5133b
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(gem_specs: bf.create_spec('foo', '1.4.5'))
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
 
@@ -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
- def create_lockfile(gem_specs:)
16
- dir = @dir
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
- deps = []
19
- gem_specs.each do |g|
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
- sources = Bundler::SourceList.new
26
- sources.add_rubygems_remote('https://rubygems.org')
27
- spec_set.each { |s| s.source = sources.rubygems_sources.first }
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
- gemfile_fn = File.join(dir, 'Gemfile.lock')
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.instance_variable_set('@resolve', spec_set)
33
- defn.lock(gemfile_fn)
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
@@ -1,5 +1,5 @@
1
1
  module Bundler
2
2
  module Fixture
3
- VERSION = '1.0.0'
3
+ VERSION = '1.1.0'
4
4
  end
5
5
  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.0.0
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 00:00:00.000000000 Z
11
+ date: 2016-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler