rubynew 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2135a6716798afa07f1663f2c36b19f5ac921a1d
4
+ data.tar.gz: b19c0d85d2d990cd3a6eb7728069a15a505bff8d
5
+ SHA512:
6
+ metadata.gz: 0ebf5875e84c1547daa03409d0f59c33f26935e959e38f485473d0ea8794dd1c5ab2a9cd54f254ef5209b9a415905704d1e29bd420fa0d1da48e15b795ea6218
7
+ data.tar.gz: fa3ee1807603a5a64d5ffe511bfbfe44f8031bd9d11b8d488f224966885edbf436c908cfaec8556ad30b66bd3944faa724fad015c382de3598d4180c6652db1a
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rubygen.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Brian Hogan
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # Rubynew
2
+
3
+ TODO: Command-line utility for creating new projects in Ruby. Creates a `lib` folder and a `test` folder, and a Rakefile set up to run tests with Minitest.
4
+
5
+ ## Installation
6
+
7
+ As this is a command-line tool, install globally with
8
+
9
+ ```
10
+ $ gem install rubynew
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ Run the `rubynew` command and pass it the name of the project you want to create. The project
16
+ name will be converted to a constant for use as a module name and a class name, similar to how
17
+ Bundler works when creating a gem.
18
+
19
+ ```
20
+ $ rubynew tip_calculator
21
+ ```
22
+
23
+ ## Contributing
24
+
25
+ Please contribute. I'm interested in discussing features, such as providing optiosn for alternative frameworks for testing. However, the default will always be what Ruby's default is. I want this to be simple for beginners, so the defaults will do whatever Ruby does by default. Right now that's Rake and Minitest.
26
+
27
+ To contribute:
28
+
29
+ 1. Fork it ( https://github.com/napcs/rubynew/fork )
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create a new Pull Request
34
+
35
+ ## License
36
+
37
+ MIT. See LICENSE.txt.
38
+
39
+ ## History
40
+
41
+ 2015-08-23
42
+
43
+ * Initial version
44
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << "test"
7
+ t.test_files = FileList['test/*_test.rb']
8
+ t.verbose = true
9
+ end
10
+
data/bin/rubynew ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "rubynew"
4
+
5
+ folder = ARGV[0]
6
+
7
+ if folder.nil?
8
+ puts "Specify a folder name and I'll create it."
9
+ else
10
+ project = Rubynew::Project.new(folder)
11
+ project.create
12
+ puts "\nCreated folder #{folder}."
13
+ puts "To use it, type: \n\tcd #{folder}\n\nand run tests with\n\n\trake test"
14
+ end
@@ -0,0 +1,46 @@
1
+ require 'erb'
2
+ require 'fileutils'
3
+
4
+ module Rubynew
5
+ class Project
6
+
7
+ def initialize(name)
8
+ @name = name
9
+ # ripped off from Bundler
10
+ @underscored_name = @name.tr("-", "_")
11
+ @constant_name = @name.gsub(/-[_-]*(?![_-]|$)/) { "::" }.gsub(/([_-]+|(::)|^)(.|$)/) { $2.to_s + $3.upcase }
12
+ end
13
+
14
+ def create
15
+ template_path = File.expand_path("../../../template", __FILE__)
16
+
17
+ # copy the template
18
+ FileUtils.cp_r template_path, @name
19
+
20
+ # rename the files
21
+ FileUtils.mv File.join(@name, "lib", "app"), File.join(@name, "lib", @underscored_name)
22
+ FileUtils.mv File.join(@name, "lib", "app.rb"), File.join(@name, "lib", "#{@underscored_name}.rb")
23
+ FileUtils.mv File.join(@name, "test", "app_test.rb"), File.join(@name, "test", "#{@underscored_name}_test.rb")
24
+
25
+ # apply templates
26
+ [
27
+ File.join(@name, "lib", "#{@underscored_name}.rb"),
28
+ File.join(@name, "lib", @underscored_name, "version.rb"),
29
+ File.join(@name, "test", "#{@underscored_name}_test.rb")
30
+ ].each { |file| render_template_to_file file, binding }
31
+
32
+
33
+
34
+ end
35
+
36
+ private
37
+
38
+ def render_template_to_file(template, context)
39
+ t = File.read(template)
40
+ File.open(template, "w") do |f|
41
+ f << ERB.new(t, nil, "-").result(context)
42
+ end
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ module Rubynew
2
+ VERSION = "0.0.1"
3
+ end
data/lib/rubynew.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'rubynew/version'
2
+ require 'rubynew/project'
3
+
4
+ module Rubynew
5
+ end
data/rubynew.gemspec ADDED
@@ -0,0 +1,40 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rubynew/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rubynew"
8
+ spec.version = Rubynew::VERSION
9
+ spec.authors = ["Brian Hogan"]
10
+ spec.email = ["brianhogan@napcs.com"]
11
+ spec.summary = %q{Generate new Ruby projects with tests.}
12
+ spec.description = %q{Ruby project generator. Creates lib/ and test/ folders with a module and a Rakefile so you can quickly develop an app with tests.}
13
+ spec.homepage = "http://github.com/napcs/rubynew"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = [
17
+ "bin/rubynew",
18
+ "lib/rubynew.rb",
19
+ "lib/rubynew/version.rb",
20
+ "lib/rubynew/project.rb",
21
+ "template/Rakefile",
22
+ "template/lib/app/version.rb",
23
+ "template/lib/app.rb",
24
+ "template/test/app_test.rb",
25
+ "test/rubynew_test.rb",
26
+ "Rakefile",
27
+ "Gemfile",
28
+ "README.md",
29
+ "rubynew.gemspec",
30
+ "LICENSE.txt"
31
+
32
+ ]
33
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
34
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
35
+ spec.require_paths = ["lib"]
36
+
37
+ spec.add_development_dependency "bundler", "~> 1.6"
38
+ spec.add_development_dependency "rake"
39
+ spec.add_development_dependency "minitest"
40
+ end
data/template/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "rake/testtask"
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << "test"
5
+ t.test_files = FileList["test/*_test.rb"]
6
+ t.verbose = true
7
+ end
@@ -0,0 +1,3 @@
1
+ module <%= @constant_name %>
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,5 @@
1
+ require "<%= @underscored_name %>/version"
2
+
3
+ module <%= @constant_name %>
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,8 @@
1
+ require "minitest/autorun"
2
+ require "<%= @underscored_name %>"
3
+
4
+ class <%= @constant_name %>Test < Minitest::Test
5
+ def test_fails
6
+ flunk "Gotta write a test!"
7
+ end
8
+ end
@@ -0,0 +1,75 @@
1
+ require 'minitest/autorun'
2
+ require 'rubynew/project'
3
+
4
+ # Not really a unit test - more of an integration test.
5
+ class RubynewTest < MiniTest::Test
6
+
7
+ def setup
8
+ @folder = "tmpproject"
9
+ end
10
+
11
+ def teardown
12
+ # Remove the folder at the end of
13
+ # each test run so it's always cleared out
14
+ FileUtils.rm_rf @folder
15
+ end
16
+
17
+ def test_create_project_dir
18
+ Rubynew::Project.new(@folder).create
19
+
20
+ assert File.exist?(File.join(@folder, "Rakefile"))
21
+ assert File.exist?(File.join(@folder, "lib", "#{@folder}.rb"))
22
+ assert File.exist?(File.join(@folder, "lib", @folder, "version.rb"))
23
+ assert File.exist?(File.join(@folder, "test", "#{@folder}_test.rb"))
24
+
25
+ end
26
+
27
+ def test_create_rakefile_with_test_task
28
+ Rubynew::Project.new(@folder).create
29
+
30
+ file = Pathname.new(File.join(@folder, "Rakefile"))
31
+ assert file.read.include?("require \"rake/testtask\"")
32
+ end
33
+
34
+ def test_class_has_constant_name
35
+ Rubynew::Project.new(@folder).create
36
+
37
+ file = Pathname.new(File.join(@folder, "lib", "#{@folder}.rb"))
38
+ assert file.read.include?("Tmpproject")
39
+ end
40
+
41
+ def test_version_has_module_name
42
+ Rubynew::Project.new(@folder).create
43
+
44
+ file = Pathname.new(File.join(@folder, "lib", "#{@folder}", "version.rb"))
45
+ assert file.read.include?("module Tmpproject")
46
+ end
47
+
48
+ def test_app_has_module_name
49
+ Rubynew::Project.new(@folder).create
50
+
51
+ file = Pathname.new(File.join(@folder, "lib", "#{@folder}.rb"))
52
+ assert file.read.include?("module Tmpproject")
53
+ end
54
+
55
+ def test_app_loads_version
56
+ Rubynew::Project.new(@folder).create
57
+
58
+ file = Pathname.new(File.join(@folder, "lib", "#{@folder}.rb"))
59
+ assert file.read.include?("require \"tmpproject/version\"")
60
+ end
61
+
62
+ def test_unit_test_loads_app
63
+ Rubynew::Project.new(@folder).create
64
+
65
+ file = Pathname.new(File.join(@folder, "test", "#{@folder}_test.rb"))
66
+ assert file.read.include?("require \"tmpproject\"")
67
+ end
68
+
69
+ def test_unit_test_creates_class
70
+ Rubynew::Project.new(@folder).create
71
+
72
+ file = Pathname.new(File.join(@folder, "test", "#{@folder}_test.rb"))
73
+ assert file.read.include?("class TmpprojectTest < Minitest::Test")
74
+ end
75
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubynew
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Brian Hogan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-23 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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
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'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '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: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Ruby project generator. Creates lib/ and test/ folders with a module
56
+ and a Rakefile so you can quickly develop an app with tests.
57
+ email:
58
+ - brianhogan@napcs.com
59
+ executables:
60
+ - rubynew
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - bin/rubynew
69
+ - lib/rubynew.rb
70
+ - lib/rubynew/project.rb
71
+ - lib/rubynew/version.rb
72
+ - rubynew.gemspec
73
+ - template/Rakefile
74
+ - template/lib/app.rb
75
+ - template/lib/app/version.rb
76
+ - template/test/app_test.rb
77
+ - test/rubynew_test.rb
78
+ homepage: http://github.com/napcs/rubynew
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.2.2
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Generate new Ruby projects with tests.
102
+ test_files:
103
+ - test/rubynew_test.rb