bddgen 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ pkg/*
2
+ tmp/*
3
+ doc/*
4
+ *.gem
5
+ .bundle
6
+ .yardoc
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm 1.9.2@bddgen
data/CHANGELOG ADDED
@@ -0,0 +1,3 @@
1
+ # 0.0.1 - November 18, 2010
2
+
3
+ * First version. Supports running `bddgen cucumber` in a fresh clean ruby project.
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in bddgen.gemspec
4
+ gemspec
5
+ gem 'rspec'
data/Gemfile.lock ADDED
@@ -0,0 +1,51 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bddgen (0.1.0)
5
+ thor
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ aruba (0.2.6)
11
+ background_process
12
+ cucumber (~> 0.9.4)
13
+ background_process (1.2)
14
+ bluecloth (2.0.9)
15
+ builder (2.1.2)
16
+ cucumber (0.9.4)
17
+ builder (~> 2.1.2)
18
+ diff-lcs (~> 1.1.2)
19
+ gherkin (~> 2.2.9)
20
+ json (~> 1.4.6)
21
+ term-ansicolor (~> 1.0.5)
22
+ diff-lcs (1.1.2)
23
+ gherkin (2.2.9)
24
+ json (~> 1.4.6)
25
+ term-ansicolor (~> 1.0.5)
26
+ json (1.4.6)
27
+ rake (0.8.7)
28
+ rspec (2.1.0)
29
+ rspec-core (~> 2.1.0)
30
+ rspec-expectations (~> 2.1.0)
31
+ rspec-mocks (~> 2.1.0)
32
+ rspec-core (2.1.0)
33
+ rspec-expectations (2.1.0)
34
+ diff-lcs (~> 1.1.2)
35
+ rspec-mocks (2.1.0)
36
+ term-ansicolor (1.0.5)
37
+ thor (0.14.4)
38
+ yard (0.6.2)
39
+
40
+ PLATFORMS
41
+ ruby
42
+
43
+ DEPENDENCIES
44
+ aruba
45
+ bddgen!
46
+ bluecloth
47
+ cucumber
48
+ rake
49
+ rspec
50
+ thor
51
+ yard
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2010 Justin Blake
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,91 @@
1
+ # BDDGen
2
+
3
+ Generate all the boilerplate for using [Cucumber](http://cukes.info) and
4
+ [RSpec](https://github.com/rspec/rspec) in a new ruby project.
5
+
6
+ Keep in mind this is intended for plain vanilla ruby projects. If you're
7
+ writing a rails app or something, there are probably generators better
8
+ suited for the job.
9
+
10
+ Also keep in mind: **This is so alpha.** Use at your own risk. Until at
11
+ least version 1, you can't use the excuse "bddgen ate my homework!" because
12
+ *I am warning you right now that might happen*.
13
+
14
+ ## Installation
15
+
16
+ The usual:
17
+
18
+ $ gem install bddgen
19
+
20
+ ## Usage
21
+
22
+ In your project's root directory...
23
+
24
+ ### Cucumber
25
+
26
+ $ bddgen cucumber
27
+
28
+ This will create a `features` directory with all the files you need to hit the
29
+ ground running, add the `cucumber` gem to your `Gemfile`, and set up your
30
+ `Rakefile` with the following tasks:
31
+
32
+ rake features # Run Cucumber features
33
+ rake features:pretty # Run Cucumber features with output in pretty format
34
+ rake features:wip # Run @wip (Work In Progress) Cucumber features
35
+
36
+ If you don't already have a `Gemfile` or `Rakefile`, one will be created.
37
+
38
+ ### Rspec
39
+
40
+ $ bddgen rspec
41
+
42
+ This will create a `spec` directory with a `spec_helper.rb`, add the `rspec`
43
+ gem to your `Gemfile`, and set up your `Rakefile` with the following tasks:
44
+
45
+ rake spec # Run specs
46
+ rake spec:doc # Run specs with output in documentation format
47
+
48
+ If you don't already have a `Gemfile` or `Rakefile`, one will be created.
49
+
50
+ ### For added convenience, you can also set up [yard](http://yardoc.org/):
51
+
52
+ $ bddgen yard
53
+
54
+ This will add `doc/*` and `.yardoc` to your `.gitignore`, add the `yard` gem
55
+ to your Gemfile, and set up a `yard` rake task.
56
+
57
+ If you don't already have a `Gemfile`, `Rakefile`, or `.gitignore`, one will
58
+ be created.
59
+
60
+ ### From scratch:
61
+
62
+ Build an entirely new project from scratch with:
63
+
64
+ $ bddgen project name
65
+
66
+ Where `name` is the name of your new project. This will set up a new
67
+ directory with that name containing a `lib` directory skeleton, a
68
+ `.gitignore`, `Gemfile`, `Rakefile`, `CHANGELOG`,
69
+ and a `README.markdown`.
70
+
71
+ You can pass options to generate the project with the boilerplate from the
72
+ other tasks:
73
+
74
+ $ bddgen project name --cucumber --rspec --yard
75
+
76
+ This would basically be the same as:
77
+
78
+ $ bddgen project name
79
+ $ cd name
80
+ $ bddgen cucumber
81
+ $ bddgen rspec
82
+ $ bddgen yard
83
+
84
+ ## TODO
85
+
86
+ * support `bddgen project` options: `--cucumber`, `--rspec`, and `--yard`
87
+ * `bddgen project` should ask if/how to create a `LICENSE` file
88
+ * Add `--mock_framework=mocha` option to rspec generator.
89
+ * Add destroy tasks
90
+ * Add development dependency if a gemspec exists.
91
+ * Don't assume use of bundler...?
data/Rakefile ADDED
@@ -0,0 +1,42 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ require 'bundler/setup'
4
+
5
+ Bundler::GemHelper.install_tasks
6
+
7
+ # Cucumber tasks
8
+ require 'cucumber/rake/task'
9
+ Cucumber::Rake::Task.new(:features) do |features|
10
+ features.cucumber_opts = "features --tags ~@wip --format progress"
11
+ end
12
+ namespace :features do
13
+ Cucumber::Rake::Task.new(:pretty, "Run Cucumber features with output in pretty format") do |features|
14
+ features.cucumber_opts = "features --tags ~@wip --format pretty"
15
+ end
16
+ Cucumber::Rake::Task.new(:wip, "Run @wip (Work In Progress) Cucumber features") do |features|
17
+ features.cucumber_opts = "features --tags @wip --format progress"
18
+ end
19
+ end
20
+
21
+ # Yardoc tasks
22
+ require 'yard'
23
+ YARD::Rake::YardocTask.new do |t|
24
+ t.files = ['lib/**/*.rb', '-', 'CHANGELOG', 'LICENSE']
25
+ t.options = ['--no-private', '--title', 'BDDGen API Documentation']
26
+ end
27
+
28
+ # Rake tasks
29
+ require 'rspec/core/rake_task'
30
+ desc "Run specs"
31
+ RSpec::Core::RakeTask.new(:spec) do |t|
32
+ t.rspec_opts = %w(--color)
33
+ end
34
+ namespace :spec do
35
+ desc "Run specs with output in documentation format"
36
+ RSpec::Core::RakeTask.new(:doc) do |t|
37
+ t.rspec_opts = ["--color", "--format d"]
38
+ end
39
+ end
40
+
41
+ # Default is to run all specs and features
42
+ task :default => [:spec, :features]
data/bddgen.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "bddgen/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "bddgen"
7
+ s.version = BDDGen::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Justin Blake"]
10
+ s.email = ["justin@hentzia.com"]
11
+ s.homepage = "http://rubygems.org/gems/bddgen"
12
+ s.summary = %q{BDD generators for new or existing ruby projects.}
13
+ s.description = %q{Generate a new ruby project using BDD libraries like RSpec and Cucumber, or add them to existing projects.}
14
+ s.rubyforge_project = "bddgen"
15
+
16
+ s.add_dependency "thor"
17
+
18
+ s.add_development_dependency "rake"
19
+ s.add_development_dependency "rspec"
20
+ s.add_development_dependency "cucumber"
21
+ s.add_development_dependency "aruba"
22
+ s.add_development_dependency "yard"
23
+ s.add_development_dependency "bluecloth"
24
+
25
+ s.files = `git ls-files`.split("\n")
26
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
27
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
28
+ s.require_paths = ["lib"]
29
+ end
data/bin/bddgen ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib_dir = File.expand_path("../lib", File.dirname(__FILE__))
4
+ $:.unshift lib_dir unless $:.include?(lib_dir)
5
+
6
+ require 'bddgen'
7
+ BDDGen::App.start
@@ -0,0 +1,66 @@
1
+ Feature: Generate cucumber
2
+ In order to use cucumber in my ruby project
3
+ As a developer
4
+ I want to generate the cucumber boilerplate in my project
5
+
6
+ Scenario: Run `bddgen cucumber` in an empty project
7
+ Given a current working directory named "myproject"
8
+ When I run "bddgen cucumber"
9
+ Then the following files should be created:
10
+ | features/support/env.rb |
11
+ | features/support/helpers.rb |
12
+ | features/step_definitions/myproject_steps.rb |
13
+ | Gemfile |
14
+ | Rakefile |
15
+ And the file "features/support/env.rb" should match the template "features/support/env.rb"
16
+ And the file "features/support/helpers.rb" should contain exactly:
17
+ """
18
+ module Myproject
19
+ module CucumberHelpers
20
+ end
21
+ end
22
+
23
+ World(Myproject::CucumberHelpers)
24
+
25
+ """
26
+ And the file "Gemfile" should contain exactly:
27
+ """
28
+ source 'http://rubygems.org'
29
+
30
+ gem 'rake'
31
+ gem 'cucumber'
32
+
33
+ """
34
+ And the file "Rakefile" should contain the bundler setup
35
+ And the file "Rakefile" should contain the cucumber tasks
36
+ And the exit status should be 0
37
+
38
+ Scenario: Run `bddgen cucumber` in a project with an existing Gemfile
39
+ Given a current working directory named "myproject"
40
+ And a file named "Gemfile" with:
41
+ """
42
+ source 'http://custom.com'
43
+ gem 'special'
44
+ """
45
+ When I run "bddgen cucumber"
46
+ Then the file "Gemfile" should contain exactly:
47
+ """
48
+ source 'http://custom.com'
49
+ gem 'special'
50
+ gem 'cucumber'
51
+
52
+ """
53
+ And the exit status should be 0
54
+
55
+ Scenario: Run `bddgen cucumber` in a project with an existing Rakefile
56
+ Given a current working directory named "myproject"
57
+ And a file named "Rakefile" with:
58
+ """
59
+ require 'custom'
60
+ require 'special'
61
+ """
62
+ When I run "bddgen cucumber"
63
+ Then the file "Rakefile" should contain "require 'custom'"
64
+ And the file "Rakefile" should contain "require 'special'"
65
+ And the file "Rakefile" should contain the cucumber tasks
66
+ And the exit status should be 0
@@ -0,0 +1,76 @@
1
+ Feature: Generate project
2
+ In order to quickly bootstrap a new ruby project
3
+ As a developer
4
+ I want to generate a new ruby project with all the boilerplate I need
5
+
6
+ Scenario: Run `bddgen project myproject`
7
+ When I run "bddgen project myproject"
8
+ Then the output should say the following files were created:
9
+ | myproject |
10
+ | .gitignore |
11
+ | CHANGELOG |
12
+ | Gemfile |
13
+ | lib/myproject.rb |
14
+ | Rakefile |
15
+ | README.markdown |
16
+ And the following files should exist:
17
+ | myproject/.gitignore |
18
+ | myproject/CHANGELOG |
19
+ | myproject/Gemfile |
20
+ | myproject/lib/myproject.rb |
21
+ | myproject/Rakefile |
22
+ | myproject/README.markdown |
23
+ And a directory named "myproject/lib/myproject" should exist
24
+ And the file "myproject/lib/myproject.rb" should contain exactly:
25
+ """
26
+ module Myproject
27
+ end
28
+
29
+ """
30
+ And the exit status should be 0
31
+
32
+ Scenario: Run `bddgen project myproject --cucumber`
33
+ When I run "bddgen project myproject --cucumber"
34
+ Then the output should say the following files were created:
35
+ | features/step_definitions/myproject_steps.rb |
36
+ | features/support/env.rb |
37
+ | features/support/helpers.rb |
38
+ And the following files should exist:
39
+ | myproject/features/step_definitions/myproject_steps.rb |
40
+ | myproject/features/support/env.rb |
41
+ | myproject/features/support/helpers.rb |
42
+ And the file "myproject/Gemfile" should contain "gem 'cucumber'"
43
+ And the file "myproject/Rakefile" should contain the cucumber tasks
44
+
45
+ Scenario: Run `bddgen project myproject --rspec`
46
+ When I run "bddgen project myproject --rspec"
47
+ Then the output should say the following files were created:
48
+ | spec/spec_helper.rb |
49
+ And the following files should exist:
50
+ | myproject/spec/spec_helper.rb |
51
+ And the file "myproject/Gemfile" should contain "gem 'rspec'"
52
+ And the file "myproject/Rakefile" should contain the rspec tasks
53
+
54
+ Scenario: Run `bddgen project myproject --yard`
55
+ When I run "bddgen project myproject --yard"
56
+ Then the file "myproject/Gemfile" should contain "gem 'yard'"
57
+ And the file "myproject/Rakefile" should contain the yard task for "myproject"
58
+
59
+ Scenario: Run `bddgen project myproject --cucumber --rspec --yard`
60
+ When I run "bddgen project myproject --cucumber --rspec --yard"
61
+ Then the output should say the following files were created:
62
+ | features/step_definitions/myproject_steps.rb |
63
+ | features/support/env.rb |
64
+ | features/support/helpers.rb |
65
+ | spec/spec_helper.rb |
66
+ And the following files should exist:
67
+ | myproject/features/step_definitions/myproject_steps.rb |
68
+ | myproject/features/support/env.rb |
69
+ | myproject/features/support/helpers.rb |
70
+ | myproject/spec/spec_helper.rb |
71
+ And the file "myproject/Gemfile" should contain "gem 'cucumber'"
72
+ And the file "myproject/Gemfile" should contain "gem 'rspec'"
73
+ And the file "myproject/Gemfile" should contain "gem 'yard'"
74
+ And the file "myproject/Rakefile" should contain the cucumber tasks
75
+ And the file "myproject/Rakefile" should contain the rspec tasks
76
+ And the file "myproject/Rakefile" should contain the yard task for "myproject"
@@ -0,0 +1,54 @@
1
+ Feature: Generate rspec
2
+ In order to use rspec in my ruby project
3
+ As a developer
4
+ I want to generate the rspec boilerplate in my project
5
+
6
+ Scenario: Run `bddgen rspec` in an empty project
7
+ Given a current working directory named "myproject"
8
+ When I run "bddgen rspec"
9
+ Then the following files should be created:
10
+ | spec/spec_helper.rb |
11
+ | Gemfile |
12
+ | Rakefile |
13
+ And the file "spec/spec_helper.rb" should match the template "spec/spec_helper.rb"
14
+ And the file "Gemfile" should contain exactly:
15
+ """
16
+ source 'http://rubygems.org'
17
+
18
+ gem 'rake'
19
+ gem 'rspec'
20
+
21
+ """
22
+ And the file "Rakefile" should contain the bundler setup
23
+ And the file "Rakefile" should contain the rspec tasks
24
+ And the exit status should be 0
25
+
26
+ Scenario: Run `bddgen rspec` in a project with an existing Gemfile
27
+ Given a current working directory named "myproject"
28
+ And a file named "Gemfile" with:
29
+ """
30
+ source 'http://custom.com'
31
+ gem 'special'
32
+ """
33
+ When I run "bddgen rspec"
34
+ Then the file "Gemfile" should contain exactly:
35
+ """
36
+ source 'http://custom.com'
37
+ gem 'special'
38
+ gem 'rspec'
39
+
40
+ """
41
+ And the exit status should be 0
42
+
43
+ Scenario: Run `bddgen rspec` in a project with an existing Rakefile
44
+ Given a current working directory named "myproject"
45
+ And a file named "Rakefile" with:
46
+ """
47
+ require 'custom'
48
+ require 'special'
49
+ """
50
+ When I run "bddgen rspec"
51
+ Then the file "Rakefile" should contain "require 'custom'"
52
+ And the file "Rakefile" should contain "require 'special'"
53
+ And the file "Rakefile" should contain the rspec tasks
54
+ And the exit status should be 0
@@ -0,0 +1,69 @@
1
+ Feature: Generate yard
2
+ In order to use yard in my ruby project
3
+ As a developer
4
+ I want to generate the yard boilerplate
5
+
6
+ Background:
7
+ Given a current working directory named "myproject"
8
+
9
+ Scenario: Run `bddgen yard` in an empty project
10
+ When I run "bddgen yard"
11
+ Then the following files should be created:
12
+ | .gitignore |
13
+ And the file ".gitignore" should contain "doc/*"
14
+ And the file ".gitignore" should contain ".yardoc"
15
+ And the file "Gemfile" should contain exactly:
16
+ """
17
+ source 'http://rubygems.org'
18
+
19
+ gem 'rake'
20
+ gem 'yard'
21
+
22
+ """
23
+ And the file "Rakefile" should contain the bundler setup
24
+ And the file "Rakefile" should contain the yard task
25
+ And the exit status should be 0
26
+
27
+ Scenario: Run `bddgen yard` in a project with an existing .gitignore
28
+ Given a file named ".gitignore" with:
29
+ """
30
+ pkg/*
31
+ tmp/*
32
+ """
33
+ When I run "bddgen yard"
34
+ Then the file ".gitignore" should contain exactly:
35
+ """
36
+ pkg/*
37
+ tmp/*
38
+ doc/*
39
+ .yardoc
40
+
41
+ """
42
+
43
+ Scenario: Run `bddgen yard` in a project with an existing Gemfile
44
+ Given a file named "Gemfile" with:
45
+ """
46
+ source 'http://custom.com'
47
+ gem 'special'
48
+ """
49
+ When I run "bddgen yard"
50
+ Then the file "Gemfile" should contain exactly:
51
+ """
52
+ source 'http://custom.com'
53
+ gem 'special'
54
+ gem 'yard'
55
+
56
+ """
57
+ And the exit status should be 0
58
+
59
+ Scenario: Run `bddgen yard` in a project with an existing Rakefile
60
+ Given a file named "Rakefile" with:
61
+ """
62
+ require 'custom'
63
+ require 'special'
64
+ """
65
+ When I run "bddgen yard"
66
+ Then the file "Rakefile" should contain "require 'custom'"
67
+ And the file "Rakefile" should contain "require 'special'"
68
+ And the file "Rakefile" should contain the yard task
69
+ And the exit status should be 0
@@ -0,0 +1,49 @@
1
+ Given /^a current working directory named "([^"]*)"$/ do |directory|
2
+ @working_dir = directory
3
+ Given "a directory named \"#{directory}\""
4
+ Given "I cd to \"#{directory}\""
5
+ end
6
+
7
+ Then /^the output should say the following files were created:$/ do |table|
8
+ table.raw.each do |row|
9
+ row.each do |col|
10
+ # can't use the aruba-provided step here because of a regex gotcha
11
+ all_output.should =~ /create.+#{Regexp.escape(col)}/
12
+ end
13
+ end
14
+ end
15
+
16
+ Then /^the following files should be created:$/ do |table|
17
+ Then "the output should say the following files were created:", table
18
+ Then "the following files should exist:", table
19
+ end
20
+
21
+ Then /^the file "([^"]*)" should contain the cucumber tasks$/ do |file|
22
+ read_temp_file(file).should include(BDDGen::Tasks.cucumber)
23
+ end
24
+
25
+ Then /^the file "([^"]*)" should contain the rspec tasks$/ do |file|
26
+ read_temp_file(file).should include(BDDGen::Tasks.rspec)
27
+ end
28
+
29
+ Then /^the file "([^"]*)" should contain the yard task$/ do |file|
30
+ read_temp_file(file).should include(BDDGen::Tasks.yard(@working_dir))
31
+ end
32
+
33
+ Then /^the file "([^"]*)" should contain the yard task for "([^"]*)"$/ do |file, working_dir|
34
+ read_temp_file(file).should include(BDDGen::Tasks.yard(working_dir))
35
+ end
36
+
37
+ Then /^the file "([^"]*)" should contain the bundler setup$/ do |file|
38
+ Then "the file \"#{file}\" should contain \"require 'rubygems'\""
39
+ Then "the file \"#{file}\" should contain \"require 'bundler'\""
40
+ Then "the file \"#{file}\" should contain \"require 'bundler/setup'\""
41
+ end
42
+
43
+ Then /^the file "([^"]*)" should match the template "([^"]*)"$/ do |file, template|
44
+ file_contents = read_temp_file(file)
45
+ template = File.join(template_dir, template)
46
+ File.should exist(template)
47
+ template_contents = File.read(template)
48
+ file_contents.strip.should == template_contents.strip
49
+ end
@@ -0,0 +1,6 @@
1
+ require "rubygems"
2
+ require "bundler/setup"
3
+
4
+ require "aruba"
5
+
6
+ require 'bddgen'
@@ -0,0 +1,21 @@
1
+ module BDDGen
2
+ module CucumberHelpers
3
+ def tmp_dir
4
+ File.expand_path("../../tmp/aruba", File.dirname(__FILE__))
5
+ end
6
+
7
+ def template_dir
8
+ BDDGen::App.source_root
9
+ end
10
+
11
+ def read_temp_file(file)
12
+ if @working_dir
13
+ File.read(File.join(tmp_dir, @working_dir, file))
14
+ else
15
+ File.read(File.join(tmp_dir, file))
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ World(BDDGen::CucumberHelpers)
data/lib/bddgen/app.rb ADDED
@@ -0,0 +1,119 @@
1
+ require 'thor'
2
+
3
+ module BDDGen
4
+ class App < Thor
5
+ include Thor::Actions
6
+
7
+ def self.source_root
8
+ File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'templates'))
9
+ end
10
+
11
+ desc "cucumber", "Generate boilerplate for cucumber"
12
+ def cucumber
13
+ init_gemfile
14
+ append_gem 'cucumber'
15
+
16
+ init_rakefile
17
+ append_task BDDGen::Tasks.cucumber
18
+
19
+ add_file "features/step_definitions/#{project_name}_steps.rb"
20
+ copy_file "features/support/env.rb"
21
+ template "features/support/helpers.erb", "features/support/helpers.rb"
22
+ end
23
+
24
+ desc "rspec", "Generate boilerplate for rspec"
25
+ def rspec
26
+ init_gemfile
27
+ append_gem 'rspec'
28
+
29
+ init_rakefile
30
+ append_task BDDGen::Tasks.rspec
31
+
32
+ copy_file "spec/spec_helper.rb"
33
+ end
34
+
35
+ desc "yard", "Generate boilerplate for yard"
36
+ def yard
37
+ init_gemfile
38
+ append_gem 'yard'
39
+
40
+ init_rakefile
41
+ append_task BDDGen::Tasks.yard(project_name)
42
+
43
+ init_gitignore
44
+ append_file ".gitignore", "doc/*\n"
45
+ append_file ".gitignore", ".yardoc\n"
46
+ end
47
+
48
+ desc "project name", "Generate a new ruby project named [name]"
49
+ method_options :cucumber => :boolean, :rspec => :boolean, :yard => :boolean
50
+ def project(name)
51
+ empty_directory name
52
+ self.destination_root = name
53
+
54
+ empty_directory "lib/#{name}"
55
+
56
+ init_gitignore
57
+ init_gemfile
58
+ init_rakefile
59
+
60
+ add_file "CHANGELOG"
61
+ add_file "README.markdown"
62
+
63
+ template "lib/project.erb", "lib/#{name}.rb"
64
+
65
+ cucumber if options.cucumber?
66
+ rspec if options.rspec?
67
+ yard if options.yard?
68
+ end
69
+
70
+ private
71
+
72
+ def project_name
73
+ destination_root.split(/\/|\\/).last
74
+ end
75
+
76
+ def init_gemfile
77
+ unless destination_file_exists?("Gemfile")
78
+ add_file "Gemfile"
79
+ append_file "Gemfile" do
80
+ "source 'http://rubygems.org'\n\n" +
81
+ "gem 'rake'\n"
82
+ end
83
+ end
84
+ end
85
+
86
+ def init_rakefile
87
+ unless destination_file_exists?("Rakefile")
88
+ add_file "Rakefile"
89
+ append_file "Rakefile" do
90
+ "require 'rubygems'\n" +
91
+ "require 'bundler'\n" +
92
+ "require 'bundler/setup'\n\n"
93
+ end
94
+ end
95
+ end
96
+
97
+ def init_gitignore
98
+ add_file ".gitignore" unless destination_file_exists?(".gitignore")
99
+ ensure_eof_newline(".gitignore")
100
+ end
101
+
102
+ def destination_file_exists?(filename)
103
+ File.exist?(File.join(destination_root, filename))
104
+ end
105
+
106
+ def append_gem(gem_name)
107
+ ensure_eof_newline("Gemfile")
108
+ append_file "Gemfile", "gem '#{gem_name}'\n"
109
+ end
110
+
111
+ def append_task(the_task)
112
+ append_file "Rakefile", "\n\n#{the_task}\n"
113
+ end
114
+
115
+ def ensure_eof_newline(filename)
116
+ gsub_file(filename, /([^\n])\z/, "\\1\n")
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,13 @@
1
+ module BDDGen
2
+ module Extensions
3
+ module String
4
+ # This is a really simple stupid method that can't handle much besides
5
+ # strings that have spaces, dashes, or underscores.
6
+ def camelize
7
+ self.capitalize.gsub(/[ _\-]+([a-z])?/) { $1.upcase }
8
+ end
9
+ end
10
+ end
11
+ end
12
+
13
+ String.send(:include, BDDGen::Extensions::String)
@@ -0,0 +1,22 @@
1
+ module BDDGen
2
+ class Tasks
3
+ def self.cucumber
4
+ @cucumber_tasks ||= read_task_file('cucumber.rb')
5
+ end
6
+
7
+ def self.rspec
8
+ @rspec_tasks ||= read_task_file('rspec.rb')
9
+ end
10
+
11
+ def self.yard(project_name)
12
+ @yard_tasks ||= read_task_file('yard.rb').gsub(
13
+ '{{project_name}}', project_name
14
+ )
15
+ end
16
+
17
+ private
18
+ def self.read_task_file(filename)
19
+ File.read(File.join(BDDGen::App.source_root, 'rake_tasks', filename))
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module BDDGen
2
+ VERSION = "0.1.0"
3
+ end
data/lib/bddgen.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'bddgen/extensions/string'
2
+
3
+ module BDDGen
4
+ autoload :App, "bddgen/app"
5
+ autoload :Tasks, "bddgen/tasks"
6
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe BDDGen::Extensions::String do
4
+ it "adds a #camelize method to all strings" do
5
+ "my string".methods.should include(:camelize)
6
+ "your string".methods.should include(:camelize)
7
+ "our string".methods.should include(:camelize)
8
+ end
9
+
10
+ describe '#camelize' do
11
+ it "returns a capitilzed version of a simple string" do
12
+ "yo".camelize.should == "Yo"
13
+ "skullcrusher".camelize.should == "Skullcrusher"
14
+ end
15
+
16
+ it "returns a camel-cased version of an underscored string" do
17
+ "voices_that_control_me".camelize.should == "VoicesThatControlMe"
18
+ "fashion_police".camelize.should == "FashionPolice"
19
+ end
20
+
21
+ it "returns a camel-cased version of a dashed string" do
22
+ "use-passenger".camelize.should == "UsePassenger"
23
+ "send-my-regards".camelize.should == "SendMyRegards"
24
+ end
25
+
26
+ it "returns a camel-cased version of a string with spaces" do
27
+ "the youth fountain".camelize.should == "TheYouthFountain"
28
+ "it hurts".camelize.should == "ItHurts"
29
+ end
30
+
31
+ it "returns a camel-cased version of a string with underscores, dashes, and spaces" do
32
+ "shuffled up-sixth_street".camelize.should == "ShuffledUpSixthStreet"
33
+ end
34
+
35
+ it "doesn't choke on multiple sequential dashes, spaces, or underscores" do
36
+ " they___come-_ out to__-smoke".camelize.should == "TheyComeOutToSmoke"
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,9 @@
1
+ require "rubygems"
2
+ require "bundler/setup"
3
+
4
+ require 'rspec'
5
+ RSpec.configure do |config|
6
+ config.fail_fast = true
7
+ end
8
+
9
+ require 'bddgen'
@@ -0,0 +1,2 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
@@ -0,0 +1,6 @@
1
+ module <%= project_name.camelize %>
2
+ module CucumberHelpers
3
+ end
4
+ end
5
+
6
+ World(<%= project_name.camelize %>::CucumberHelpers)
@@ -0,0 +1,2 @@
1
+ module <%= project_name.camelize %>
2
+ end
@@ -0,0 +1,13 @@
1
+ require 'cucumber/rake/task'
2
+ Cucumber::Rake::Task.new(:features) do |features|
3
+ features.cucumber_opts = "features --tags ~@wip --format progress"
4
+ end
5
+ namespace :features do
6
+ Cucumber::Rake::Task.new(:pretty, "Run Cucumber features with output in pretty format") do |features|
7
+ features.cucumber_opts = "features --tags ~@wip --format pretty"
8
+ end
9
+ Cucumber::Rake::Task.new(:wip, "Run @wip (Work In Progress) Cucumber features") do |features|
10
+ features.cucumber_opts = "features --tags @wip --format progress"
11
+ end
12
+ end
13
+
@@ -0,0 +1,12 @@
1
+ require 'rspec/core/rake_task'
2
+ desc "Run specs"
3
+ RSpec::Core::RakeTask.new(:spec) do |t|
4
+ t.rspec_opts = %w(--color)
5
+ end
6
+ namespace :spec do
7
+ desc "Run specs with output in documentation format"
8
+ RSpec::Core::RakeTask.new(:doc) do |t|
9
+ t.rspec_opts = ["--color", "--format d"]
10
+ end
11
+ end
12
+
@@ -0,0 +1,5 @@
1
+ require 'yard'
2
+ YARD::Rake::YardocTask.new do |t|
3
+ t.files = ['lib/**/*.rb', '-', 'CHANGELOG', 'LICENSE']
4
+ t.options = ['--no-private', '--title', '{{project_name}} API Documentation']
5
+ end
@@ -0,0 +1,8 @@
1
+ require "rubygems"
2
+ require "bundler/setup"
3
+
4
+ require 'rspec'
5
+
6
+ RSpec.configure do |config|
7
+ config.fail_fast = true
8
+ end
metadata ADDED
@@ -0,0 +1,195 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bddgen
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Justin Blake
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-11-23 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: thor
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ prerelease: false
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: rake
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ segments:
41
+ - 0
42
+ version: "0"
43
+ type: :development
44
+ prerelease: false
45
+ version_requirements: *id002
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: &id003 !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ segments:
54
+ - 0
55
+ version: "0"
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *id003
59
+ - !ruby/object:Gem::Dependency
60
+ name: cucumber
61
+ requirement: &id004 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ segments:
67
+ - 0
68
+ version: "0"
69
+ type: :development
70
+ prerelease: false
71
+ version_requirements: *id004
72
+ - !ruby/object:Gem::Dependency
73
+ name: aruba
74
+ requirement: &id005 !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: *id005
85
+ - !ruby/object:Gem::Dependency
86
+ name: yard
87
+ requirement: &id006 !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ segments:
93
+ - 0
94
+ version: "0"
95
+ type: :development
96
+ prerelease: false
97
+ version_requirements: *id006
98
+ - !ruby/object:Gem::Dependency
99
+ name: bluecloth
100
+ requirement: &id007 !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ segments:
106
+ - 0
107
+ version: "0"
108
+ type: :development
109
+ prerelease: false
110
+ version_requirements: *id007
111
+ description: Generate a new ruby project using BDD libraries like RSpec and Cucumber, or add them to existing projects.
112
+ email:
113
+ - justin@hentzia.com
114
+ executables:
115
+ - bddgen
116
+ extensions: []
117
+
118
+ extra_rdoc_files: []
119
+
120
+ files:
121
+ - .gitignore
122
+ - .rvmrc
123
+ - CHANGELOG
124
+ - Gemfile
125
+ - Gemfile.lock
126
+ - LICENSE
127
+ - README.markdown
128
+ - Rakefile
129
+ - bddgen.gemspec
130
+ - bin/bddgen
131
+ - features/generate_cucumber.feature
132
+ - features/generate_project.feature
133
+ - features/generate_rspec.feature
134
+ - features/generate_yard.feature
135
+ - features/step_definitions/bddgen_steps.rb
136
+ - features/support/env.rb
137
+ - features/support/helpers.rb
138
+ - lib/bddgen.rb
139
+ - lib/bddgen/app.rb
140
+ - lib/bddgen/extensions/string.rb
141
+ - lib/bddgen/tasks.rb
142
+ - lib/bddgen/version.rb
143
+ - spec/bddgen/extensions/string_spec.rb
144
+ - spec/spec_helper.rb
145
+ - templates/features/support/env.rb
146
+ - templates/features/support/helpers.erb
147
+ - templates/lib/project.erb
148
+ - templates/rake_tasks/cucumber.rb
149
+ - templates/rake_tasks/rspec.rb
150
+ - templates/rake_tasks/yard.rb
151
+ - templates/spec/spec_helper.rb
152
+ has_rdoc: true
153
+ homepage: http://rubygems.org/gems/bddgen
154
+ licenses: []
155
+
156
+ post_install_message:
157
+ rdoc_options: []
158
+
159
+ require_paths:
160
+ - lib
161
+ required_ruby_version: !ruby/object:Gem::Requirement
162
+ none: false
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ hash: 3661949598000053515
167
+ segments:
168
+ - 0
169
+ version: "0"
170
+ required_rubygems_version: !ruby/object:Gem::Requirement
171
+ none: false
172
+ requirements:
173
+ - - ">="
174
+ - !ruby/object:Gem::Version
175
+ hash: 3661949598000053515
176
+ segments:
177
+ - 0
178
+ version: "0"
179
+ requirements: []
180
+
181
+ rubyforge_project: bddgen
182
+ rubygems_version: 1.3.7
183
+ signing_key:
184
+ specification_version: 3
185
+ summary: BDD generators for new or existing ruby projects.
186
+ test_files:
187
+ - features/generate_cucumber.feature
188
+ - features/generate_project.feature
189
+ - features/generate_rspec.feature
190
+ - features/generate_yard.feature
191
+ - features/step_definitions/bddgen_steps.rb
192
+ - features/support/env.rb
193
+ - features/support/helpers.rb
194
+ - spec/bddgen/extensions/string_spec.rb
195
+ - spec/spec_helper.rb