blam 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d92a28640beb18f8070efd31f266d764812de862
4
+ data.tar.gz: 24b98b9b36352698f2791e197d21660824e58b96
5
+ SHA512:
6
+ metadata.gz: 1eced1ec385cd835f9a8dd9a019a4146de26610b45e90d8b804a7e333cfba727b83b69554d27eff07885197cd81fd2b9ca014197b458364f221c1f5c19012ad4
7
+ data.tar.gz: 131c8b41125a8ac2c5f709171312e30e8316c4d4ea7c9c7501fd886edf91648029daadfc18933bcd14fdcc086acab2b1c8e7d0daf53d4c3661da9534b6cb8194
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ build
@@ -0,0 +1,15 @@
1
+ LineLength:
2
+ Enabled: false
3
+
4
+ MethodLength:
5
+ Max: 30
6
+
7
+ SymbolName:
8
+ AllowCamelCase: false
9
+
10
+ Documentation:
11
+ Enabled: false
12
+
13
+ AllCops:
14
+ Excludes:
15
+ - build
@@ -0,0 +1 @@
1
+ blam
@@ -0,0 +1 @@
1
+ ruby-2.0.0-p247
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
@@ -0,0 +1,2 @@
1
+ #1.0.0 (2013-10-03)
2
+ - Initial Release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in blam.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jason Fox
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.
@@ -0,0 +1,86 @@
1
+ # BLAM! [![Build Status](https://travis-ci.org/neverstopbuilding/blam.png?branch=develop)](https://travis-ci.org/neverstopbuilding/blam)
2
+
3
+ ##Create ruby files quickly on the command line. BLAM!
4
+
5
+ It's a pain to have to create a bunch of folders and duplicate files to make your source and associated test files. Blam fixes this.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'blam'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install blam
20
+
21
+ ## Usage
22
+
23
+ $ blam BeastlyModule::DopeClass
24
+
25
+ By default creates these files:
26
+
27
+ - lib
28
+ - beastly_module
29
+ - dope_class.rb
30
+ - spec
31
+ - beastly_module
32
+ - dope_class_spec.rb
33
+
34
+ The class file has:
35
+
36
+ ```ruby
37
+ # Encoding: utf-8
38
+
39
+ module BeastlyModule
40
+ class DopeClass
41
+
42
+ end
43
+ end
44
+ ```
45
+
46
+ The spec file has:
47
+
48
+ ```ruby
49
+ # Encoding: utf-8
50
+
51
+ require 'spec_helper'
52
+ require 'beastly_module/dope_class'
53
+
54
+ describe BeastlyModule::DopeClass do
55
+
56
+ end
57
+ ```
58
+
59
+ ###Command Line Options
60
+
61
+ - **--source-dir** - Pass an alternative directory to `lib` in which the source files will be created.
62
+ - **--tests-dir** - Pass an alternative directory to `spec` in which the test files will be created.
63
+ - **--test-suffix** - Change the suffix from the test files from the default `spec` to anything you like. Non spec suffixes will get a default class template rather than an rspec class template.
64
+ - **--additional-test-dirs** - Add other directories to create additional test files. This can be helpful for breaking up your tests into folders like `spec/unit` `spec/integration`
65
+
66
+ ###.blam File
67
+
68
+ No one likes to type all those crazy options all the time! BLAM! Put them in a file called `.blam` in the root of your project:
69
+
70
+ ```YAML
71
+ tests_dir: spec/unit/lib
72
+ additional_test_dirs: [spec/integration/lib, spec/system/lib]
73
+ source_dir: lib
74
+ test_suffix: spec
75
+ ```
76
+
77
+ Don't worry, you can override these with the command line options any time. Blam!
78
+
79
+ ## Contributing
80
+
81
+ 1. Fork it
82
+ 2. Create your feature branch with [git-flow](https://github.com/nvie/gitflow) (`git flow feature start my-new-feature`)
83
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
84
+ 4. Run the fucking tests (`rake` Runs Rubocop and Cucumber by default.)
85
+ 4. Publish the feature (`git flow feature publish my-new-feature`)
86
+ 5. Create new Pull Request
@@ -0,0 +1,19 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rubocop/rake_task'
3
+ require 'cucumber/rake/task'
4
+
5
+ task default: :build
6
+
7
+ task build: [:clean, :prepare, :rubocop, :cucumber]
8
+
9
+ task :clean do
10
+ FileUtils.rm_rf 'build'
11
+ end
12
+
13
+ task :prepare do
14
+ FileUtils.mkdir_p('build')
15
+ end
16
+
17
+ Rubocop::RakeTask.new
18
+
19
+ Cucumber::Rake::Task.new(:cucumber)
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # Encoding: utf-8
3
+
4
+ require 'blam'
5
+
6
+ Blam.start
@@ -0,0 +1,26 @@
1
+ # Encoding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'blam'
8
+ spec.version = '1.0.0'
9
+ spec.authors = ['Jason Fox']
10
+ spec.email = ['jasonrobertfox@gmail.com']
11
+ spec.description = %q{Blam: quickly create ruby source and test files in the right place.}
12
+ spec.summary = %q{With a single command Blam will create your source file and any test files in the right directories based on namespace.}
13
+ spec.homepage = 'https://github.com/neverstopbuilding/blam'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'aruba'
24
+ spec.add_development_dependency 'rubocop'
25
+ spec.add_dependency 'thor'
26
+ end
@@ -0,0 +1,123 @@
1
+ @announce
2
+ Feature: Creates a class and associated test files in the correct place
3
+
4
+ Scenario: Running the command with no arguments
5
+ Given I run `bundle exec blam NameSpace::ClassName`
6
+ Then the following directories should exist:
7
+ | lib/name_space |
8
+ | spec/name_space |
9
+ And the following files should exist:
10
+ | lib/name_space/class_name.rb |
11
+ | spec/name_space/class_name_spec.rb |
12
+
13
+ Scenario: Specifying the source path
14
+ Given I run `bundle exec blam NameSpace::ClassName --source_dir=other/dir`
15
+ Then the following files should exist:
16
+ | other/dir/name_space/class_name.rb |
17
+
18
+
19
+ Scenario: A trailing slash should not matter
20
+ Given I run `bundle exec blam NameSpace::ClassName --source_dir=other/dir/`
21
+ Then the following files should exist:
22
+ | other/dir/name_space/class_name.rb |
23
+
24
+ Scenario: Specifying the test path
25
+ Given I run `bundle exec blam NameSpace::ClassName --tests_dir=spec/unit/lib`
26
+ Then the following files should exist:
27
+ | spec/unit/lib/name_space/class_name_spec.rb |
28
+
29
+ Scenario: Specifying the test suffix
30
+ Given I run `bundle exec blam NameSpace::ClassName --test_suffix=test`
31
+ Then the following files should exist:
32
+ | spec/name_space/class_name_test.rb |
33
+
34
+ Scenario: Specifying additional test directories
35
+ Given I run `bundle exec blam NameSpace::ClassName --tests_dir=spec/unit/lib --additional-test-dirs=spec/integration/lib spec/system/lib`
36
+ Then the following files should exist:
37
+ | lib/name_space/class_name.rb |
38
+ | spec/unit/lib/name_space/class_name_spec.rb |
39
+ | spec/integration/lib/name_space/class_name_spec.rb |
40
+ | spec/system/lib/name_space/class_name_spec.rb |
41
+
42
+ Scenario: Specifying default settings with a .blam file
43
+ Given a file named ".blam" with:
44
+ """
45
+ tests_dir: spec/unit/lib
46
+ additional_test_dirs: [spec/integration/lib, spec/system/lib]
47
+ source_dir: src
48
+ test_suffix: test
49
+ """
50
+ When I run `bundle exec blam NameSpace::ClassName`
51
+ Then the following files should exist:
52
+ | src/name_space/class_name.rb |
53
+ | spec/unit/lib/name_space/class_name_test.rb |
54
+ | spec/integration/lib/name_space/class_name_test.rb |
55
+ | spec/system/lib/name_space/class_name_test.rb |
56
+
57
+ Scenario: Overriding the .blam file with cli options
58
+ Given a file named ".blam" with:
59
+ """
60
+ tests_dir: spec/unit/lib
61
+ additional_test_dirs: [spec/integration/lib, spec/system/lib]
62
+ source_dir: src
63
+ test_suffix: test
64
+ """
65
+ When I run `bundle exec blam NameSpace::ClassName --tests_dir=tests/unit/lib --additional-test-dirs=tests/integration/lib tests/system/lib --source_dir=code --test_suffix=example `
66
+ Then the following files should exist:
67
+ | code/name_space/class_name.rb |
68
+ | tests/unit/lib/name_space/class_name_example.rb |
69
+ | tests/integration/lib/name_space/class_name_example.rb |
70
+ | tests/system/lib/name_space/class_name_example.rb |
71
+
72
+ Scenario: Create the correct source and test file
73
+ Given I run `bundle exec blam NameSpace::OtherSpace::ClassName`
74
+ Then the file "lib/name_space/other_space/class_name.rb" should contain exactly:
75
+ """
76
+ # Encoding: utf-8
77
+
78
+ module NameSpace
79
+ module OtherSpace
80
+ class ClassName
81
+
82
+ end
83
+ end
84
+ end
85
+
86
+ """
87
+ And the file "spec/name_space/other_space/class_name_spec.rb" should contain exactly:
88
+ """
89
+ # Encoding: utf-8
90
+
91
+ require 'spec_helper'
92
+ require 'name_space/other_space/class_name'
93
+
94
+ describe NameSpace::OtherSpace::ClassName do
95
+
96
+ end
97
+
98
+ """
99
+
100
+ Scenario: Create the correct alternative test file
101
+ Given I run `bundle exec blam NameSpace::OtherSpace::ClassName --test_suffix=test`
102
+ Then the file "spec/name_space/other_space/class_name_test.rb" should contain exactly:
103
+ """
104
+ # Encoding: utf-8
105
+
106
+ require 'name_space/other_space/class_name'
107
+
108
+ class NameSpace::OtherSpace::ClassNameTest do
109
+
110
+ end
111
+
112
+ """
113
+
114
+ Scenario: Don't overwrite existing files
115
+ Given a file named "lib/name_space/class_name.rb" with:
116
+ """
117
+ Important Code
118
+ """
119
+ When I run `bundle exec blam NameSpace::ClassName`
120
+ Then the file "lib/name_space/class_name.rb" should contain exactly:
121
+ """
122
+ Important Code
123
+ """
@@ -0,0 +1,8 @@
1
+ # Encoding: utf-8
2
+
3
+ require 'aruba/cucumber'
4
+
5
+ Before do
6
+ FileUtils.rm_rf('build/tmp')
7
+ @dirs = ['build/tmp']
8
+ end
@@ -0,0 +1,63 @@
1
+ # Encoding: utf-8
2
+
3
+ require 'thor/group'
4
+ require 'yaml'
5
+
6
+ class Blam < Thor::Group
7
+
8
+ include Thor::Actions
9
+
10
+ argument :name
11
+
12
+ class_option :source_dir
13
+ class_option :tests_dir
14
+ class_option :test_suffix
15
+ class_option :additional_test_dirs, type: :array
16
+
17
+ def self.source_root
18
+ File.dirname(__FILE__)
19
+ end
20
+
21
+ def create_source_file
22
+ dir = opts[:source_dir]
23
+ @class_parts = name.split('::')
24
+ file_name = "#{dir}/#{get_path(name)}.rb"
25
+ template('templates/source.tt', file_name) unless File.exists?(file_name)
26
+ end
27
+
28
+ def create_test_file
29
+ dirs = [opts[:tests_dir]]
30
+ test_suffix = opts[:test_suffix]
31
+ test_template = test_suffix == 'spec' ? 'rspec' : 'test'
32
+ dirs.concat opts[:additional_test_dirs] if opts[:additional_test_dirs]
33
+ dirs.each do |dir|
34
+ @name = name
35
+ @path = get_path(name)
36
+ file_name = "#{dir}/#{get_path(name)}_#{test_suffix}.rb"
37
+ template("templates/#{test_template}.tt", file_name) unless File.exists?(file_name)
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ def get_path(name)
44
+ name.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').gsub(/([a-z\d])([A-Z])/, '\1_\2').tr('-', '_').downcase
45
+ end
46
+
47
+ def opts
48
+ default_opts = { source_dir: 'lib', tests_dir: 'spec', test_suffix: 'spec' }
49
+ cli_opts = symbolize(options)
50
+ return default_opts.merge(cli_opts) unless File.exists?('.blam')
51
+ raw_file_opts = ::YAML.load_file('.blam') || {}
52
+ file_opts = symbolize(raw_file_opts)
53
+ default_opts.merge(file_opts).merge(cli_opts)
54
+ end
55
+
56
+ def symbolize(hash)
57
+ new_hash = {}
58
+ hash.each do |key, value|
59
+ new_hash[key.to_sym] = value
60
+ end
61
+ new_hash
62
+ end
63
+ end
@@ -0,0 +1,8 @@
1
+ # Encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require '<%= @path %>'
5
+
6
+ describe <%= @name %> do
7
+
8
+ end
@@ -0,0 +1,17 @@
1
+ # Encoding: utf-8
2
+
3
+ <%
4
+ spacing = ''
5
+ @class_parts[0..-2].each do |namespace|
6
+ %><%= spacing + 'module ' + namespace %>
7
+ <%
8
+ spacing+= ' '
9
+ end %><%= spacing + 'class ' + @class_parts.last %>
10
+
11
+ <%= spacing + 'end' %><% loop do
12
+ l = spacing.length - 2
13
+ spacing = l >= 0 ? ' '*l : ''
14
+ %>
15
+ <%= spacing + 'end' %><%
16
+ break if l == 0
17
+ end %>
@@ -0,0 +1,7 @@
1
+ # Encoding: utf-8
2
+
3
+ require '<%= @path %>'
4
+
5
+ class <%= @name + 'Test' %> do
6
+
7
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: blam
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jason Fox
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-04 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: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
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: aruba
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
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: thor
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: 'Blam: quickly create ruby source and test files in the right place.'
84
+ email:
85
+ - jasonrobertfox@gmail.com
86
+ executables:
87
+ - blam
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - .gitignore
92
+ - .rubocop.yml
93
+ - .ruby-gemset
94
+ - .ruby-version
95
+ - .travis.yml
96
+ - CHANGELOG.md
97
+ - Gemfile
98
+ - LICENSE.txt
99
+ - README.md
100
+ - Rakefile
101
+ - bin/blam
102
+ - blam.gemspec
103
+ - features/default.feature
104
+ - features/support/env.rb
105
+ - lib/blam.rb
106
+ - lib/templates/rspec.tt
107
+ - lib/templates/source.tt
108
+ - lib/templates/test.tt
109
+ homepage: https://github.com/neverstopbuilding/blam
110
+ licenses:
111
+ - MIT
112
+ metadata: {}
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 2.0.3
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: With a single command Blam will create your source file and any test files
133
+ in the right directories based on namespace.
134
+ test_files:
135
+ - features/default.feature
136
+ - features/support/env.rb