gem_bootstrap 0.2.7 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ #### 0.2.8
2
+
3
+ - Add some tests (better late than never)
4
+ - Add Guardfile for TDD/BDD
5
+
1
6
  #### 0.2.7
2
7
 
3
8
  - Use require instead require_relative
data/lib/gem_bootstrap.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # external libraries
1
2
  require 'grit'
2
3
  require 'open3'
3
4
  require 'thor'
@@ -5,7 +6,9 @@ require 'active_support'
5
6
  require 'active_support/core_ext/object/blank'
6
7
  require 'active_support/core_ext/hash/keys'
7
8
  require 'active_support/core_ext/hash/indifferent_access'
9
+ # internal files
8
10
  require 'gem_bootstrap/version'
11
+ require 'gem_bootstrap/errors'
9
12
  require 'gem_bootstrap/cli'
10
13
  require 'gem_bootstrap/git_utils'
11
14
  require 'gem_bootstrap/misc_utils'
@@ -0,0 +1,5 @@
1
+ module GemBootstrap
2
+ class Errors
3
+ CustomError = Class.new(StandardError)
4
+ end
5
+ end
@@ -21,6 +21,8 @@ module GemBootstrap
21
21
  git_add(base_dir, files)
22
22
  end
23
23
 
24
+ private
25
+
24
26
  # Run the `git init` on a given directory
25
27
  #
26
28
  # @param [String] base_dir the starting directory
@@ -46,8 +48,6 @@ module GemBootstrap
46
48
  end
47
49
  end
48
50
 
49
- private
50
-
51
51
  def expand_path(base_dir)
52
52
  raise "Invalid directory name `{base_dir}`" if base_dir.nil? || !File.directory?(File.new(base_dir))
53
53
  File.expand_path(base_dir)
@@ -1,13 +1,12 @@
1
1
  module GemBootstrap
2
2
  class MiscUtils
3
- CustomError = Class.new(StandardError)
4
-
5
3
  class << self
6
4
  # Receives a string and convert it to snake case.
7
5
  # SnakeCase returns snake_case.
8
6
  #
9
7
  # @param [String] str the input string
10
8
  def snake_case(str)
9
+ # for testing only
11
10
  return str.downcase if str =~ /^[A-Z_]+$/
12
11
  str.gsub(/\B[A-Z]/, '_\&').squeeze('_') =~ /_*(.*)/
13
12
  $+.downcase
@@ -27,14 +26,14 @@ module GemBootstrap
27
26
  # @param [Hash<Symbol, Object>] args keys and values of argument
28
27
  def files(args = {})
29
28
  opts = {
30
- base_dir: Dir.pwd,
29
+ base_dir: Dir.pwd,
31
30
  recursive: false,
32
- exts: [],
33
- non_exts: []
31
+ exts: [],
32
+ non_exts: []
34
33
  }.merge(args)
35
34
 
36
35
  base_dir = opts[:base_dir]
37
- fail CustomError, "The directory #{base_dir} is not valid or or not readable!" unless File.exist?(base_dir)
36
+ fail Errors::CustomError, "The directory #{base_dir} is not valid or or not readable!" unless File.exist?(base_dir)
38
37
 
39
38
  wildcard = opts[:recursive] ? '**' : ''
40
39
  exts = opts[:exts]
@@ -1,3 +1,3 @@
1
1
  module GemBootstrap
2
- VERSION = '0.2.7'
2
+ VERSION = '0.2.8'
3
3
  end
@@ -1,4 +1,3 @@
1
- # A sample Guardfile
2
1
  # More info at https://github.com/guard/guard#readme
3
2
  guard 'minitest' do
4
3
  watch(%r|^test/(.*)\/?test_(.*)\.rb|)
@@ -1,4 +1,3 @@
1
- # A sample Guardfile
2
1
  # More info at https://github.com/guard/guard#readme
3
2
  guard :rspec, cmd: 'rspec', all_on_start: true, all_after_pass: true do
4
3
  watch(%r{^spec/.+_spec\.rb$})
@@ -6,7 +6,6 @@ Rake::TestTask.new do |t|
6
6
  t.test_files = FileList["test/lib/#{project_name}/test_*.rb"]
7
7
  t.verbose = true
8
8
  end
9
-
10
9
  task default: [:test, :rubocop]
11
10
  task :pry do
12
11
  require 'pry'
@@ -16,7 +15,6 @@ task :pry do
16
15
  ARGV.clear
17
16
  Pry.start
18
17
  end
19
-
20
18
  require 'rubocop/rake_task'
21
19
  desc 'Run RuboCop on the lib directory'
22
20
  RuboCop::RakeTask.new(:rubocop) do |task|
@@ -2,7 +2,6 @@ require "bundler/gem_tasks"
2
2
  Bundler::GemHelper.install_tasks
3
3
  require "rspec/core/rake_task"
4
4
  RSpec::Core::RakeTask.new
5
-
6
5
  task :pry do
7
6
  require "pry"
8
7
  require "awesome_print"
@@ -11,7 +10,6 @@ task :pry do
11
10
  ARGV.clear
12
11
  Pry.start
13
12
  end
14
-
15
13
  require "rubocop/rake_task"
16
14
  desc "Run RuboCop on the lib directory"
17
15
  RuboCop::RakeTask.new(:rubocop) do |task|
@@ -19,5 +17,4 @@ RuboCop::RakeTask.new(:rubocop) do |task|
19
17
  task.formatters = ["files"]
20
18
  task.fail_on_error = false
21
19
  end
22
-
23
20
  task default: [:spec, :rubocop]
data/templates/bin/newgem CHANGED
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
  require_relative '../lib/<%= name %>'
3
- include <%= MiscUtils.camel_case(name) %>
4
3
  if ARGV.empty?
5
4
  <%= MiscUtils.camel_case(name) %>::CLI.start(%w[usage])
6
5
  else
@@ -4,7 +4,7 @@ require 'active_support/core_ext/hash/keys'
4
4
  require 'active_support/core_ext/hash/indifferent_access'
5
5
  require 'active_support/core_ext/kernel/reporting'
6
6
  require 'thor'
7
- require_relative '<%= name %>/version'
8
- require_relative '<%= name %>/<%= name %>'
9
- require_relative '<%= name %>/cli'
7
+ require '<%= name %>/version'
8
+ require '<%= name %>/<%= name %>'
9
+ require '<%= name %>/cli'
10
10
  include <%= MiscUtils.camel_case(name) %>
@@ -1,7 +1,6 @@
1
1
  module <%= MiscUtils.camel_case(name) %>
2
2
  CustomError = Class.new(StandardError)
3
3
  class << self
4
- # main helper method
5
4
  def helper
6
5
  puts 'FYI: <%= MiscUtils.camel_case(name) %>::helper()'
7
6
  end
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
32
32
  spec.add_development_dependency 'guard-minitest', '~> 2.3.2'
33
33
  spec.add_development_dependency 'minitest', '~> 5.4.2'
34
34
  spec.add_development_dependency 'minitest-spec-context', '~> 0.0.3'
35
- spec.add_development_dependency 'pry', '~> 0.10.0'
35
+ spec.add_development_dependency 'pry', '~> 0.10.1'
36
36
  spec.add_development_dependency 'pry-byebug', '~> 2.0.0' if RUBY_VERSION >= '2.0.0'
37
37
  spec.add_development_dependency 'rake', '~> 10.3.2'
38
38
  spec.add_development_dependency 'rubocop', '~> 0.26.1'
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,62 @@
1
+ require_relative '../../test_helper'
2
+ describe GemBootstrap do
3
+ describe '#snake_case' do
4
+ it 'handles camel case text properly' do
5
+ MiscUtils.snake_case("someText").must_equal("some_text")
6
+ MiscUtils.snake_case("SomeText").must_equal("some_text")
7
+ end
8
+ it 'handles string that does not start with lowercase' do
9
+ MiscUtils.snake_case("Sometext").must_equal("sometext")
10
+ end
11
+ end
12
+ describe '#camel_case' do
13
+ it 'handles string with underscore' do
14
+ MiscUtils.camel_case("some_text").must_equal("SomeText")
15
+ MiscUtils.camel_case("_some_text").must_equal("SomeText")
16
+ end
17
+ it 'handles string without underscore' do
18
+ MiscUtils.camel_case("html2pdf").must_equal("Html2pdf")
19
+ end
20
+ end
21
+ describe '#files' do
22
+ let :fixtures_dir do
23
+ File.expand_path("../../../fixtures", __FILE__)
24
+ end
25
+ context 'non matching file' do
26
+ it 'returns empty list by default' do
27
+ MiscUtils.files.must_equal []
28
+ end
29
+ it 'returns empty list for non-matching files' do
30
+ result = MiscUtils.files(base_dir: fixtures_dir,
31
+ exts: %w(invalid_extension),
32
+ recursive: true)
33
+ result.must_be_empty
34
+ end
35
+ end
36
+ context 'recursive' do
37
+ it 'returns proper list of files' do
38
+ result = MiscUtils.files(base_dir: fixtures_dir,
39
+ exts: %w(txt),
40
+ recursive: true)
41
+ result.map! { |file| file.gsub(fixtures_dir, '') }
42
+ result.must_equal ['/file1.txt', '/file2.txt', '/sub_dir/file3.txt', '/sub_dir/file4.txt']
43
+ end
44
+ it 'returns all files including one with no extension' do
45
+ result = MiscUtils.files(base_dir: fixtures_dir,
46
+ exts: %w(txt),
47
+ non_exts: %w(file0),
48
+ recursive: true)
49
+ result.map! { |file| file.gsub(fixtures_dir, '') }
50
+ result.must_equal ['/file0', '/file1.txt', '/file2.txt', '/sub_dir/file3.txt', '/sub_dir/file4.txt']
51
+ end
52
+ end
53
+ context 'non-recursive' do
54
+ it 'returns proper list of files' do
55
+ result = MiscUtils.files(base_dir: fixtures_dir,
56
+ exts: %w(txt))
57
+ result.map! { |file| file.gsub(fixtures_dir, '') }
58
+ result.must_equal ['/file1.txt', '/file2.txt' ]
59
+ end
60
+ end
61
+ end
62
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gem_bootstrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-09-30 00:00:00.000000000 Z
12
+ date: 2014-10-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport-core-ext
@@ -248,6 +248,7 @@ extra_rdoc_files: []
248
248
  files:
249
249
  - bin/gem_bootstrap
250
250
  - lib/gem_bootstrap/cli.rb
251
+ - lib/gem_bootstrap/errors.rb
251
252
  - lib/gem_bootstrap/gem_bootstrap.rb
252
253
  - lib/gem_bootstrap/git_utils.rb
253
254
  - lib/gem_bootstrap/misc_utils.rb
@@ -284,7 +285,13 @@ files:
284
285
  - LICENSE
285
286
  - .rubocop.yml
286
287
  - .gitignore
288
+ - test/fixtures/file0
289
+ - test/fixtures/file1.txt
290
+ - test/fixtures/file2.txt
291
+ - test/fixtures/sub_dir/file3.txt
292
+ - test/fixtures/sub_dir/file4.txt
287
293
  - test/lib/gem_bootstrap/test_gem_bootstrap.rb
294
+ - test/lib/gem_bootstrap/test_misc_utils.rb
288
295
  - test/test_helper.rb
289
296
  homepage: https://github.com/agilecreativity/gem_bootstrap
290
297
  licenses:
@@ -312,6 +319,12 @@ signing_key:
312
319
  specification_version: 3
313
320
  summary: Bootstrap the creation of ruby gem so that you don't have to start from scratch
314
321
  test_files:
322
+ - test/fixtures/file0
323
+ - test/fixtures/file1.txt
324
+ - test/fixtures/file2.txt
325
+ - test/fixtures/sub_dir/file3.txt
326
+ - test/fixtures/sub_dir/file4.txt
315
327
  - test/lib/gem_bootstrap/test_gem_bootstrap.rb
328
+ - test/lib/gem_bootstrap/test_misc_utils.rb
316
329
  - test/test_helper.rb
317
330
  has_rdoc: