safedep 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +2 -0
- data/README.md +1 -1
- data/lib/safedep/gemfile_lock.rb +2 -18
- data/lib/safedep/runner.rb +14 -11
- data/lib/safedep/version.rb +1 -1
- data/safedep.gemspec +1 -2
- data/spec/safedep/runner_spec.rb +23 -2
- data/spec/support/shared_contexts.rb +6 -6
- metadata +9 -43
- data/lib/safedep/abstract_dependency.rb +0 -80
- data/lib/safedep/abstract_gemfile.rb +0 -50
- data/lib/safedep/gemfile/dependency.rb +0 -61
- data/lib/safedep/gemfile.rb +0 -13
- data/lib/safedep/gemspec/dependency.rb +0 -32
- data/lib/safedep/gemspec.rb +0 -13
- data/lib/safedep/literal.rb +0 -48
- data/lib/safedep/util.rb +0 -16
- data/spec/safedep/gemfile/dependency_spec.rb +0 -231
- data/spec/safedep/gemfile_lock_spec.rb +0 -29
- data/spec/safedep/gemfile_spec.rb +0 -22
- data/spec/safedep/gemspec/dependency_spec.rb +0 -184
- data/spec/safedep/gemspec_spec.rb +0 -22
- data/spec/safedep/literal_spec.rb +0 -49
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9a584134a92b66c3998292d52951e55df40452e
|
4
|
+
data.tar.gz: fa525a409445338e868b3e75e232d6414288e8e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00bb90cf32c7a0b336129c9221d81487270b4c711e687c659e6d7bbc91ae8ad99850e54bc4aa3e059923f3711f0165e008fb4a80197c1e98218d17b2b0aab74a
|
7
|
+
data.tar.gz: 32ea3ddb8ffb4547e7540f79f9a6fee1bdcb2875e960c78916315f8df4feef9541337cb4f405fbf8dc9aa9cff83de686889190df119963f1e9f37e8033e491bb
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
|
11
11
|
* [Using >= Considered Harmful (or, What’s Wrong With >=) « Katz Got Your Tongue?](http://yehudakatz.com/2010/08/21/using-considered-harmful-or-whats-wrong-with/)
|
12
12
|
|
13
|
-
Version specifier with `>=` is considered harmful, then dependencies without version
|
13
|
+
Version specifier with `>=` is considered harmful, then dependencies without version specifier must be super harmful. :)
|
14
14
|
|
15
15
|
## Example
|
16
16
|
|
data/lib/safedep/gemfile_lock.rb
CHANGED
@@ -1,31 +1,15 @@
|
|
1
|
+
require 'gemologist/gemfile_lock'
|
1
2
|
require 'bundler'
|
2
3
|
require 'ostruct'
|
3
4
|
|
4
5
|
module Safedep
|
5
|
-
class GemfileLock
|
6
|
-
attr_reader :path
|
7
|
-
|
8
|
-
def initialize(path)
|
9
|
-
@path = path
|
10
|
-
end
|
11
|
-
|
12
|
-
def find_dependency(name)
|
13
|
-
dependencies.find { |dep| dep.name == name }
|
14
|
-
end
|
15
|
-
|
6
|
+
class GemfileLock < Gemologist::GemfileLock
|
16
7
|
def dependencies
|
17
8
|
@dependencies ||= lockfile.specs + [bundler_dependency]
|
18
9
|
end
|
19
10
|
|
20
11
|
private
|
21
12
|
|
22
|
-
def lockfile
|
23
|
-
@lockfile ||= begin
|
24
|
-
content = File.read(path)
|
25
|
-
Bundler::LockfileParser.new(content)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
13
|
def bundler_dependency
|
30
14
|
OpenStruct.new(name: 'bundler', version: Bundler::VERSION)
|
31
15
|
end
|
data/lib/safedep/runner.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
require 'safedep/configuration'
|
2
|
-
require 'safedep/
|
3
|
-
require 'safedep/gemfile'
|
2
|
+
require 'safedep/error'
|
4
3
|
require 'safedep/gemfile_lock'
|
5
4
|
require 'safedep/policy/sem_ver'
|
6
|
-
require '
|
5
|
+
require 'gemologist'
|
7
6
|
|
8
7
|
module Safedep
|
9
8
|
class Runner
|
@@ -51,27 +50,31 @@ module Safedep
|
|
51
50
|
def gemspec
|
52
51
|
@gemspec ||= begin
|
53
52
|
path = Dir['*.gemspec'].first
|
54
|
-
Gemspec.new(path) if path
|
53
|
+
Gemologist::Gemspec.new(path) if path
|
55
54
|
end
|
56
55
|
end
|
57
56
|
|
58
57
|
def gemfile
|
59
58
|
@gemfile ||= begin
|
60
|
-
|
61
|
-
Gemfile.new(GEMFILE_PATH)
|
59
|
+
check_file_existence!(GEMFILE_PATH)
|
60
|
+
Gemologist::Gemfile.new(GEMFILE_PATH)
|
62
61
|
end
|
63
62
|
end
|
64
63
|
|
65
64
|
def gemfile_lock
|
66
65
|
@gemfile_lock ||= begin
|
67
|
-
|
68
|
-
|
69
|
-
end
|
70
|
-
|
71
|
-
GemfileLock.new(GEMFILE_LOCK_PATH)
|
66
|
+
check_file_existence!(GEMFILE_LOCK_PATH, 'Please run `bundle install`.')
|
67
|
+
Safedep::GemfileLock.new(GEMFILE_LOCK_PATH)
|
72
68
|
end
|
73
69
|
end
|
74
70
|
|
71
|
+
def check_file_existence!(path, additional_message = nil)
|
72
|
+
return if File.exist?(path)
|
73
|
+
message = "#{path} is not found."
|
74
|
+
message << ' ' + additional_message if additional_message
|
75
|
+
fail Error, message
|
76
|
+
end
|
77
|
+
|
75
78
|
def should_ignore?(dependency)
|
76
79
|
return true unless dependency.version_specifiers.empty?
|
77
80
|
return true unless (dependency.groups & configuration.skipped_groups).empty?
|
data/lib/safedep/version.rb
CHANGED
data/safedep.gemspec
CHANGED
@@ -19,7 +19,6 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
20
|
spec.require_paths = ['lib']
|
21
21
|
|
22
|
-
spec.add_runtime_dependency 'parser', '~> 2.2'
|
23
|
-
spec.add_runtime_dependency 'astrolabe', '~> 1.3'
|
24
22
|
spec.add_runtime_dependency 'bundler', '~> 1.7'
|
23
|
+
spec.add_runtime_dependency 'gemologist', '~> 0.1'
|
25
24
|
end
|
data/spec/safedep/runner_spec.rb
CHANGED
@@ -60,9 +60,9 @@ module Safedep
|
|
60
60
|
|
61
61
|
context 'when a dependency specified in Gemfile does not exist in Gemfile.lock', :gemfile, :lockfile do
|
62
62
|
let!(:lockfile) do
|
63
|
-
require '
|
63
|
+
require 'gemologist/gemfile_lock'
|
64
64
|
create_file(lockfile_path, invalid_lockfile_source)
|
65
|
-
|
65
|
+
Gemologist::GemfileLock.new(lockfile_path)
|
66
66
|
end
|
67
67
|
|
68
68
|
let(:invalid_lockfile_source) { lockfile_source.gsub(/.*rspec.*\n/, '') }
|
@@ -72,6 +72,27 @@ module Safedep
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
+
context 'when bundler dependency is specified in gemspec', :gemfile, :lockfile do
|
76
|
+
let!(:gemspec) do
|
77
|
+
require 'gemologist/gemspec'
|
78
|
+
create_file(gemspec_path, gemspec_source)
|
79
|
+
Gemologist::Gemspec.new(gemspec_path)
|
80
|
+
end
|
81
|
+
|
82
|
+
let(:gemspec_path) { 'safedep.gemspec' }
|
83
|
+
|
84
|
+
let(:gemspec_source) { <<-END.strip_indent }
|
85
|
+
Gem::Specification.new do |spec|
|
86
|
+
spec.name = 'safedep'
|
87
|
+
spec.add_runtime_dependency 'bundler'
|
88
|
+
end
|
89
|
+
END
|
90
|
+
|
91
|
+
it 'does not raise error' do
|
92
|
+
expect { runner.run }.not_to raise_error
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
75
96
|
context 'when Configuration#skipped_groups is specified', :gemspec, :gemfile, :lockfile do
|
76
97
|
before do
|
77
98
|
configuration.skipped_groups = ['development']
|
@@ -12,9 +12,9 @@ end
|
|
12
12
|
|
13
13
|
shared_context 'with gemspec', :gemspec do
|
14
14
|
let!(:gemspec) do
|
15
|
-
require '
|
15
|
+
require 'gemologist/gemspec'
|
16
16
|
create_file(gemspec_path, gemspec_source)
|
17
|
-
|
17
|
+
Gemologist::Gemspec.new(gemspec_path)
|
18
18
|
end
|
19
19
|
|
20
20
|
let(:gemspec_path) { 'safedep.gemspec' }
|
@@ -32,9 +32,9 @@ end
|
|
32
32
|
|
33
33
|
shared_context 'with Gemfile', :gemfile do
|
34
34
|
let!(:gemfile) do
|
35
|
-
require '
|
35
|
+
require 'gemologist/gemfile'
|
36
36
|
create_file(gemfile_path, gemfile_source)
|
37
|
-
|
37
|
+
Gemologist::Gemfile.new(gemfile_path)
|
38
38
|
end
|
39
39
|
|
40
40
|
let(:gemfile_path) { 'Gemfile' }
|
@@ -56,9 +56,9 @@ end
|
|
56
56
|
|
57
57
|
shared_context 'with Gemfile.lock', :lockfile do
|
58
58
|
let!(:lockfile) do
|
59
|
-
require '
|
59
|
+
require 'gemologist/gemfile_lock'
|
60
60
|
create_file(lockfile_path, lockfile_source)
|
61
|
-
|
61
|
+
Gemologist::GemfileLock.new(lockfile_path)
|
62
62
|
end
|
63
63
|
|
64
64
|
let(:lockfile_path) { 'Gemfile.lock' }
|
metadata
CHANGED
@@ -1,57 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: safedep
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuji Nakayama
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '2.2'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '2.2'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: astrolabe
|
14
|
+
name: bundler
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
30
16
|
requirements:
|
31
17
|
- - "~>"
|
32
18
|
- !ruby/object:Gem::Version
|
33
|
-
version: '1.
|
19
|
+
version: '1.7'
|
34
20
|
type: :runtime
|
35
21
|
prerelease: false
|
36
22
|
version_requirements: !ruby/object:Gem::Requirement
|
37
23
|
requirements:
|
38
24
|
- - "~>"
|
39
25
|
- !ruby/object:Gem::Version
|
40
|
-
version: '1.
|
26
|
+
version: '1.7'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
28
|
+
name: gemologist
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
44
30
|
requirements:
|
45
31
|
- - "~>"
|
46
32
|
- !ruby/object:Gem::Version
|
47
|
-
version: '1
|
33
|
+
version: '0.1'
|
48
34
|
type: :runtime
|
49
35
|
prerelease: false
|
50
36
|
version_requirements: !ruby/object:Gem::Requirement
|
51
37
|
requirements:
|
52
38
|
- - "~>"
|
53
39
|
- !ruby/object:Gem::Version
|
54
|
-
version: '1
|
40
|
+
version: '0.1'
|
55
41
|
description: Make your Gemfile safe by adding dependency version specifiers automatically.
|
56
42
|
email:
|
57
43
|
- nkymyj@gmail.com
|
@@ -71,31 +57,17 @@ files:
|
|
71
57
|
- README.md
|
72
58
|
- Rakefile
|
73
59
|
- bin/safedep
|
74
|
-
- lib/safedep/abstract_dependency.rb
|
75
|
-
- lib/safedep/abstract_gemfile.rb
|
76
60
|
- lib/safedep/cli.rb
|
77
61
|
- lib/safedep/cli/option_parser.rb
|
78
62
|
- lib/safedep/configuration.rb
|
79
63
|
- lib/safedep/error.rb
|
80
|
-
- lib/safedep/gemfile.rb
|
81
|
-
- lib/safedep/gemfile/dependency.rb
|
82
64
|
- lib/safedep/gemfile_lock.rb
|
83
|
-
- lib/safedep/gemspec.rb
|
84
|
-
- lib/safedep/gemspec/dependency.rb
|
85
|
-
- lib/safedep/literal.rb
|
86
65
|
- lib/safedep/policy/sem_ver.rb
|
87
66
|
- lib/safedep/runner.rb
|
88
|
-
- lib/safedep/util.rb
|
89
67
|
- lib/safedep/version.rb
|
90
68
|
- safedep.gemspec
|
91
69
|
- spec/.rubocop.yml
|
92
70
|
- spec/safedep/cli_spec.rb
|
93
|
-
- spec/safedep/gemfile/dependency_spec.rb
|
94
|
-
- spec/safedep/gemfile_lock_spec.rb
|
95
|
-
- spec/safedep/gemfile_spec.rb
|
96
|
-
- spec/safedep/gemspec/dependency_spec.rb
|
97
|
-
- spec/safedep/gemspec_spec.rb
|
98
|
-
- spec/safedep/literal_spec.rb
|
99
71
|
- spec/safedep/policy/sem_ver_spec.rb
|
100
72
|
- spec/safedep/runner_spec.rb
|
101
73
|
- spec/spec_helper.rb
|
@@ -121,19 +93,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
93
|
version: '0'
|
122
94
|
requirements: []
|
123
95
|
rubyforge_project:
|
124
|
-
rubygems_version: 2.4.
|
96
|
+
rubygems_version: 2.4.6
|
125
97
|
signing_key:
|
126
98
|
specification_version: 4
|
127
99
|
summary: Make your Gemfile safe by adding dependency version specifiers automatically.
|
128
100
|
test_files:
|
129
101
|
- spec/.rubocop.yml
|
130
102
|
- spec/safedep/cli_spec.rb
|
131
|
-
- spec/safedep/gemfile/dependency_spec.rb
|
132
|
-
- spec/safedep/gemfile_lock_spec.rb
|
133
|
-
- spec/safedep/gemfile_spec.rb
|
134
|
-
- spec/safedep/gemspec/dependency_spec.rb
|
135
|
-
- spec/safedep/gemspec_spec.rb
|
136
|
-
- spec/safedep/literal_spec.rb
|
137
103
|
- spec/safedep/policy/sem_ver_spec.rb
|
138
104
|
- spec/safedep/runner_spec.rb
|
139
105
|
- spec/spec_helper.rb
|
@@ -1,80 +0,0 @@
|
|
1
|
-
require 'safedep/literal'
|
2
|
-
|
3
|
-
module Safedep
|
4
|
-
class AbstractDependency
|
5
|
-
attr_reader :node, :rewriter
|
6
|
-
|
7
|
-
def self.valid_node?(node)
|
8
|
-
return false unless node.send_type?
|
9
|
-
_receiver_node, message, name_node, = *node
|
10
|
-
method_names.include?(message) && name_node.str_type?
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.method_names
|
14
|
-
fail NotImplementedError
|
15
|
-
end
|
16
|
-
|
17
|
-
def initialize(node, rewriter)
|
18
|
-
fail 'Invalid node.' unless self.class.valid_node?(node)
|
19
|
-
@node = node
|
20
|
-
@rewriter = rewriter
|
21
|
-
end
|
22
|
-
|
23
|
-
def name
|
24
|
-
name_node.children.first
|
25
|
-
end
|
26
|
-
|
27
|
-
def groups
|
28
|
-
fail NotImplementedError
|
29
|
-
end
|
30
|
-
|
31
|
-
def version_specifiers
|
32
|
-
@version_specifiers ||= version_nodes.map { |node| Literal.value(node) }.flatten
|
33
|
-
end
|
34
|
-
|
35
|
-
def version_specifiers=(*specifiers)
|
36
|
-
source = specifiers.flatten.map { |specifier| "'#{specifier}'" }.join(', ')
|
37
|
-
|
38
|
-
if version_nodes.empty?
|
39
|
-
rewriter.insert_after(name_node.loc.expression, ", #{source}")
|
40
|
-
else
|
41
|
-
rewriter.replace(version_range, source)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def options
|
46
|
-
{}
|
47
|
-
end
|
48
|
-
|
49
|
-
private
|
50
|
-
|
51
|
-
def method_name
|
52
|
-
node.children[1]
|
53
|
-
end
|
54
|
-
|
55
|
-
def name_node
|
56
|
-
node.children[2]
|
57
|
-
end
|
58
|
-
|
59
|
-
def trailing_nodes
|
60
|
-
node.children[3..-1]
|
61
|
-
end
|
62
|
-
|
63
|
-
def version_nodes
|
64
|
-
fail NotImplementedError
|
65
|
-
end
|
66
|
-
|
67
|
-
def version_range
|
68
|
-
version_nodes.first.loc.expression.join(version_nodes.last.loc.expression)
|
69
|
-
end
|
70
|
-
|
71
|
-
def content_range_of_str_node(str_node)
|
72
|
-
map = str_node.loc
|
73
|
-
Parser::Source::Range.new(
|
74
|
-
map.expression.source_buffer,
|
75
|
-
map.begin.end_pos,
|
76
|
-
map.end.begin_pos
|
77
|
-
)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'astrolabe/builder'
|
2
|
-
require 'parser/current'
|
3
|
-
|
4
|
-
module Safedep
|
5
|
-
class AbstractGemfile
|
6
|
-
attr_reader :path
|
7
|
-
|
8
|
-
def initialize(path)
|
9
|
-
@path = path
|
10
|
-
end
|
11
|
-
|
12
|
-
def find_dependency(name)
|
13
|
-
dependencies.find { |dep| dep.name == name }
|
14
|
-
end
|
15
|
-
|
16
|
-
def dependencies
|
17
|
-
@dependencies ||= ast.each_node.with_object([]) do |node, dependencies|
|
18
|
-
next unless dependency_class.valid_node?(node)
|
19
|
-
dependencies << dependency_class.new(node, source_rewriter)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def rewrite!
|
24
|
-
rewritten_source = source_rewriter.process
|
25
|
-
File.write(path, rewritten_source)
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
def dependency_class
|
31
|
-
fail NotImplementedError
|
32
|
-
end
|
33
|
-
|
34
|
-
def ast
|
35
|
-
@ast ||= begin
|
36
|
-
builder = Astrolabe::Builder.new
|
37
|
-
parser = Parser::CurrentRuby.new(builder)
|
38
|
-
parser.parse(source_buffer)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def source_rewriter
|
43
|
-
@source_rewriter ||= Parser::Source::Rewriter.new(source_buffer)
|
44
|
-
end
|
45
|
-
|
46
|
-
def source_buffer
|
47
|
-
@source_buffer ||= Parser::Source::Buffer.new(path).read
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -1,61 +0,0 @@
|
|
1
|
-
require 'safedep/abstract_dependency'
|
2
|
-
require 'safedep/util'
|
3
|
-
require 'astrolabe/sexp'
|
4
|
-
|
5
|
-
module Safedep
|
6
|
-
class Gemfile
|
7
|
-
class Dependency < AbstractDependency
|
8
|
-
include Util, Astrolabe::Sexp
|
9
|
-
|
10
|
-
METHOD_NAMES = [:gem].freeze
|
11
|
-
|
12
|
-
def self.method_names
|
13
|
-
METHOD_NAMES
|
14
|
-
end
|
15
|
-
|
16
|
-
def groups
|
17
|
-
@groups ||= (groups_via_block + groups_via_option).map(&:to_sym)
|
18
|
-
end
|
19
|
-
|
20
|
-
def options
|
21
|
-
@options ||= symbolize_keys(Literal.value(options_node) || {})
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def groups_via_block
|
27
|
-
return [] unless group_node
|
28
|
-
_receiver_node, _message, *arg_nodes = *group_node
|
29
|
-
arg_nodes.map { |node| Literal.value(node) }
|
30
|
-
end
|
31
|
-
|
32
|
-
def groups_via_option
|
33
|
-
Array(options[:group])
|
34
|
-
end
|
35
|
-
|
36
|
-
# https://github.com/bundler/bundler/blob/v1.7.11/lib/bundler/dsl.rb#L68-L70
|
37
|
-
def version_nodes
|
38
|
-
@version_nodes ||= trailing_nodes - [options_node]
|
39
|
-
end
|
40
|
-
|
41
|
-
def options_node
|
42
|
-
node = trailing_nodes.last
|
43
|
-
|
44
|
-
if node && node.hash_type?
|
45
|
-
node
|
46
|
-
else
|
47
|
-
nil
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def group_node
|
52
|
-
candidates = node.each_ancestor(:block).map { |block_node| block_node.children.first }
|
53
|
-
|
54
|
-
candidates.find do |send_node|
|
55
|
-
receiver_node, message, = *send_node
|
56
|
-
receiver_node.nil? && message == :group
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
data/lib/safedep/gemfile.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'safedep/abstract_dependency'
|
2
|
-
require 'safedep/util'
|
3
|
-
|
4
|
-
module Safedep
|
5
|
-
class Gemspec
|
6
|
-
class Dependency < AbstractDependency
|
7
|
-
include Util
|
8
|
-
|
9
|
-
METHOD_NAMES = [:add_runtime_dependency, :add_development_dependency, :add_dependency].freeze
|
10
|
-
|
11
|
-
def self.method_names
|
12
|
-
METHOD_NAMES
|
13
|
-
end
|
14
|
-
|
15
|
-
def groups
|
16
|
-
case method_name
|
17
|
-
when :add_development_dependency
|
18
|
-
[:development]
|
19
|
-
else
|
20
|
-
[]
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
# https://github.com/rubygems/rubygems/blob/v2.4.5/lib/rubygems/specification.rb#L449-L473
|
27
|
-
def version_nodes
|
28
|
-
trailing_nodes
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
data/lib/safedep/gemspec.rb
DELETED
data/lib/safedep/literal.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
module Safedep
|
2
|
-
module Literal
|
3
|
-
module_function
|
4
|
-
|
5
|
-
def value(node)
|
6
|
-
concretize(node)
|
7
|
-
end
|
8
|
-
|
9
|
-
def concretize(node) # rubocop:disable CyclomaticComplexity
|
10
|
-
return nil unless node
|
11
|
-
|
12
|
-
case node.type
|
13
|
-
when :true then true
|
14
|
-
when :false then false
|
15
|
-
when :nil then nil
|
16
|
-
when :int, :float, :str, :sym then node.children.first
|
17
|
-
when :regexp then concretize_regexp(node)
|
18
|
-
when :array then concretize_array(node)
|
19
|
-
when :hash then concretize_hash(node)
|
20
|
-
when :irange, :erange then concretize_range(node)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def concretize_regexp(regexp_node)
|
25
|
-
str_node, *_interporated_nodes, regopt_node = *regexp_node
|
26
|
-
string = str_node.children.first
|
27
|
-
options = regopt_node.children.map(&:to_s).reduce(:+)
|
28
|
-
eval("/#{string}/#{options}") # rubocop:disable Eval
|
29
|
-
end
|
30
|
-
|
31
|
-
def concretize_array(array_node)
|
32
|
-
array_node.children.map { |child_node| concretize(child_node) }
|
33
|
-
end
|
34
|
-
|
35
|
-
def concretize_hash(hash_node)
|
36
|
-
hash_node.children.each_with_object({}) do |pair_node, hash|
|
37
|
-
key_node, value_node = *pair_node
|
38
|
-
key = concretize(key_node)
|
39
|
-
hash[key] = concretize(value_node) if key
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def concretize_range(range_node)
|
44
|
-
values = range_node.children.map { |child_node| concretize(child_node) }
|
45
|
-
Range.new(*values, range_node.type == :erange)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
data/lib/safedep/util.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
module Safedep
|
2
|
-
module Util
|
3
|
-
module_function
|
4
|
-
|
5
|
-
def symbolize_keys(original_hash)
|
6
|
-
hash = original_hash.dup
|
7
|
-
|
8
|
-
original_hash.each do |key, value|
|
9
|
-
hash[key] = symbolize_keys(value) if value.is_a?(Hash)
|
10
|
-
hash[key.to_sym] = hash.delete(key) if key.is_a?(String)
|
11
|
-
end
|
12
|
-
|
13
|
-
hash
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,231 +0,0 @@
|
|
1
|
-
require 'safedep/gemfile'
|
2
|
-
|
3
|
-
module Safedep
|
4
|
-
class Gemfile
|
5
|
-
describe Dependency, :gemfile do
|
6
|
-
include FileHelper
|
7
|
-
include_context 'isolated environment'
|
8
|
-
|
9
|
-
let(:gemfile_source) { <<-END.strip_indent }
|
10
|
-
source 'https://rubygems.org'
|
11
|
-
|
12
|
-
gemspec
|
13
|
-
|
14
|
-
group :development, :test do
|
15
|
-
gem 'rake'
|
16
|
-
gem 'rspec', '~> 3.1'
|
17
|
-
gem 'rubocop', require: false
|
18
|
-
end
|
19
|
-
|
20
|
-
group :development do
|
21
|
-
gem 'guard', '>= 2.1', '< 3.0'
|
22
|
-
end
|
23
|
-
END
|
24
|
-
|
25
|
-
describe '#name' do
|
26
|
-
let(:dependency) { gemfile.dependencies.first }
|
27
|
-
|
28
|
-
it 'returns the name of the gem' do
|
29
|
-
expect(dependency.name).to eq('rake')
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
describe '#groups' do
|
34
|
-
subject { dependency.groups }
|
35
|
-
|
36
|
-
let(:gemfile_source) { <<-END.strip_indent }
|
37
|
-
source 'https://rubygems.org'
|
38
|
-
|
39
|
-
gem 'parser'
|
40
|
-
|
41
|
-
group :development, :test do
|
42
|
-
gem 'rake'
|
43
|
-
end
|
44
|
-
|
45
|
-
group :development do
|
46
|
-
gem 'guard'
|
47
|
-
gem 'rubocop', group: :test
|
48
|
-
end
|
49
|
-
|
50
|
-
group 'development' do
|
51
|
-
gem 'fuubar'
|
52
|
-
end
|
53
|
-
|
54
|
-
gem 'rspec', 'group' => [:test, :development]
|
55
|
-
END
|
56
|
-
|
57
|
-
context 'when the dependency is specified in top level' do
|
58
|
-
let(:dependency) { gemfile.find_dependency('parser') }
|
59
|
-
it { should be_empty }
|
60
|
-
end
|
61
|
-
|
62
|
-
context 'when the dependency is specified in :development block' do
|
63
|
-
let(:dependency) { gemfile.find_dependency('guard') }
|
64
|
-
it { should eq([:development]) }
|
65
|
-
end
|
66
|
-
|
67
|
-
context 'when the dependency is specified in "development" block' do
|
68
|
-
let(:dependency) { gemfile.find_dependency('fuubar') }
|
69
|
-
it { should eq([:development]) }
|
70
|
-
end
|
71
|
-
|
72
|
-
context 'when the dependency is specified in :development and :test group' do
|
73
|
-
let(:dependency) { gemfile.find_dependency('rake') }
|
74
|
-
it { should eq([:development, :test]) }
|
75
|
-
end
|
76
|
-
|
77
|
-
context 'when the dependency is specified with group: [:test, :development] option' do
|
78
|
-
let(:dependency) { gemfile.find_dependency('rspec') }
|
79
|
-
it { should eq([:test, :development]) }
|
80
|
-
end
|
81
|
-
|
82
|
-
context 'when the dependency is specified with group: :test option in :development group' do
|
83
|
-
let(:dependency) { gemfile.find_dependency('rubocop') }
|
84
|
-
it { should eq([:development, :test]) }
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
describe '#version_specifiers' do
|
89
|
-
subject(:version_specifiers) { dependency.version_specifiers }
|
90
|
-
|
91
|
-
context 'when the dependency has a version specifier' do
|
92
|
-
let(:dependency) { gemfile.find_dependency('rspec') }
|
93
|
-
|
94
|
-
it 'returns the specifier' do
|
95
|
-
expect(version_specifiers).to eq(['~> 3.1'])
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
context 'when the dependency has multiple specifiers' do
|
100
|
-
let(:dependency) { gemfile.find_dependency('guard') }
|
101
|
-
|
102
|
-
it 'returns the specifiers' do
|
103
|
-
expect(version_specifiers).to eq(['>= 2.1', '< 3.0'])
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
context 'when the dependency has no version specifier' do
|
108
|
-
context 'and has no options' do
|
109
|
-
let(:dependency) { gemfile.find_dependency('rake') }
|
110
|
-
it { should be_empty }
|
111
|
-
end
|
112
|
-
|
113
|
-
context 'but has options' do
|
114
|
-
let(:dependency) { gemfile.find_dependency('rubocop') }
|
115
|
-
it { should be_empty }
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
describe '#version_specifiers=' do
|
121
|
-
let(:rewritten_source) { File.read(gemfile.path) }
|
122
|
-
|
123
|
-
context 'when the dependency has a version specifier' do
|
124
|
-
let(:dependency) { gemfile.find_dependency('rspec') }
|
125
|
-
|
126
|
-
let(:expected_source) { <<-END.strip_indent }
|
127
|
-
source 'https://rubygems.org'
|
128
|
-
|
129
|
-
gemspec
|
130
|
-
|
131
|
-
group :development, :test do
|
132
|
-
gem 'rake'
|
133
|
-
gem 'rspec', '> 4.0'
|
134
|
-
gem 'rubocop', require: false
|
135
|
-
end
|
136
|
-
|
137
|
-
group :development do
|
138
|
-
gem 'guard', '>= 2.1', '< 3.0'
|
139
|
-
end
|
140
|
-
END
|
141
|
-
|
142
|
-
it 'replaces the existing specifier with the passed specifier' do
|
143
|
-
dependency.version_specifiers = '> 4.0'
|
144
|
-
gemfile.rewrite!
|
145
|
-
expect(rewritten_source).to eq(expected_source)
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
context 'when the dependency has no version specifier' do
|
150
|
-
context 'and has no options' do
|
151
|
-
let(:dependency) { gemfile.find_dependency('rake') }
|
152
|
-
|
153
|
-
let(:expected_source) { <<-END.strip_indent }
|
154
|
-
source 'https://rubygems.org'
|
155
|
-
|
156
|
-
gemspec
|
157
|
-
|
158
|
-
group :development, :test do
|
159
|
-
gem 'rake', '~> 10.1'
|
160
|
-
gem 'rspec', '~> 3.1'
|
161
|
-
gem 'rubocop', require: false
|
162
|
-
end
|
163
|
-
|
164
|
-
group :development do
|
165
|
-
gem 'guard', '>= 2.1', '< 3.0'
|
166
|
-
end
|
167
|
-
END
|
168
|
-
|
169
|
-
it 'adds the passed specifier' do
|
170
|
-
dependency.version_specifiers = '~> 10.1'
|
171
|
-
gemfile.rewrite!
|
172
|
-
expect(rewritten_source).to eq(expected_source)
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
context 'but has options' do
|
177
|
-
let(:dependency) { gemfile.find_dependency('rubocop') }
|
178
|
-
|
179
|
-
let(:expected_source) { <<-END.strip_indent }
|
180
|
-
source 'https://rubygems.org'
|
181
|
-
|
182
|
-
gemspec
|
183
|
-
|
184
|
-
group :development, :test do
|
185
|
-
gem 'rake'
|
186
|
-
gem 'rspec', '~> 3.1'
|
187
|
-
gem 'rubocop', '~> 0.28', require: false
|
188
|
-
end
|
189
|
-
|
190
|
-
group :development do
|
191
|
-
gem 'guard', '>= 2.1', '< 3.0'
|
192
|
-
end
|
193
|
-
END
|
194
|
-
|
195
|
-
it 'adds the passed specifier' do
|
196
|
-
dependency.version_specifiers = '~> 0.28'
|
197
|
-
gemfile.rewrite!
|
198
|
-
expect(rewritten_source).to eq(expected_source)
|
199
|
-
end
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
context 'when multiple specifiers are passed' do
|
204
|
-
let(:dependency) { gemfile.find_dependency('rspec') }
|
205
|
-
|
206
|
-
let(:expected_source) { <<-END.strip_indent }
|
207
|
-
source 'https://rubygems.org'
|
208
|
-
|
209
|
-
gemspec
|
210
|
-
|
211
|
-
group :development, :test do
|
212
|
-
gem 'rake'
|
213
|
-
gem 'rspec', '>= 4.0', '< 5.0'
|
214
|
-
gem 'rubocop', require: false
|
215
|
-
end
|
216
|
-
|
217
|
-
group :development do
|
218
|
-
gem 'guard', '>= 2.1', '< 3.0'
|
219
|
-
end
|
220
|
-
END
|
221
|
-
|
222
|
-
it 'replaces the existing specifier with the passed specifiers' do
|
223
|
-
dependency.version_specifiers = ['>= 4.0', '< 5.0']
|
224
|
-
gemfile.rewrite!
|
225
|
-
expect(rewritten_source).to eq(expected_source)
|
226
|
-
end
|
227
|
-
end
|
228
|
-
end
|
229
|
-
end
|
230
|
-
end
|
231
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'safedep/gemfile_lock'
|
2
|
-
|
3
|
-
module Safedep
|
4
|
-
describe GemfileLock, :lockfile do
|
5
|
-
include FileHelper
|
6
|
-
include_context 'isolated environment'
|
7
|
-
|
8
|
-
describe '#find_dependency' do
|
9
|
-
it 'returns the dependency matching the passed name' do
|
10
|
-
dependency = lockfile.find_dependency('rspec')
|
11
|
-
expect(dependency.name).to eq('rspec')
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe '#dependencies' do
|
16
|
-
let(:dep_names) { lockfile.dependencies.map(&:name) }
|
17
|
-
|
18
|
-
it 'returns an array of the specifications' do
|
19
|
-
expect(dep_names).to include('rake', 'rspec', 'rubocop')
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'includes "bundler" dependency' do
|
23
|
-
dependency = lockfile.find_dependency('bundler')
|
24
|
-
expect(dependency.name).to eq('bundler')
|
25
|
-
expect(dependency.version).to eq(Bundler::VERSION)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'safedep/gemfile'
|
2
|
-
|
3
|
-
module Safedep
|
4
|
-
describe Gemfile, :gemfile do
|
5
|
-
include FileHelper
|
6
|
-
include_context 'isolated environment'
|
7
|
-
|
8
|
-
describe '#find_dependency' do
|
9
|
-
it 'returns the dependency matching the passed name' do
|
10
|
-
dependency = gemfile.find_dependency('rspec')
|
11
|
-
expect(dependency.name).to eq('rspec')
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe '#dependencies' do
|
16
|
-
it 'returns an array of the dependencies' do
|
17
|
-
expect(gemfile.dependencies.size).to eq(3)
|
18
|
-
expect(gemfile.dependencies).to all be_a(Gemfile::Dependency)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,184 +0,0 @@
|
|
1
|
-
require 'safedep/gemspec'
|
2
|
-
|
3
|
-
module Safedep
|
4
|
-
class Gemspec
|
5
|
-
describe Dependency, :gemspec do
|
6
|
-
include FileHelper
|
7
|
-
include_context 'isolated environment'
|
8
|
-
|
9
|
-
let(:gemspec_source) { <<-END.strip_indent }
|
10
|
-
Gem::Specification.new do |spec|
|
11
|
-
spec.name = 'safedep'
|
12
|
-
spec.add_dependency 'parser'
|
13
|
-
spec.add_runtime_dependency 'bundler', '>= 1.3.1', '< 2.0'
|
14
|
-
spec.add_runtime_dependency 'astrolabe', ['>= 1.3', '< 2.0']
|
15
|
-
spec.add_development_dependency 'rspec', '~> 3.1'
|
16
|
-
end
|
17
|
-
END
|
18
|
-
|
19
|
-
describe '#name' do
|
20
|
-
let(:dependency) { gemspec.dependencies.first }
|
21
|
-
|
22
|
-
it 'returns the name of the gem' do
|
23
|
-
expect(dependency.name).to eq('parser')
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe '#groups' do
|
28
|
-
subject { dependency.groups }
|
29
|
-
|
30
|
-
context 'when the dependency is specified via #add_dependency' do
|
31
|
-
let(:dependency) { gemspec.find_dependency('parser') }
|
32
|
-
it { should be_empty }
|
33
|
-
end
|
34
|
-
|
35
|
-
context 'when the dependency is specified via #add_runtime_dependency' do
|
36
|
-
let(:dependency) { gemspec.find_dependency('astrolabe') }
|
37
|
-
it { should be_empty }
|
38
|
-
end
|
39
|
-
|
40
|
-
context 'when the dependency is specified via #add_runtime_dependency' do
|
41
|
-
let(:dependency) { gemspec.find_dependency('rspec') }
|
42
|
-
it { should eq([:development]) }
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe '#version_specifiers' do
|
47
|
-
subject(:version_specifier) { dependency.version_specifiers }
|
48
|
-
|
49
|
-
context 'when the dependency has no version specifier' do
|
50
|
-
let(:dependency) { gemspec.find_dependency('parser') }
|
51
|
-
it { should be_empty }
|
52
|
-
end
|
53
|
-
|
54
|
-
context 'when the dependency has a version specifier' do
|
55
|
-
let(:dependency) { gemspec.find_dependency('rspec') }
|
56
|
-
|
57
|
-
it 'returns the specifier' do
|
58
|
-
expect(version_specifier).to eq(['~> 3.1'])
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
context 'when the dependency has multiple version specifiers' do
|
63
|
-
let(:dependency) { gemspec.find_dependency('bundler') }
|
64
|
-
|
65
|
-
it 'returns the specifiers' do
|
66
|
-
expect(version_specifier).to eq(['>= 1.3.1', '< 2.0'])
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
context 'when the dependency has multiple version specifiers in an array' do
|
71
|
-
let(:dependency) { gemspec.find_dependency('astrolabe') }
|
72
|
-
|
73
|
-
it 'returns the specifiers' do
|
74
|
-
expect(version_specifier).to eq(['>= 1.3', '< 2.0'])
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
describe '#version_specifiers=' do
|
80
|
-
let(:rewritten_source) { File.read(gemspec.path) }
|
81
|
-
|
82
|
-
context 'when the dependency has no version specifier' do
|
83
|
-
let(:dependency) { gemspec.find_dependency('parser') }
|
84
|
-
|
85
|
-
let(:expected_source) { <<-END.strip_indent }
|
86
|
-
Gem::Specification.new do |spec|
|
87
|
-
spec.name = 'safedep'
|
88
|
-
spec.add_dependency 'parser', '~> 2.2'
|
89
|
-
spec.add_runtime_dependency 'bundler', '>= 1.3.1', '< 2.0'
|
90
|
-
spec.add_runtime_dependency 'astrolabe', ['>= 1.3', '< 2.0']
|
91
|
-
spec.add_development_dependency 'rspec', '~> 3.1'
|
92
|
-
end
|
93
|
-
END
|
94
|
-
|
95
|
-
it 'adds the passed specifier' do
|
96
|
-
dependency.version_specifiers = '~> 2.2'
|
97
|
-
gemspec.rewrite!
|
98
|
-
expect(rewritten_source).to eq(expected_source)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
context 'when the dependency has a version specifier' do
|
103
|
-
let(:dependency) { gemspec.find_dependency('rspec') }
|
104
|
-
|
105
|
-
let(:expected_source) { <<-END.strip_indent }
|
106
|
-
Gem::Specification.new do |spec|
|
107
|
-
spec.name = 'safedep'
|
108
|
-
spec.add_dependency 'parser'
|
109
|
-
spec.add_runtime_dependency 'bundler', '>= 1.3.1', '< 2.0'
|
110
|
-
spec.add_runtime_dependency 'astrolabe', ['>= 1.3', '< 2.0']
|
111
|
-
spec.add_development_dependency 'rspec', '> 4.0'
|
112
|
-
end
|
113
|
-
END
|
114
|
-
|
115
|
-
it 'replaces the existing specifier with the passed specifier' do
|
116
|
-
dependency.version_specifiers = '> 4.0'
|
117
|
-
gemspec.rewrite!
|
118
|
-
expect(rewritten_source).to eq(expected_source)
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
context 'when the dependency has multiple version specifiers' do
|
123
|
-
let(:dependency) { gemspec.find_dependency('bundler') }
|
124
|
-
|
125
|
-
let(:expected_source) { <<-END.strip_indent }
|
126
|
-
Gem::Specification.new do |spec|
|
127
|
-
spec.name = 'safedep'
|
128
|
-
spec.add_dependency 'parser'
|
129
|
-
spec.add_runtime_dependency 'bundler', '~> 2.0'
|
130
|
-
spec.add_runtime_dependency 'astrolabe', ['>= 1.3', '< 2.0']
|
131
|
-
spec.add_development_dependency 'rspec', '~> 3.1'
|
132
|
-
end
|
133
|
-
END
|
134
|
-
|
135
|
-
it 'replaces the existing specifiers with the passed specifier' do
|
136
|
-
dependency.version_specifiers = '~> 2.0'
|
137
|
-
gemspec.rewrite!
|
138
|
-
expect(rewritten_source).to eq(expected_source)
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
context 'when the dependency has multiple version specifiers in an array' do
|
143
|
-
let(:dependency) { gemspec.find_dependency('astrolabe') }
|
144
|
-
|
145
|
-
let(:expected_source) { <<-END.strip_indent }
|
146
|
-
Gem::Specification.new do |spec|
|
147
|
-
spec.name = 'safedep'
|
148
|
-
spec.add_dependency 'parser'
|
149
|
-
spec.add_runtime_dependency 'bundler', '>= 1.3.1', '< 2.0'
|
150
|
-
spec.add_runtime_dependency 'astrolabe', '~> 2.0'
|
151
|
-
spec.add_development_dependency 'rspec', '~> 3.1'
|
152
|
-
end
|
153
|
-
END
|
154
|
-
|
155
|
-
it 'replaces the existing specifiers with the passed specifier' do
|
156
|
-
dependency.version_specifiers = '~> 2.0'
|
157
|
-
gemspec.rewrite!
|
158
|
-
expect(rewritten_source).to eq(expected_source)
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
context 'when multiple specifiers are passed' do
|
163
|
-
let(:dependency) { gemspec.find_dependency('rspec') }
|
164
|
-
|
165
|
-
let(:expected_source) { <<-END.strip_indent }
|
166
|
-
Gem::Specification.new do |spec|
|
167
|
-
spec.name = 'safedep'
|
168
|
-
spec.add_dependency 'parser'
|
169
|
-
spec.add_runtime_dependency 'bundler', '>= 1.3.1', '< 2.0'
|
170
|
-
spec.add_runtime_dependency 'astrolabe', ['>= 1.3', '< 2.0']
|
171
|
-
spec.add_development_dependency 'rspec', '>= 3.1', '< 4.0'
|
172
|
-
end
|
173
|
-
END
|
174
|
-
|
175
|
-
it 'replaces the existing specifier with the passed specifier' do
|
176
|
-
dependency.version_specifiers = ['>= 3.1', '< 4.0']
|
177
|
-
gemspec.rewrite!
|
178
|
-
expect(rewritten_source).to eq(expected_source)
|
179
|
-
end
|
180
|
-
end
|
181
|
-
end
|
182
|
-
end
|
183
|
-
end
|
184
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'safedep/gemspec'
|
2
|
-
|
3
|
-
module Safedep
|
4
|
-
describe Gemspec, :gemspec do
|
5
|
-
include FileHelper
|
6
|
-
include_context 'isolated environment'
|
7
|
-
|
8
|
-
describe '#find_dependency' do
|
9
|
-
it 'returns the dependency matching the passed name' do
|
10
|
-
dependency = gemspec.find_dependency('parser')
|
11
|
-
expect(dependency.name).to eq('parser')
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe '#dependencies' do
|
16
|
-
it 'returns an array of the dependencies' do
|
17
|
-
expect(gemspec.dependencies.size).to eq(2)
|
18
|
-
expect(gemspec.dependencies).to all be_a(Gemspec::Dependency)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'safedep/literal'
|
2
|
-
require 'astrolabe/builder'
|
3
|
-
require 'parser/current'
|
4
|
-
|
5
|
-
module Safedep
|
6
|
-
describe Literal do
|
7
|
-
let(:node) do
|
8
|
-
builder = Astrolabe::Builder.new
|
9
|
-
parser = Parser::CurrentRuby.new(builder)
|
10
|
-
parser.parse(source_buffer)
|
11
|
-
end
|
12
|
-
|
13
|
-
let(:source_buffer) do
|
14
|
-
Parser::Source::Buffer.new('(string)').tap do |buffer|
|
15
|
-
buffer.source = source
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe '.value' do
|
20
|
-
subject { Literal.value(node) }
|
21
|
-
|
22
|
-
[
|
23
|
-
true,
|
24
|
-
false,
|
25
|
-
nil,
|
26
|
-
123,
|
27
|
-
3.14,
|
28
|
-
'foo',
|
29
|
-
:foo,
|
30
|
-
/foo/im,
|
31
|
-
['foo', 123],
|
32
|
-
{ 'foo' => 123, bar: false },
|
33
|
-
1..3,
|
34
|
-
1...3,
|
35
|
-
{ 'foo' => [:bar, { baz: 3.14 }] }
|
36
|
-
].each do |value|
|
37
|
-
context "with #{value.inspect} node" do
|
38
|
-
let(:source) { value.inspect }
|
39
|
-
it { should eq(value) }
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
context 'when nil is passed' do
|
44
|
-
let(:node) { nil }
|
45
|
-
it { should be_nil }
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|