Skip to content
Browse files

working/gemspec helper tool'lets.

  • Loading branch information...
1 parent 6eabba0 commit 3c91965bd38f04c51016b0cc60a64a6d49ff9a29 @rking committed with rking@sharpsaw.org
Showing with 101 additions and 35 deletions.
  1. +0 −23 lib/working.rb
  2. +55 −0 lib/working/gemspec.rb
  3. +1 −0 test/test_helper.rb
  4. +45 −0 test/working/gemspec_test.rb
  5. +0 −12 test/working_test.rb
View
23 lib/working.rb
@@ -1,27 +1,4 @@
require 'working/version'
module Working
- README_PATH = 'README.rdoc'
-
- class << self
- def file_snippet path, start_pattern, end_pattern
- desired = []
- File.readlines(path).each do |e|
- return desired.join if e[end_pattern]
- in_desired_region = true if e[start_pattern]
- desired << e if in_desired_region
- end
- desired
- end
- def readme_snippet start_pattern, end_pattern
- file_snippet README_PATH, start_pattern, end_pattern
- end
-
- def file_third_line path
- File.readlines(path)[2]
- end
- def third_line_of_readme
- file_third_line README_PATH
- end
- end
end
View
55 lib/working/gemspec.rb
@@ -0,0 +1,55 @@
+$:.unshift './lib'
+
+module Working
+ README_PATH = 'README.rdoc'
+
+ class << self
+ def gemspec args
+ require_version_file args[:name]
+ Gem::Specification.new do |gem|
+ gem.name = args[:name]
+ gem.authors = args[:authors]
+ gem.email = args[:email]
+ gem.version = args[:version]
+
+ gem.homepage = 'https://github.com/' + args[:github]
+
+ gem.files = git_ls_files
+ gem.executables = gem.files.grep(%r{^bin/}).map{|f| File.basename f}
+ gem.test_files = gem.files.grep %r{^(test|spec|features)}
+
+ args[:deps].each do |e|
+ gem.add_dependency e
+ end
+ end
+ end
+
+ def git_ls_files
+ `git ls-files`.split $/
+ end
+
+ def require_version_file name
+ require name
+ end
+
+ def file_snippet path, start_pattern, end_pattern
+ desired = []
+ File.readlines(path).each do |e|
+ return desired.join if e[end_pattern]
+ in_desired_region = true if e[start_pattern]
+ desired << e if in_desired_region
+ end
+ desired
+ end
+ def readme_snippet start_pattern, end_pattern
+ file_snippet README_PATH, start_pattern, end_pattern
+ end
+
+ def file_third_line path
+ File.readlines(path)[2]
+ end
+ def third_line_of_readme
+ file_third_line README_PATH
+ end
+ end
+end
View
1 test/test_helper.rb
@@ -2,4 +2,5 @@
# Spork.prefork doesn't like when this is missing
Spork.each_run do
require 'working'
+ require 'working/gemspec'
end
View
45 test/working/gemspec_test.rb
@@ -0,0 +1,45 @@
+require './test/test_helper.rb'
+class WorkingGemspecTest < MiniTest::Unit::TestCase
+ def test_dsl
+ gem = nil
+ fake_file_list = %w(
+ Gemfile
+ bin/mygeminate
+ lib/mygem.rb
+ lib/mygem/version.rb
+ test/mygem_test.rb
+ )
+ version_file_arg = nil
+ Working.stub :require_version_file, -> path { version_file_arg = path } do
+ Working.stub :git_ls_files, fake_file_list do
+ gem = Working.gemspec \
+ name: 'mygem', # TODO: Deduce this
+ version: '0.2.3', # TODO: Deduce MyGem::VERSION (from file?)
+ authors: ['Cod Err'],
+ github: 'coderr/mygem',
+ email: 'foo@example.com',
+ deps: %w(a b c)
+ end
+ end
+ assert_equal 'mygem', gem.name
+ assert_equal ['Cod Err'], gem.authors
+ assert_equal 'foo@example.com', gem.email
+ assert_equal 'https://github.com/coderr/mygem', gem.homepage
+ assert_equal '0.2.3', gem.version.to_s
+ assert_equal 3, gem.dependencies.size
+ assert_equal fake_file_list, gem.files
+ assert_equal %w(mygeminate), gem.executables
+ assert_equal %w(test/mygem_test.rb), gem.test_files
+ assert_equal 'mygem', version_file_arg
+ end
+
+ def test_file_snippet
+ actual = Working.file_snippet(__FILE__, /^require/, /^class/)
+ assert_equal "require './test/test_helper.rb'\n", actual
+ end
+
+ # This is because I put the gem.summary on the 3rd line of the README.rdoc
+ def test_third_line
+ assert_equal " def test_dsl\n", Working.file_third_line(__FILE__)
+ end
+end
View
12 test/working_test.rb
@@ -1,12 +0,0 @@
-require './test/test_helper.rb'
-class WorkingTest < MiniTest::Unit::TestCase
- def test_file_snippet
- actual = Working.file_snippet(__FILE__, /^require/, /^class/)
- assert_equal "require './test/test_helper.rb'\n", actual
- end
-
- # This is because I put the gem.summary on the 3rd line of the README.rdoc
- def test_third_line
- assert_equal " def test_file_snippet\n", Working.file_third_line(__FILE__)
- end
-end

0 comments on commit 3c91965

Please sign in to comment.
Something went wrong with that request. Please try again.