cpb-generators 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9ba26f6029d31aca25618826901c9ab020f141db
4
+ data.tar.gz: 6f2f126251b3228bdbbe72cc4ef5b357a367c1cd
5
+ SHA512:
6
+ metadata.gz: ff877cbe9d783993329f140474893bfc00d99a2d0069109da0bd8f845a40e7161d384c58d01cc349ff8eabda3c7f6852887962bde507efeba86c0ed257da0348
7
+ data.tar.gz: 21607da2b95383f369e1fc4990f8cc4e8e6e53ff9dcbe3e95d80c2a490184b2b2dd380d3de19732622854acc326bcd4012aed6faea766354f2035d52048f49f1
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cpb-generators.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem "aruba", github: 'cpb/aruba', branch: 'reporting_argument_error'
8
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Caleb Buxton
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,38 @@
1
+ # Cpb::Generators
2
+
3
+ My idiomatic Ruby practices, encoded.
4
+ Includes generators for common workflow patterns.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ group :development do
11
+ gem 'cpb-generators'
12
+ end
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ ## Usage
19
+
20
+ $ bundle exec cpb entity namespace/class_name
21
+ create lib/namespace/class_name.rb
22
+ create spec/namespace/class_name_spec.rb
23
+
24
+ $ bundle exec rspec spec/namespace/class_name_spec.rb
25
+ *
26
+
27
+ Pending:
28
+ Namespace::ClassName Define what Namespace::ClassName does
29
+ # No reason given
30
+ # ./spec/namespace/class_name_spec.rb:6
31
+
32
+ ## Contributing
33
+
34
+ 1. Fork it
35
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
36
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
37
+ 4. Push to the branch (`git push origin my-new-feature`)
38
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ require 'cucumber/rake/task'
7
+ Cucumber::Rake::Task.new(:features)
8
+
9
+ Cucumber::Rake::Task.new(:run_aruba_features, nil) do |t|
10
+ t.cucumber_opts = "ARUBA_REPORT_DIR=doc --format progress"
11
+ end
12
+
13
+ task :check_for_pygments do
14
+ unless system("pygmentize", [:err,:out]=>"/dev/null")
15
+ raise "You're missing pygmentize, try:\n sudo easy_install Pygments"
16
+ end
17
+ end
18
+
19
+ desc "Run Cucumber features generating Aruba Report using Pygments"
20
+ task :aruba_features => [:check_for_pygments, :run_aruba_features]
21
+ task :default => [:spec,:features]
data/bin/cpb ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'cpb/generators'
4
+
5
+ Cpb::Generators::Runner.start
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cpb/generators/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cpb-generators"
8
+ spec.version = Cpb::Generators::VERSION
9
+ spec.authors = ["Caleb Buxton"]
10
+ spec.email = ["me@cpb.ca"]
11
+ spec.description = %q{My idiomatic Ruby practices, encoded}
12
+ spec.summary = %q{Includes generators for common workflow patterns}
13
+ spec.homepage = ""
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_dependency "thor"
22
+ spec.add_dependency "rspec"
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "cucumber"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "pry"
27
+ end
@@ -0,0 +1,25 @@
1
+ Feature: I can install cpb-generators and generate files
2
+
3
+ @disable-bundler
4
+ Scenario: Installation in the development group
5
+ Given a file named "Gemfile" with:
6
+ """
7
+ group :development do
8
+ gem 'cpb-generators', path: '../..'
9
+ end
10
+ """
11
+ And I run `bundle install`
12
+ When I run `bundle exec cpb entity namespace/new_name`
13
+ Then a file named "lib/namespace/new_name.rb" should exist
14
+ And a file named "spec/namespace/new_name_spec.rb" should exist
15
+
16
+ Scenario: Usage post installation
17
+ Given a Gemfile setup with:
18
+ """
19
+ group :development do
20
+ gem 'cpb-generators', path: '../..'
21
+ end
22
+ """
23
+ And I run `bundle exec cpb entity namespace/class_name`
24
+ When I run `bundle exec rspec`
25
+ Then the output should contain "pending"
@@ -0,0 +1,5 @@
1
+ Given(/^a Gemfile setup with:$/) do |file_content|
2
+ unset_bundler_env_vars
3
+ write_file("Gemfile", file_content)
4
+ run_simple(unescape("bundle install"), false)
5
+ end
@@ -0,0 +1 @@
1
+ require 'aruba/cucumber'
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ require '<%= class_path(name) %>'
4
+
5
+ describe <%= described_class(name) %> do
6
+ pending "Define what #{described_class} does"
7
+ end
@@ -0,0 +1,67 @@
1
+ require 'thor/group'
2
+
3
+ module Cpb
4
+ module Generators
5
+ class ClassGenerator < Thor::Group
6
+ include Thor::Actions
7
+
8
+ argument :name
9
+
10
+ source_root File.expand_path("class_generator",File.dirname(__FILE__))
11
+ def create_class
12
+ create_file "lib/#{class_path(name)}.rb" do
13
+ verbose_namespace_definition(name)
14
+ end
15
+ end
16
+
17
+ def create_spec
18
+ template "spec.rb.tt", "spec/#{class_path(name)}_spec.rb"
19
+ end
20
+
21
+ def create_spec_helper
22
+ create_file "spec/spec_helper.rb" do
23
+ "$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)"
24
+ end
25
+ end
26
+
27
+ private
28
+ def class_path(name)
29
+ @class_path ||= if name =~ /[A-Z]/
30
+ name.gsub(/::/, '/').
31
+ gsub!(/(.)([A-Z])/,'\1_\2').
32
+ downcase
33
+ else
34
+ name
35
+ end
36
+ end
37
+
38
+ def described_class(name)
39
+ @described_class ||= name.split(/[\/-]/).map do |frag|
40
+ frag.split('_').map(&:capitalize).join("")
41
+ end.join("::")
42
+ end
43
+
44
+ def verbose_namespace_definition(name)
45
+ first_part, parts = described_class(name).split("::").reverse
46
+
47
+ if parts
48
+ parts = Array(parts)
49
+ i = parts.length
50
+ parts.inject(lambda { "#{tabs(parts.length)}class #{first_part}\n#{tabs(parts.length)}end\n" }) do |memo, namespace|
51
+ lambda do
52
+ "#{tabs(i-=1)}module #{namespace}\n" +
53
+ memo.call +
54
+ "#{tabs(i)}end\n"
55
+ end
56
+ end.call
57
+ else
58
+ "class #{first_part}\nend"
59
+ end
60
+ end
61
+
62
+ def tabs(i)
63
+ " "*i
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,5 @@
1
+ module Cpb
2
+ module Generators
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,12 @@
1
+ require "cpb/generators/version"
2
+ require "thor"
3
+
4
+ require 'cpb/generators/class_generator'
5
+
6
+ module Cpb
7
+ module Generators
8
+ class Runner < Thor
9
+ register Cpb::Generators::ClassGenerator, "entity", "entity [class_name]", "Generates a class and spec"
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ require 'cpb/generators/class_generator'
4
+
5
+ describe Cpb::Generators::ClassGenerator do
6
+ destination File.expand_path("../../../../tmp/class_artifacts",__FILE__)
7
+
8
+ before { prepare_destination }
9
+
10
+ it 'runs both the class and spec tasks' do
11
+ gen = generator %w(posts)
12
+ gen.should_receive :create_class
13
+ gen.should_receive :create_spec
14
+ capture(:stdout) { gen.invoke_all }
15
+ end
16
+
17
+ describe 'the generated files' do
18
+ before do
19
+ run_generator %w(posts)
20
+ end
21
+
22
+ describe 'the spec' do
23
+ subject { file('spec/posts_spec.rb') }
24
+
25
+ it { should exist }
26
+ it { should contain(/require 'spec_helper'/) }
27
+ it { should contain(/describe Posts/) }
28
+ end
29
+
30
+ describe 'the implementation' do
31
+ subject { file('lib/posts.rb') }
32
+
33
+ it { should exist }
34
+ it { should contain(/class Posts/) }
35
+ end
36
+ end
37
+ end
38
+
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Cpb::Generators do
4
+ it 'should have a version number' do
5
+ Cpb::Generators::VERSION.should_not be_nil
6
+ end
7
+ end
@@ -0,0 +1,19 @@
1
+ RSpec::Matchers.define :contain do |expected_content|
2
+ match do |file_path|
3
+ @actual_contents = File.new(file_path).read
4
+ case expected_content
5
+ when String
6
+ @actual_contents.include? expected_content
7
+ when Regexp
8
+ @actual_contents =~ expected_content
9
+ end
10
+ end
11
+
12
+ failure_message_for_should do |file_path|
13
+ "expected the file #{file_path} to contain #{expected_content.inspect} but it contained #{@actual_contents.inspect}"
14
+ end
15
+
16
+ failure_message_for_should_not do |file_path|
17
+ "expected the file #{file_path} to not contain #{expected_content.inspect} but it did"
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ RSpec::Matchers.define :exist do
2
+ match do |file_path|
3
+ File.exists?(file_path)
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'cpb/generators'
3
+
4
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
5
+ Dir["#{File.dirname(__FILE__)}/matchers/**/*.rb"].each {|f| require f}
6
+
7
+ RSpec.configure do |config|
8
+ config.extend(Helpers::ClassMethods)
9
+ config.include(Helpers::InstanceMethods)
10
+ end
@@ -0,0 +1,43 @@
1
+ module Helpers
2
+
3
+ module ClassMethods
4
+ def destination(new_destination)
5
+ let(:destination_root) { new_destination }
6
+ end
7
+ end
8
+
9
+ module InstanceMethods
10
+ def capture(stream,&block)
11
+ capturing = StringIO.new
12
+
13
+ case stream
14
+ when :stdout
15
+ $stdout = capturing
16
+ end
17
+
18
+ yield
19
+ capturing
20
+ ensure
21
+ $stdout = STDOUT
22
+ end
23
+
24
+ def prepare_destination
25
+ FileUtils.rm_rf destination_root
26
+ FileUtils.mkdir_p destination_root
27
+ end
28
+
29
+ def generator(arguments, options={}, config={})
30
+ @generator ||= described_class.new(arguments, options, {destination_root: destination_root}.merge(config))
31
+ end
32
+
33
+ def run_generator(arguments, options={}, config={})
34
+ capture(:stdout) {
35
+ generator(arguments,options,config).invoke_all
36
+ }
37
+ end
38
+
39
+ def file(relative)
40
+ File.expand_path(relative, destination_root)
41
+ end
42
+ end
43
+ end
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cpb-generators
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Caleb Buxton
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
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: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: cucumber
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: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: My idiomatic Ruby practices, encoded
98
+ email:
99
+ - me@cpb.ca
100
+ executables:
101
+ - cpb
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - .gitignore
106
+ - .rspec
107
+ - .travis.yml
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/cpb
113
+ - cpb-generators.gemspec
114
+ - features/readme.feature
115
+ - features/step_definitions/readme_steps.rb
116
+ - features/support/env.rb
117
+ - lib/cpb/generators.rb
118
+ - lib/cpb/generators/class_generator.rb
119
+ - lib/cpb/generators/class_generator/spec.rb.tt
120
+ - lib/cpb/generators/version.rb
121
+ - spec/cpb/generators/class_generator_spec.rb
122
+ - spec/cpb/generators_spec.rb
123
+ - spec/matchers/contain.rb
124
+ - spec/matchers/exist.rb
125
+ - spec/spec_helper.rb
126
+ - spec/support/helpers.rb
127
+ homepage: ''
128
+ licenses:
129
+ - MIT
130
+ metadata: {}
131
+ post_install_message:
132
+ rdoc_options: []
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - '>='
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ requirements: []
146
+ rubyforge_project:
147
+ rubygems_version: 2.0.3
148
+ signing_key:
149
+ specification_version: 4
150
+ summary: Includes generators for common workflow patterns
151
+ test_files:
152
+ - features/readme.feature
153
+ - features/step_definitions/readme_steps.rb
154
+ - features/support/env.rb
155
+ - spec/cpb/generators/class_generator_spec.rb
156
+ - spec/cpb/generators_spec.rb
157
+ - spec/matchers/contain.rb
158
+ - spec/matchers/exist.rb
159
+ - spec/spec_helper.rb
160
+ - spec/support/helpers.rb