grub 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2e00e745fa6f31b1d45dd4cec754330d5e8a00eb
4
- data.tar.gz: 284f19215ccee5756bc2fec8dee10dd5dad01ac5
3
+ metadata.gz: 2b6fc103ca951a638cd8cdd8b2b2c72c72b11fc0
4
+ data.tar.gz: fc330005a4d6a3377745cc12797adc412e5c9a18
5
5
  SHA512:
6
- metadata.gz: 3d043f4f9d76d84fec7d7a4063fe6fe81095721d0ae4b48aac92ea06ae01df7fb98eeb7757d041384f97a4af9792ce855fbfbd885efe26f93a1db50e2977f55e
7
- data.tar.gz: be5d9fa170ef7e7899554fc8ac4f13dc8f4960f3c24091b3980b08094f7de5df47f84c466f7da1395a7297f08bbd4ecb3243a65dd560a655a5a93fdbfb5a5e47
6
+ metadata.gz: 74e8ff61ac7addb78f4ee5a7a7bd9eacbc6363c68a52acd1cb22e4fdf88b298e7c344e5d0e83522a288c704c1122cc4895c685fbab625cf59c5e85bb3719647a
7
+ data.tar.gz: 8e71525d5e2655aafda9264bcbdd77dc23f3333f39de35dd274f501d23dc94bbbe40873405030dd88d8a76f88331e24e77c21513f8703dc919f23f06e4482c53
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in grub.gemspec
4
4
  gemspec
5
+
6
+ gem "pry"
data/Rakefile CHANGED
@@ -1,2 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rake/testtask"
2
3
 
4
+ Rake::TestTask.new do |t|
5
+ t.libs << "test"
6
+ t.test_files = FileList['test/**/*test.rb']
7
+ t.verbose = true
8
+ end
@@ -21,6 +21,8 @@ Gem::Specification.new do |spec|
21
21
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
22
22
  spec.require_paths = ["lib"]
23
23
 
24
- spec.add_runtime_dependency "bundler", "~> 1.7"
24
+ spec.add_runtime_dependency "bundler", "~> 1.7.4"
25
25
  spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "minitest", "~> 5.0"
27
+ spec.add_development_dependency "mocha", "~> 1.1"
26
28
  end
@@ -16,7 +16,7 @@ module Grub
16
16
  self.source = File.readlines(gemfile_path)
17
17
  source.each_with_index do |line, i|
18
18
  if match = GEM_LINE_REGEX.match(line)
19
- prev_line = source[i - 1]
19
+ prev_line = source[i - 1] if i > 0
20
20
  prev_line_comment = prev_line if is_line_a_comment?(prev_line)
21
21
  self.gem_lines << GemLine.new(
22
22
  name: match[:name],
@@ -31,7 +31,7 @@ module Grub
31
31
 
32
32
  def write_comments
33
33
  gem_lines.reverse.each do |gem_line|
34
- source.insert(gem_line.location , gem_line.comment) if gem_line.should_insert?
34
+ source.insert(gem_line.location, gem_line.comment) if gem_line.should_insert?
35
35
  end
36
36
  File.write(gemfile_path, source.join)
37
37
  end
@@ -39,7 +39,7 @@ module Grub
39
39
  private
40
40
 
41
41
  def is_line_a_comment?(line)
42
- line.strip.start_with?("#")
42
+ line && line.strip.start_with?("#")
43
43
  end
44
44
 
45
45
  end
@@ -12,6 +12,7 @@ module Grub
12
12
  def find_matching_specs_for(gem_lines)
13
13
  gem_lines.each do |line|
14
14
  matching_specs = Gem::Dependency.new(line.name).matching_specs
15
+ # need to find latest
15
16
  line.spec = matching_specs.first if matching_specs.any?
16
17
  end
17
18
  end
@@ -1,4 +1,4 @@
1
1
  module Grub
2
- VERSION = "0.0.2".freeze
2
+ VERSION = "0.0.3".freeze
3
3
  DESCRIPTION = "Add comments to your Gemfile with each dependency's description.".freeze
4
4
  end
@@ -0,0 +1,31 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'rails', '4.2.1'
4
+ gem 'sqlite3'
5
+ gem 'sass-rails', '~> 5.0'
6
+ gem 'uglifier', '>= 1.3.0'
7
+ gem 'coffee-rails', '~> 4.1.0'
8
+ # See https://github.com/rails/execjs#readme for more supported runtimes
9
+ # gem 'therubyracer', platforms: :ruby
10
+
11
+ gem 'jquery-rails'
12
+ gem 'turbolinks'
13
+ gem 'jbuilder', '~> 2.0'
14
+ # bundle exec rake doc:rails generates the API under doc/api.
15
+ gem 'sdoc', '~> 0.4.0', group: :doc
16
+
17
+ # Use ActiveModel has_secure_password
18
+ # gem 'bcrypt', '~> 3.1.7'
19
+
20
+ # Use Unicorn as the app server
21
+ # gem 'unicorn'
22
+
23
+ # Use Capistrano for deployment
24
+ # gem 'capistrano-rails', group: :development
25
+
26
+ group :development, :test do
27
+ gem 'byebug'
28
+ gem 'web-console', '~> 2.0'
29
+ # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
30
+ gem 'spring'
31
+ end
@@ -0,0 +1,43 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Full-stack web application framework. (http://www.rubyonrails.org)
4
+ gem 'rails', '4.2.1'
5
+ # This module allows Ruby programs to interface with the SQLite3 database engine (http://www.sqlite.org) (https://github.com/sparklemotion/sqlite3-ruby)
6
+ gem 'sqlite3'
7
+ # Sass adapter for the Rails asset pipeline. (https://github.com/rails/sass-rails)
8
+ gem 'sass-rails', '~> 5.0'
9
+ # Ruby wrapper for UglifyJS JavaScript compressor (http://github.com/lautis/uglifier)
10
+ gem 'uglifier', '>= 1.3.0'
11
+ # CoffeeScript adapter for the Rails asset pipeline. (https://github.com/rails/coffee-rails)
12
+ gem 'coffee-rails', '~> 4.1.0'
13
+ # See https://github.com/rails/execjs#readme for more supported runtimes
14
+ # gem 'therubyracer', platforms: :ruby
15
+
16
+ # Use jQuery with Rails 4+ (http://rubygems.org/gems/jquery-rails)
17
+ gem 'jquery-rails'
18
+ # Turbolinks makes navigating your web application faster (https://github.com/turbolinks/turbolinks-rails)
19
+ gem 'turbolinks'
20
+ # Create JSON structures via a Builder-style DSL (https://github.com/rails/jbuilder)
21
+ gem 'jbuilder', '~> 2.0'
22
+ # bundle exec rake doc:rails generates the API under doc/api.
23
+ # rdoc html with javascript search index. (http://github.com/voloko/sdoc)
24
+ gem 'sdoc', '~> 0.4.0', group: :doc
25
+
26
+ # Use ActiveModel has_secure_password
27
+ # gem 'bcrypt', '~> 3.1.7'
28
+
29
+ # Use Unicorn as the app server
30
+ # gem 'unicorn'
31
+
32
+ # Use Capistrano for deployment
33
+ # gem 'capistrano-rails', group: :development
34
+
35
+ group :development, :test do
36
+ # Ruby 2.0 fast debugger - base + CLI (http://github.com/deivid-rodriguez/byebug)
37
+ gem 'byebug'
38
+ # A debugging tool for your Ruby on Rails applications. (https://github.com/rails/web-console)
39
+ gem 'web-console', '~> 2.0'
40
+ # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
41
+ # Rails application preloader (https://github.com/rails/spring)
42
+ gem 'spring'
43
+ end
@@ -0,0 +1,23 @@
1
+ require "test_helper"
2
+ require "grub/cli"
3
+
4
+ # Acts as integration test since it will actually fetch data from API
5
+ class Grub::CLITest < Minitest::Test
6
+
7
+ def test_run_for_gemfile
8
+ with_gemfile(File.read(gemfile_path)) do |path|
9
+ Bundler.expects(:default_gemfile).returns(path)
10
+ out, _ = capture_io do
11
+ Grub::CLI.new.run_for_gemfile
12
+ end
13
+ assert_equal File.read(grubbed_gemfile_path), File.read(path)
14
+ end
15
+ end
16
+
17
+ def test_run_for_gem
18
+ out, _ = capture_io do
19
+ Grub::CLI.new.run_for_gem("grub")
20
+ end
21
+ assert_equal "Add comments to your Gemfile with each dependency's description. (https://github.com/ivantsepp/grub)\n", out
22
+ end
23
+ end
@@ -0,0 +1,76 @@
1
+ require "test_helper"
2
+
3
+ class Grub::GemLineTest < Minitest::Test
4
+
5
+ def test_info
6
+ gem_line = create_gem_line
7
+ spec = stub(summary: "Hello world", homepage: "http://example.com")
8
+ gem_line.spec = spec
9
+ assert_equal "Hello world (http://example.com)\n", gem_line.info
10
+ end
11
+
12
+ def test_info_with_website_only
13
+ gem_line = create_gem_line(options: { website_only: true })
14
+ spec = stub(summary: "Hello world", homepage: "http://example.com")
15
+ gem_line.spec = spec
16
+ assert_equal "http://example.com\n", gem_line.info
17
+ end
18
+
19
+ def test_info_with_description_only
20
+ gem_line = create_gem_line(options: { description_only: true })
21
+ spec = stub(summary: "Hello world", homepage: "http://example.com")
22
+ gem_line.spec = spec
23
+ assert_equal "Hello world\n", gem_line.info
24
+ end
25
+
26
+ def test_should_insert_with_no_info
27
+ gem_line = create_gem_line
28
+ gem_line.expects(:info).returns("")
29
+ refute gem_line.should_insert?
30
+ end
31
+
32
+ def test_should_insert_with_already_added_comment
33
+ gem_line = create_gem_line(prev_line_comment: "# Hello world (http://example.com)\n")
34
+ spec = stub(summary: "Hello world", homepage: "http://example.com")
35
+ gem_line.spec = spec
36
+ refute gem_line.should_insert?
37
+ end
38
+
39
+ def test_should_insert_with_new_comments_only
40
+ gem_line = create_gem_line(
41
+ prev_line_comment: "# This is an existing comment\n",
42
+ options: { new_comments_only: true }
43
+ )
44
+ spec = stub(summary: "Hello world", homepage: "http://example.com")
45
+ gem_line.spec = spec
46
+ refute gem_line.should_insert?
47
+ end
48
+
49
+ def test_comment
50
+ gem_line = create_gem_line
51
+ spec = stub(summary: "Hello world", homepage: "http://example.com")
52
+ gem_line.spec = spec
53
+ assert_equal "# Hello world (http://example.com)\n", gem_line.comment
54
+ end
55
+
56
+ def test_comment_with_indentation_in_original_line
57
+ gem_line = Grub::GemLine.new(
58
+ name: "grub",
59
+ original_line: " \tgem 'grub'"
60
+ )
61
+ spec = stub(summary: "Hello world", homepage: "http://example.com")
62
+ gem_line.spec = spec
63
+ assert_equal " \t# Hello world (http://example.com)\n", gem_line.comment
64
+ end
65
+
66
+ private
67
+
68
+ def create_gem_line(options = {})
69
+ Grub::GemLine.new(
70
+ name: "grub",
71
+ original_line: "gem 'grub'",
72
+ **options
73
+ )
74
+ end
75
+
76
+ end
@@ -0,0 +1,71 @@
1
+ require "test_helper"
2
+
3
+ class Grub::GemfileTest < Minitest::Test
4
+
5
+ def test_parses_source
6
+ gemfile = gemfile_for(unindent(<<-GEMFILE))
7
+ hello
8
+ world!
9
+ GEMFILE
10
+ assert 2, gemfile.source.length
11
+ assert_equal "hello\n", gemfile.source.first
12
+ assert_equal "world!\n", gemfile.source.last
13
+ end
14
+
15
+ def test_parses_gem_lines
16
+ Grub::GemLine.expects(:new).with(
17
+ name: "rails",
18
+ original_line: "gem \"rails\"\n",
19
+ location: 0,
20
+ prev_line_comment: nil,
21
+ options: {}
22
+ ).once
23
+ Grub::GemLine.expects(:new).with(
24
+ name: "grub",
25
+ original_line: "gem \"grub\"\n",
26
+ location: 2,
27
+ prev_line_comment: "# this gem has a comment\n",
28
+ options: {}
29
+ ).once
30
+ gemfile = gemfile_for(unindent(<<-GEMFILE))
31
+ gem "rails"
32
+ # this gem has a comment
33
+ gem "grub"
34
+ # gem "commented_out"
35
+ GEMFILE
36
+ assert_equal 2, gemfile.gem_lines.length
37
+ end
38
+
39
+ def test_write_comments
40
+ with_gemfile("gem 'rails'") do |path|
41
+ gemfile = Grub::Gemfile.new(path)
42
+ gemfile.gem_lines = [mock(location: 0, comment: "Rails description!\n", should_insert?: true)]
43
+ gemfile.source = ["gem 'rails'"]
44
+ gemfile.write_comments
45
+ assert_equal "Rails description!\ngem 'rails'", File.read(path)
46
+ end
47
+ end
48
+
49
+ def test_that_options_are_passed_through
50
+ Grub::GemLine.expects(:new).with(
51
+ name: "rails",
52
+ original_line: "gem 'rails'",
53
+ location: 0,
54
+ prev_line_comment: nil,
55
+ options: { description_only: true }
56
+ ).once
57
+ gemfile = gemfile_for("gem 'rails'", description_only: true)
58
+ end
59
+
60
+ private
61
+
62
+ def gemfile_for(content, options = {})
63
+ gemfile = nil
64
+ with_gemfile(content) do |path|
65
+ gemfile = Grub::Gemfile.new(path, options)
66
+ gemfile.parse
67
+ end
68
+ gemfile
69
+ end
70
+
71
+ end
@@ -0,0 +1,57 @@
1
+ require "test_helper"
2
+
3
+ class Grub::SpecFinderTest < Minitest::Test
4
+ def test_find_specs_for
5
+ gem_line_1 = mock(spec: nil)
6
+ gem_line_2 = mock(spec: "spec")
7
+ Grub::SpecFinder.expects(:find_matching_specs_for).with([gem_line_1, gem_line_2])
8
+ Grub::SpecFinder.expects(:fetch_specs_for).with([gem_line_1])
9
+ Grub::SpecFinder.find_specs_for([gem_line_1, gem_line_2])
10
+ end
11
+
12
+ def test_find_matching_specs_for
13
+ spec_1 = mock
14
+ gem_line_1 = mock(name: "1")
15
+ gem_line_1.expects(:spec=).with(spec_1)
16
+ spec_2 = mock
17
+ gem_line_2 = mock(name: "2")
18
+ gem_line_2.expects(:spec=).with(spec_2)
19
+ gem_lines = [gem_line_1, gem_line_2]
20
+ Gem::Dependency.expects(:new).with("1").returns(mock(matching_specs: [spec_1]))
21
+ Gem::Dependency.expects(:new).with("2").returns(mock(matching_specs: [spec_2]))
22
+ Grub::SpecFinder.find_matching_specs_for(gem_lines)
23
+ end
24
+
25
+ def test_fetch_specs_for
26
+ original_stdout = $stdout
27
+ $stdout = StringIO.new
28
+
29
+ spec_1 = mock
30
+ gem_line_1 = mock
31
+ gem_line_1.stubs(name: "1")
32
+ gem_line_1.expects(:spec=).with(spec_1)
33
+ spec_2 = mock
34
+ gem_line_2 = mock
35
+ gem_line_2.stubs(name: "2")
36
+ gem_line_2.expects(:spec=).with(spec_2)
37
+
38
+ Bundler::Fetcher.any_instance.expects(:fetch_dependency_remote_specs).with(["1", "2"]).returns([[
39
+ ["1", Gem::Version.new("1")],
40
+ ["2", Gem::Version.new("1")],
41
+ ], "dependencies here"])
42
+ Grub::SpecFinder.expects(:find_latest_version).returns(Gem::Version.new("1")).twice
43
+ Bundler::Fetcher.any_instance.expects(:fetch_spec).with(["1", Gem::Version.new("1")]).returns(spec_1)
44
+ Bundler::Fetcher.any_instance.expects(:fetch_spec).with(["2", Gem::Version.new("1")]).returns(spec_2)
45
+ Grub::SpecFinder.fetch_specs_for([gem_line_1, gem_line_2])
46
+
47
+ $stdout = original_stdout
48
+ end
49
+
50
+ def test_find_latest_version
51
+ versions = [
52
+ ["rails", Gem::Version.new("2.3.5")],
53
+ ["rails", Gem::Version.new("4")]
54
+ ]
55
+ assert_equal Gem::Version.new("4"), Grub::SpecFinder.find_latest_version(versions)
56
+ end
57
+ end
@@ -0,0 +1,31 @@
1
+ require "minitest/autorun"
2
+ require "mocha/mini_test"
3
+ require "grub"
4
+
5
+ module TestHelpers
6
+
7
+ def gemfile_path
8
+ File.join(File.dirname(__FILE__), "fixtures", "Gemfile")
9
+ end
10
+
11
+ def grubbed_gemfile_path
12
+ File.join(File.dirname(__FILE__), "fixtures", "Gemfile_grubbed")
13
+ end
14
+
15
+ def with_gemfile(content)
16
+ file = Tempfile.new('gemfile')
17
+ file.write(content)
18
+ file.close
19
+ yield(file.path)
20
+ file.unlink
21
+ end
22
+
23
+ def unindent(str)
24
+ str.gsub(/^#{str.scan(/^[ ]+(?=\S)/).min}/, "")
25
+ end
26
+
27
+ end
28
+
29
+ class Minitest::Test
30
+ include TestHelpers
31
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Tse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-08 00:00:00.000000000 Z
11
+ date: 2016-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.7'
19
+ version: 1.7.4
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.7'
26
+ version: 1.7.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: mocha
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.1'
41
69
  description: 'Clarify your dependencies by adding a detailed comment to each line
42
70
  in Gemfile specifying the gem''s summary and its website if any. '
43
71
  email:
@@ -61,6 +89,13 @@ files:
61
89
  - lib/grub/options.rb
62
90
  - lib/grub/spec_finder.rb
63
91
  - lib/grub/version.rb
92
+ - test/fixtures/Gemfile
93
+ - test/fixtures/Gemfile_grubbed
94
+ - test/grub/cli_test.rb
95
+ - test/grub/gem_line_test.rb
96
+ - test/grub/gemfile_test.rb
97
+ - test/grub/spec_finder_test.rb
98
+ - test/test_helper.rb
64
99
  homepage: https://github.com/ivantsepp/grub
65
100
  licenses:
66
101
  - MIT
@@ -85,4 +120,11 @@ rubygems_version: 2.2.2
85
120
  signing_key:
86
121
  specification_version: 4
87
122
  summary: Add comments to your Gemfile with each dependency's description.
88
- test_files: []
123
+ test_files:
124
+ - test/fixtures/Gemfile
125
+ - test/fixtures/Gemfile_grubbed
126
+ - test/grub/cli_test.rb
127
+ - test/grub/gem_line_test.rb
128
+ - test/grub/gemfile_test.rb
129
+ - test/grub/spec_finder_test.rb
130
+ - test/test_helper.rb