librariesio-gem-parser 1.0.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.
@@ -0,0 +1,239 @@
1
+ require "spec_helper"
2
+
3
+ describe Gemnasium::Parser::Podfile do
4
+ def content(string)
5
+ @content ||= begin
6
+ indent = string.scan(/^[ \t]*(?=\S)/)
7
+ n = indent ? indent.size : 0
8
+ string.gsub(/^[ \t]{#{n}}/, "")
9
+ end
10
+ end
11
+
12
+ def podfile
13
+ @podfile ||= Gemnasium::Parser::Podfile.new(@content)
14
+ end
15
+
16
+ def dependencies
17
+ @dependencies ||= podfile.dependencies
18
+ end
19
+
20
+ def dependency
21
+ dependencies.size.should == 1
22
+ dependencies.first
23
+ end
24
+
25
+ def reset
26
+ @content = @podfile = @dependencies = nil
27
+ end
28
+
29
+ it "parses double quotes" do
30
+ content(%(pod "rake", ">= 0.8.7"))
31
+ dependency.name.should == "rake"
32
+ dependency.requirement.as_list.should == [">= 0.8.7"]
33
+ end
34
+
35
+ it "parses single quotes" do
36
+ content(%(pod 'rake', '>= 0.8.7'))
37
+ dependency.name.should == "rake"
38
+ dependency.requirement.as_list.should == [">= 0.8.7"]
39
+ end
40
+
41
+ it "ignores mixed quotes" do
42
+ content(%(pod "rake', ">= 0.8.7"))
43
+ dependencies.size.should == 0
44
+ end
45
+
46
+ it "parses pods with a period in the name" do
47
+ content(%(pod "pygment.rb", ">= 0.8.7"))
48
+ dependency.name.should == "pygment.rb"
49
+ dependency.requirement.as_list.should == [">= 0.8.7"]
50
+ end
51
+
52
+ it "parses non-requirement pods" do
53
+ content(%(pod "rake"))
54
+ dependency.name.should == "rake"
55
+ dependency.requirement.as_list.should == [">= 0"]
56
+ end
57
+
58
+ it "parses multi-requirement pods" do
59
+ content(%(pod "rake", ">= 0.8.7", "<= 0.9.2"))
60
+ dependency.name.should == "rake"
61
+ dependency.requirement.as_list.should == ["<= 0.9.2", ">= 0.8.7"]
62
+ end
63
+
64
+ it "parses pods with options" do
65
+ content(%(pod "rake", ">= 0.8.7", :require => false))
66
+ dependency.name.should == "rake"
67
+ dependency.requirement.as_list.should == [">= 0.8.7"]
68
+ end
69
+
70
+ it "parses pods of a type" do
71
+ content(%(pod "rake"))
72
+ dependency.type.should == :runtime
73
+ reset
74
+ content(%(pod "rake", :type => :development))
75
+ dependency.type.should == :development
76
+ end
77
+
78
+ it "parses pods of a group" do
79
+ content(%(pod "rake"))
80
+ dependency.groups.should == [:default]
81
+ reset
82
+ content(%(pod "rake", :group => :development))
83
+ dependency.groups.should == [:development]
84
+ end
85
+
86
+ it "parses pods of multiple groups" do
87
+ content(%(pod "rake", :group => [:development, :test]))
88
+ dependency.groups.should == [:development, :test]
89
+ end
90
+
91
+ it "recognizes :groups" do
92
+ content(%(pod "rake", :groups => [:development, :test]))
93
+ dependency.groups.should == [:development, :test]
94
+ end
95
+
96
+ it "parses pods in a group" do
97
+ content(<<-EOF)
98
+ pod "rake"
99
+ group :production do
100
+ pod "pg"
101
+ end
102
+ group :development do
103
+ pod "sqlite3"
104
+ end
105
+ EOF
106
+ dependencies[0].groups.should == [:default]
107
+ dependencies[1].groups.should == [:production]
108
+ dependencies[2].groups.should == [:development]
109
+ end
110
+
111
+ it "parses pods in a group with parentheses" do
112
+ content(<<-EOF)
113
+ group(:production) do
114
+ pod "pg"
115
+ end
116
+ EOF
117
+ dependency.groups.should == [:production]
118
+ end
119
+
120
+ it "parses pods in multiple groups" do
121
+ content(<<-EOF)
122
+ group :development, :test do
123
+ pod "sqlite3"
124
+ end
125
+ EOF
126
+ dependency.groups.should == [:development, :test]
127
+ end
128
+
129
+ it "parses multiple pods in a group" do
130
+ content(<<-EOF)
131
+ group :development do
132
+ pod "rake"
133
+ pod "sqlite3"
134
+ end
135
+ EOF
136
+ dependencies[0].groups.should == [:development]
137
+ dependencies[1].groups.should == [:development]
138
+ end
139
+
140
+ it "parses multiple pods in multiple groups" do
141
+ content(<<-EOF)
142
+ group :development, :test do
143
+ pod "rake"
144
+ pod "sqlite3"
145
+ end
146
+ EOF
147
+ dependencies[0].groups.should == [:development, :test]
148
+ dependencies[1].groups.should == [:development, :test]
149
+ end
150
+
151
+ it "ignores h4x" do
152
+ path = File.expand_path("../h4x.txt", __FILE__)
153
+ content(%(pod "h4x", :require => "\#{`touch #{path}`}"))
154
+ dependencies.size.should == 0
155
+ begin
156
+ File.should_not exist(path)
157
+ ensure
158
+ FileUtils.rm_f(path)
159
+ end
160
+ end
161
+
162
+ it "ignores pods with a git option" do
163
+ content(%(pod "rails", :git => "https://github.com/rails/rails.git"))
164
+ dependencies.size.should == 1
165
+ end
166
+
167
+ it "ignores pods with a github option" do
168
+ content(%(pod "rails", :github => "rails/rails"))
169
+ dependencies.size.should == 1
170
+ end
171
+
172
+ it "ignores pods with a path option" do
173
+ content(%(pod "rails", :path => "vendor/rails"))
174
+ dependencies.size.should == 1
175
+ end
176
+
177
+ it "ignores pods in a git block" do
178
+ content(<<-EOF)
179
+ git "https://github.com/rails/rails.git" do
180
+ pod "rails"
181
+ end
182
+ EOF
183
+ dependencies.size.should == 1
184
+ end
185
+
186
+ it "ignores pods in a git block with parentheses" do
187
+ content(<<-EOF)
188
+ git("https://github.com/rails/rails.git") do
189
+ pod "rails"
190
+ end
191
+ EOF
192
+ dependencies.size.should == 1
193
+ end
194
+
195
+ it "ignores pods in a path block" do
196
+ content(<<-EOF)
197
+ path "vendor/rails" do
198
+ pod "rails"
199
+ end
200
+ EOF
201
+ dependencies.size.should == 1
202
+ end
203
+
204
+ it "ignores pods in a path block with parentheses" do
205
+ content(<<-EOF)
206
+ path("vendor/rails") do
207
+ pod "rails"
208
+ end
209
+ EOF
210
+ dependencies.size.should == 1
211
+ end
212
+
213
+ it "records dependency line numbers" do
214
+ content(<<-EOF)
215
+ pod "rake"
216
+
217
+ pod "rails"
218
+ EOF
219
+ dependencies[0].instance_variable_get(:@line).should == 1
220
+ dependencies[1].instance_variable_get(:@line).should == 3
221
+ end
222
+
223
+ it "parses parentheses" do
224
+ content(%(pod("rake", ">= 0.8.7")))
225
+ dependency.name.should == "rake"
226
+ dependency.requirement.as_list.should == [">= 0.8.7"]
227
+ end
228
+
229
+ it "parses pods followed by inline comments" do
230
+ content(%(pod "rake", ">= 0.8.7" # Comment))
231
+ dependency.name.should == "rake"
232
+ dependency.requirement.as_list.should == [">= 0.8.7"]
233
+ end
234
+
235
+ it "parses oddly quoted pods" do
236
+ content(%(pod %q<rake>))
237
+ dependency.name.should == "rake"
238
+ end
239
+ end
@@ -0,0 +1,150 @@
1
+ require "spec_helper"
2
+
3
+ describe Gemnasium::Parser::Podspec do
4
+ def content(string)
5
+ @content ||= begin
6
+ indent = string.scan(/^[ \t]*(?=\S)/)
7
+ n = indent ? indent.size : 0
8
+ string.gsub(/^[ \t]{#{n}}/, "")
9
+ end
10
+ end
11
+
12
+ def podspec
13
+ @podspec ||= Gemnasium::Parser::Podspec.new(@content)
14
+ end
15
+
16
+ def dependencies
17
+ @dependencies ||= podspec.dependencies
18
+ end
19
+
20
+ def dependency
21
+ dependencies.size.should == 1
22
+ dependencies.first
23
+ end
24
+
25
+ def reset
26
+ @content = @podspec = @dependencies = nil
27
+ end
28
+
29
+ it "parses double quotes" do
30
+ content(<<-EOF)
31
+ Pod::Spec.new do |spec|
32
+ spec.dependency "rake", ">= 0.8.7"
33
+ end
34
+ EOF
35
+ dependency.name.should == "rake"
36
+ dependency.requirement.as_list.should == [">= 0.8.7"]
37
+ end
38
+
39
+ it "parses single quotes" do
40
+ content(<<-EOF)
41
+ Pod::Spec.new do |spec|
42
+ spec.dependency 'rake', '>= 0.8.7'
43
+ end
44
+ EOF
45
+ dependency.name.should == "rake"
46
+ dependency.requirement.as_list.should == [">= 0.8.7"]
47
+ end
48
+
49
+ it "ignores mixed quotes" do
50
+ content(<<-EOF)
51
+ Pod::Spec.new do |spec|
52
+ spec.dependency "rake', ">= 0.8.7"
53
+ end
54
+ EOF
55
+ dependencies.size.should == 0
56
+ end
57
+
58
+ it "parses pods with a period in the name" do
59
+ content(<<-EOF)
60
+ Pod::Spec.new do |spec|
61
+ spec.dependency "pygment.rb", ">= 0.8.7"
62
+ end
63
+ EOF
64
+ dependency.name.should == "pygment.rb"
65
+ dependency.requirement.as_list.should == [">= 0.8.7"]
66
+ end
67
+
68
+ it "parses non-requirement pods" do
69
+ content(<<-EOF)
70
+ Pod::Spec.new do |spec|
71
+ spec.dependency "rake"
72
+ end
73
+ EOF
74
+ dependency.name.should == "rake"
75
+ dependency.requirement.as_list.should == [">= 0"]
76
+ end
77
+
78
+ it "parses multi-requirement pods" do
79
+ content(<<-EOF)
80
+ Pod::Spec.new do |spec|
81
+ spec.dependency "rake", ">= 0.8.7", "<= 0.9.2"
82
+ end
83
+ EOF
84
+ dependency.name.should == "rake"
85
+ dependency.requirement.as_list.should == ["<= 0.9.2", ">= 0.8.7"]
86
+ end
87
+
88
+ it "parses single-element array requirement pods" do
89
+ content(<<-EOF)
90
+ Pod::Spec.new do |spec|
91
+ spec.dependency "rake", [">= 0.8.7"]
92
+ end
93
+ EOF
94
+ dependency.name.should == "rake"
95
+ dependency.requirement.as_list.should == [">= 0.8.7"]
96
+ end
97
+
98
+ it "parses multi-element array requirement pods" do
99
+ content(<<-EOF)
100
+ Pod::Spec.new do |spec|
101
+ spec.dependency "rake", [">= 0.8.7", "<= 0.9.2"]
102
+ end
103
+ EOF
104
+ dependency.name.should == "rake"
105
+ dependency.requirement.as_list.should == ["<= 0.9.2", ">= 0.8.7"]
106
+ end
107
+
108
+ it "parses runtime pods" do
109
+ content(<<-EOF)
110
+ Pod::Spec.new do |spec|
111
+ spec.dependency "rake"
112
+ end
113
+ EOF
114
+ dependencies[0].type.should == :runtime
115
+ end
116
+
117
+ it "records dependency line numbers" do
118
+ content(<<-EOF)
119
+ Pod::Spec.new do |spec|
120
+ spec.dependency "rake"
121
+
122
+ spec.dependency "rails"
123
+ end
124
+ EOF
125
+ dependencies[0].instance_variable_get(:@line).should == 2
126
+ dependencies[1].instance_variable_get(:@line).should == 4
127
+ end
128
+
129
+ it "parses parentheses" do
130
+ content(<<-EOF)
131
+ Pod::Spec.new do |s|
132
+ s.subspec 'Default' do |ss|
133
+ ss.dependency 'CocoaLumberjack/Core', '>= 1.0.0'
134
+ end
135
+ end
136
+ EOF
137
+ dependency.name.should == "CocoaLumberjack"
138
+ dependency.requirement.as_list.should == [">= 1.0.0"]
139
+ end
140
+
141
+ it "parses pods followed by inline comments" do
142
+ content(<<-EOF)
143
+ Pod::Spec.new do |spec|
144
+ spec.dependency "rake", ">= 0.8.7" # Comment
145
+ end
146
+ EOF
147
+ dependency.name.should == "rake"
148
+ dependency.requirement.as_list.should == [">= 0.8.7"]
149
+ end
150
+ end
@@ -0,0 +1,34 @@
1
+ require "spec_helper"
2
+
3
+ describe Gemnasium::Parser do
4
+ describe ".gemfile" do
5
+ it "requires a single string argument" do
6
+ expect{ Gemnasium::Parser.gemfile }.to raise_error(ArgumentError)
7
+ expect{ Gemnasium::Parser.gemfile("") }.to_not raise_error
8
+ end
9
+
10
+ it "returns a Gemfile" do
11
+ Gemnasium::Parser.gemfile("").should be_a(Gemnasium::Parser::Gemfile)
12
+ end
13
+
14
+ it "removes CR chars from content" do
15
+ Gemnasium::Parser.gemfile("\r").content.match("\r").should be_nil
16
+ end
17
+
18
+ end
19
+
20
+ describe ".gemspec" do
21
+ it "requires a single string argument" do
22
+ expect{ Gemnasium::Parser.gemspec }.to raise_error(ArgumentError)
23
+ expect{ Gemnasium::Parser.gemspec("") }.to_not raise_error
24
+ end
25
+
26
+ it "returns a Gemspec" do
27
+ Gemnasium::Parser.gemspec("").should be_a(Gemnasium::Parser::Gemspec)
28
+ end
29
+
30
+ it "removes CR chars from content" do
31
+ Gemnasium::Parser.gemspec("\r").content.match("\r").should be_nil
32
+ end
33
+ end
34
+ end
@@ -0,0 +1 @@
1
+ require "gemnasium/parser"
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: librariesio-gem-parser
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Nesbitt
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.8.7
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.8.7
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.4'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.4'
55
+ description: Fork of gemnasium-parser
56
+ email: andrewnez@gmail.com
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - ".gitignore"
62
+ - ".travis.yml"
63
+ - CHANGELOG.md
64
+ - Gemfile
65
+ - LICENSE
66
+ - README.md
67
+ - Rakefile
68
+ - lib/gemnasium/parser.rb
69
+ - lib/gemnasium/parser/configuration.rb
70
+ - lib/gemnasium/parser/gemfile.rb
71
+ - lib/gemnasium/parser/gemspec.rb
72
+ - lib/gemnasium/parser/patterns.rb
73
+ - lib/gemnasium/parser/podfile.rb
74
+ - lib/gemnasium/parser/podspec.rb
75
+ - librariesio-gem-parser.gemspec
76
+ - spec/gemnasium/parser/gemfile_spec.rb
77
+ - spec/gemnasium/parser/gemspec_spec.rb
78
+ - spec/gemnasium/parser/podfile_spec.rb
79
+ - spec/gemnasium/parser/podspec_spec.rb
80
+ - spec/gemnasium/parser_spec.rb
81
+ - spec/spec_helper.rb
82
+ homepage: https://github.com/librariesio/gemnasium-parser
83
+ licenses: []
84
+ metadata: {}
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.5.1
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: Fork of gemnasium-parser
105
+ test_files:
106
+ - spec/gemnasium/parser/gemfile_spec.rb
107
+ - spec/gemnasium/parser/gemspec_spec.rb
108
+ - spec/gemnasium/parser/podfile_spec.rb
109
+ - spec/gemnasium/parser/podspec_spec.rb
110
+ - spec/gemnasium/parser_spec.rb
111
+ - spec/spec_helper.rb