working 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1 +1,4 @@
1
1
  source :rubygems; gemspec
2
+ group :development do
3
+ gem 'working', path: '.'
4
+ end
data/Guardfile ADDED
@@ -0,0 +1,2 @@
1
+ require 'working/guard'
2
+ # vim ft=ruby
data/README.md CHANGED
@@ -1,22 +1,25 @@
1
- # Working
1
+ = Working
2
2
 
3
3
  Whoa!! ☈king's opinionated rig for Ruby dev.
4
4
 
5
- - Guard for test running (`bundle exec guard`)
5
+ == Basic Idea
6
+
7
+ - Opinionatedly uses MiniTest for everything. It makes better in-memory structures than RSpec, and is therefore better for the goals of https://github.com/pry/pry/wiki/pry-de
6
8
  - 1:1 mapping between stuff in `lib/` or `app/` and the `test/` dirs.
9
+ - Guard for test running (`bundle exec guard`)
7
10
  - Spork in effect for faster runs
8
11
 
9
- # See also:
12
+ == See also:
10
13
 
11
14
  http://github.com/rking/working-rails
12
15
 
13
- ## Example uses:
16
+ == Example uses:
14
17
 
15
18
  - https://github.com/rking/demo-ruby-tests
16
19
  - https://github.com/rking/monkeynote
17
20
  - https://github.com/rking/terminal-info
18
21
 
19
- ## Installation
22
+ == Installation
20
23
 
21
24
  Add this line to your application's Gemfile:
22
25
 
@@ -27,6 +30,6 @@ And then execute:
27
30
  bundle
28
31
  working-init # this tinkers with several files (verbosely)
29
32
 
30
- ## TODO
33
+ == TODO
31
34
 
32
35
  Explain the parts.
data/Rakefile CHANGED
@@ -1 +1,2 @@
1
1
  require 'bundler/gem_tasks'
2
+ require 'working/rake_tasks'
data/bin/working-init CHANGED
@@ -24,7 +24,6 @@ end
24
24
  '# vim ft=ruby',
25
25
  ],
26
26
  'Rakefile' => [
27
- # gem TODO require 'bundler/gem_tasks'
28
27
  %{require 'working/rake_tasks'}
29
28
  ],
30
29
  'test/test_helper.rb' => [
@@ -0,0 +1,81 @@
1
+ $:.unshift './lib'
2
+
3
+ module Working
4
+ README_PATH = 'README.rdoc'
5
+ REQUIRED_FIELDS = [
6
+ :name,
7
+ :summary,
8
+ :description,
9
+ :authors,
10
+ :email,
11
+ :version,
12
+ :github,
13
+ :deps,
14
+ ]
15
+
16
+ class << self
17
+ def gemspec args
18
+ validate_gem_args! args
19
+ require_version_file args[:name]
20
+ Gem::Specification.new do |gem|
21
+ [ :name, :summary, :authors, :email, :version ].each do |e|
22
+ gem.send "#{e}=", args[e]
23
+ end
24
+
25
+ gem.description = gem.summary + "\n\n" + args[:description]
26
+
27
+ gem.homepage = 'https://github.com/' + args[:github]
28
+
29
+ gem.files = git_ls_files
30
+ gem.executables = gem.files.grep(%r{^bin/}).map{|f| File.basename f}
31
+ gem.test_files = gem.files.grep %r{^(test|spec|features)}
32
+
33
+ args[:deps].each do |e|
34
+ gem.add_dependency e
35
+ end
36
+ end
37
+ end
38
+
39
+ def validate_gem_args! input
40
+ args = input.dup
41
+ missing_fields = REQUIRED_FIELDS.find_all{|e| !args.delete e}
42
+ fail <<-EOT unless args.size.zero?
43
+ Working.gem got #{args.keys.join ' and '},
44
+ but only expected #{REQUIRED_FIELDS.map(&:to_s).join ', '}
45
+ EOT
46
+ return if missing_fields.size.zero?
47
+ fail "Working.gem needs: #{missing_fields.map(&:to_s).join ', '}"
48
+ end
49
+
50
+ def git_ls_files
51
+ `git ls-files`.split $/
52
+ end
53
+
54
+ def require_version_file name
55
+ require name
56
+ rescue LoadError
57
+ # Do nothing
58
+ end
59
+
60
+ def file_snippet path, start_pattern, end_pattern
61
+ desired = []
62
+ in_desired_region = false
63
+ File.readlines(path).each do |e|
64
+ break if e[end_pattern]
65
+ in_desired_region = true if e[start_pattern]
66
+ desired << e if in_desired_region
67
+ end
68
+ desired.join
69
+ end
70
+ def readme_snippet start_pattern, end_pattern
71
+ file_snippet README_PATH, start_pattern, end_pattern
72
+ end
73
+
74
+ def file_third_line path
75
+ File.readlines(path)[2]
76
+ end
77
+ def third_line_of_readme
78
+ file_third_line README_PATH
79
+ end
80
+ end
81
+ end
@@ -1,3 +1,4 @@
1
+ require 'bundler/gem_tasks'
1
2
  task default: :test
2
3
  task :test do
3
4
  Dir['test/**/*_test.rb'].each{|e| load e}
@@ -1,3 +1,3 @@
1
1
  module Working
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.8'
3
3
  end
data/lib/working.rb CHANGED
@@ -1,5 +1,4 @@
1
- require "working/version"
1
+ require 'working/version'
2
2
 
3
3
  module Working
4
- # Your code goes here...
5
4
  end
@@ -0,0 +1,6 @@
1
+ require 'working/test_helper'
2
+ # Spork.prefork doesn't like when this is missing
3
+ Spork.each_run do
4
+ require 'working'
5
+ require 'working/gemspec'
6
+ end
@@ -0,0 +1,75 @@
1
+ require './test/test_helper.rb'
2
+ class WorkingGemspecTest < MiniTest::Unit::TestCase
3
+ def valid_working_gemspec_args
4
+ {
5
+ name: 'mygem', # TODO: Deduce this
6
+ version: '0.2.3', # TODO: Deduce MyGem::VERSION (from file?)
7
+ authors: ['Cod Err'],
8
+ github: 'coderr/mygem',
9
+ email: 'foo@example.com',
10
+ deps: %w(a b c),
11
+ summary: 'Hi.',
12
+ description: 'Hello, how are you?',
13
+ }
14
+ end
15
+
16
+ def test_dsl
17
+ gem = nil
18
+ fake_file_list = %w(
19
+ Gemfile
20
+ bin/mygeminate
21
+ lib/mygem.rb
22
+ lib/mygem/version.rb
23
+ test/mygem_test.rb
24
+ )
25
+ version_file_arg = nil
26
+ Working.stub :require_version_file, -> path { version_file_arg = path } do
27
+ Working.stub :git_ls_files, fake_file_list do
28
+ args = valid_working_gemspec_args
29
+ gem = Working.gemspec args
30
+ end
31
+ end
32
+ assert_equal 'mygem', gem.name
33
+ assert_equal 'Hi.', gem.summary
34
+ assert_equal "Hi.\n\nHello, how are you?", gem.description
35
+ assert_equal ['Cod Err'], gem.authors
36
+ assert_equal 'foo@example.com', gem.email
37
+ assert_equal 'https://github.com/coderr/mygem', gem.homepage
38
+ assert_equal '0.2.3', gem.version.to_s
39
+ assert_equal 3, gem.dependencies.size
40
+ assert_equal fake_file_list, gem.files
41
+ assert_equal %w(mygeminate), gem.executables
42
+ assert_equal %w(test/mygem_test.rb), gem.test_files
43
+ assert_equal 'mygem', version_file_arg
44
+ end
45
+
46
+ def test_verbose_failure
47
+ args = valid_working_gemspec_args
48
+ required_fields = %w(name authors email version github deps)
49
+ required_fields.each do |e|
50
+ begin
51
+ bad_args = args.dup
52
+ bad_args.delete e.to_sym
53
+ Working.gemspec bad_args
54
+ rescue => err
55
+ assert_match e, err.message
56
+ end
57
+ end
58
+
59
+ assert_raises RuntimeError do
60
+ Working.gemspec valid_working_gemspec_args.merge hi: 1
61
+ end
62
+ end
63
+
64
+ def test_file_snippet
65
+ actual = Working.file_snippet(__FILE__, /^require/, /^\s*def/)
66
+ assert_equal %(require './test/test_helper.rb'
67
+ class WorkingGemspecTest < MiniTest::Unit::TestCase\n), actual
68
+ end
69
+
70
+ # This is because I put the gem.summary on the 3rd line of the README.rdoc
71
+ def test_third_line
72
+ assert_equal " def valid_working_gemspec_args\n",
73
+ Working.file_third_line(__FILE__)
74
+ end
75
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: working
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.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: 2013-01-04 00:00:00.000000000 Z
12
+ date: 2013-01-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pry-de
@@ -134,15 +134,19 @@ files:
134
134
  - .gemspec
135
135
  - .gitignore
136
136
  - Gemfile
137
+ - Guardfile
137
138
  - LICENSE.txt
138
139
  - README.md
139
140
  - Rakefile
140
141
  - bin/working-init
141
142
  - lib/working.rb
143
+ - lib/working/gemspec.rb
142
144
  - lib/working/guard.rb
143
145
  - lib/working/rake_tasks.rb
144
146
  - lib/working/test_helper.rb
145
147
  - lib/working/version.rb
148
+ - test/test_helper.rb
149
+ - test/working/gemspec_test.rb
146
150
  homepage: https://github.com/rking/working
147
151
  licenses: []
148
152
  post_install_message:
@@ -169,4 +173,6 @@ specification_version: 3
169
173
  summary: Whoa — ☈king's rig
170
174
  test_files:
171
175
  - .gemspec
176
+ - lib/working/gemspec.rb
177
+ - test/working/gemspec_test.rb
172
178
  has_rdoc: