dummier 0.1.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ .bundle
3
+ .DS_Store
4
+ Gemfile.lock
5
+ pkg/*
6
+ test/dummy
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "http://rubygems.org"
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ Redistribution and use in source and binary forms, with or without modification,
2
+ are permitted provided that the following conditions are met:
3
+
4
+ * Redistributions of source code must retain the above copyright notice,
5
+ this list of conditions and the following disclaimer.
6
+ * Redistributions in binary form must reproduce the above copyright notice,
7
+ this list of conditions and the following disclaimer in the documentation
8
+ and/or other materials provided with the distribution.
9
+ * Neither the name of the Rails Dog LLC nor the names of its
10
+ contributors may be used to endorse or promote products derived from this
11
+ software without specific prior written permission.
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
14
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
15
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
16
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,70 @@
1
+ Dummier
2
+ =======
3
+
4
+ **Under construction**
5
+
6
+ A smart gem with a dumb name; Dummier is a rails generator for automating the creation of rails testing applications. These applications usually live in test/dummy, and we see them alot.
7
+
8
+ It's just not cool having so many empty, un-loved rails apps hiding away in the /test directory of all these fun gems. Let's give them some more attention by using dummier to make it exciting to generate these apps!
9
+
10
+ Once dummier is ready for action, you'll cd into your existing gem and run `bundle exec dummier`.
11
+
12
+ You can create custom hooks that fire along the way by placing the appropriately named files in `your_gem/lib/dummy_hooks/hook_name.rb`.
13
+
14
+ That's all for now.
15
+
16
+
17
+ Installation
18
+ ------------
19
+
20
+ Don't do that quite yet.
21
+
22
+
23
+ Testing
24
+ -------
25
+
26
+ To get setup for testing, clone this repo, bundle up and run rake.
27
+
28
+ git clone git://github.com/citrus/dummier.git
29
+ cd dummier
30
+ bundle install
31
+ rake
32
+
33
+ Or do this if you want to spork:
34
+
35
+ git clone git://github.com/citrus/dummier.git
36
+ cd dummier
37
+ bundle install
38
+ bundle exec spork
39
+
40
+ # in another window
41
+ cd back/to/dummier
42
+ testdrb test/**/*_test.rb
43
+
44
+ Enjoy!
45
+
46
+
47
+
48
+ To Do
49
+ -----
50
+
51
+ * testing..
52
+ * get migrate task to work
53
+
54
+
55
+ Change Log
56
+ ----------
57
+
58
+ **2011/5/11**
59
+
60
+ * added spork and some tests
61
+
62
+ **2011/5/10**
63
+
64
+ * it exists!
65
+
66
+
67
+ License
68
+ -------
69
+
70
+ Copyright (c) 2011 Spencer Steffen and Citrus, released under the New BSD License All rights reserved.
@@ -0,0 +1,12 @@
1
+ require 'bundler'
2
+ require 'rake/testtask'
3
+
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << 'test' << 'lib'
8
+ t.pattern = 'test/**/*_test.rb'
9
+ t.verbose = true
10
+ end
11
+
12
+ task :default => :test
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.expand_path("../../lib", __FILE__)
4
+ require 'dummier'
5
+
6
+ dir = (ARGV.shift || `pwd`).strip
7
+ puts "Getting dumb in #{dir.inspect}"
8
+
9
+ Dummier::AppGenerator.new(dir).run!
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "dummier/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "dummier"
7
+ s.version = Dummier::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Spencer Steffen"]
10
+ s.email = ["spencer@citrusme.com"]
11
+ s.homepage = "https://github.com/citrus/dummier"
12
+ s.summary = %q{Dummier generates a minimal rails testing application.}
13
+ s.description = %q{Dummier is a rails generator for automating the creation of rails testing applications.}
14
+
15
+ s.rubyforge_project = "dummier"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency('rails', '>= 3.0.0')
23
+
24
+ s.add_development_dependency('shoulda', '>= 2.11.3')
25
+ s.add_development_dependency('spork', '>= 0.9.0.rc7')
26
+ s.add_development_dependency('spork-testunit', '>= 0.0.5')
27
+
28
+ end
@@ -0,0 +1,5 @@
1
+ require 'dummier/app_generator'
2
+
3
+ module Dummier
4
+
5
+ end
@@ -0,0 +1,140 @@
1
+ require "fileutils"
2
+ require "rails/generators"
3
+ require "rails/generators/rails/app/app_generator"
4
+
5
+
6
+ # Much of this generator came from enginex by José Valim
7
+ # https://github.com/josevalim/enginex/blob/master/lib/enginex.rb
8
+
9
+ module Dummier
10
+
11
+ class AppGenerator < Rails::Generators::Base
12
+
13
+ source_root File.expand_path('../../templates', __FILE__)
14
+
15
+ def defaults
16
+ { :verbose => false }
17
+ end
18
+
19
+ def initialize(root, options={})
20
+ @behavior = :invoke
21
+ @root_path = File.expand_path(root)
22
+ @destination_stack = []
23
+ @options = defaults.merge(options)
24
+ self.destination_root = File.join(test_path, name)
25
+ raise "Invalid directory!" unless Dir.exists?(@root_path)
26
+ end
27
+
28
+ # The name of the rails application
29
+ def name
30
+ "dummy"
31
+ end
32
+
33
+ # The name of the extension to be tested
34
+ def extension
35
+ File.basename(root_path)
36
+ end
37
+
38
+ # The name, camelized
39
+ def camelized
40
+ @camelized ||= name.camelize
41
+ end
42
+
43
+ # The name, underscored
44
+ def underscored
45
+ @underscored ||= name.underscore
46
+ end
47
+
48
+ # Path the the extension's root folder
49
+ def root_path
50
+ @root_path
51
+ end
52
+
53
+ # Path to the extension's test folder
54
+ def test_path
55
+ File.join(root_path, "test")
56
+ end
57
+
58
+ # Path to the testing application
59
+ def destination_path
60
+ File.join(test_path, name)
61
+ end
62
+
63
+ # gets the current application.rb contents
64
+ def application_definition
65
+ @application_definition ||= begin
66
+ contents = File.read("#{destination_root}/config/application.rb")
67
+ contents[(contents.index("module Dummy"))..-1]
68
+ end
69
+ end
70
+ alias :store_application_definition! :application_definition
71
+
72
+ # loads a hook file and evalutes its contents.
73
+ # rescues any exceptions and logs their message.
74
+ # store hooks in your_extension/lib/dummy_hooks
75
+ def fire_hook(hook_name)
76
+ begin
77
+ file = File.join(root_path, "lib/dummy_hooks/#{hook_name}.rb")
78
+ say_status "hook", hook_name, File.exists?(file) ? :cyan : :red
79
+ if File.exists?(file)
80
+ rb = File.read(file)
81
+ eval(rb)
82
+ end
83
+ rescue Exception => e
84
+ say_status "failed", "#{hook_name} raised an exception", :red
85
+ say e.message.strip + "\n", :red
86
+ end
87
+ end
88
+
89
+
90
+
91
+ # Runs the generator
92
+ def run!
93
+
94
+ fire_hook :before_delete
95
+
96
+ # remove existing test app
97
+ FileUtils.rm_r(destination_path) if File.directory?(destination_path)
98
+
99
+ fire_hook :before_app_generator
100
+
101
+ # run the base app generator
102
+ Rails::Generators::AppGenerator.start([destination_path])
103
+
104
+ fire_hook :after_app_generator
105
+
106
+ inside destination_path do
107
+
108
+ # remove unnecessary files
109
+ files = %w(public/index.html public/images/rails.png Gemfile README doc test vendor)
110
+ files.each do |file|
111
+ say_status "delete", file
112
+ FileUtils.rm_r(file) if File.exists?(file)
113
+ end
114
+
115
+ # replace crucial templates
116
+ template "rails/application.rb", "config/application.rb", :force => true
117
+ template "rails/boot.rb", "config/boot.rb", :force => true
118
+
119
+ # add cucumber to database.yml
120
+ cukes = Dir.exists?(File.join(root_path, "features"))
121
+ if cukes
122
+ append_file "config/database.yml" do
123
+ %(
124
+ cucumber:
125
+ <<: *test
126
+ )
127
+ end
128
+ end
129
+
130
+ fire_hook :before_migrate
131
+
132
+ rake("db:migrate", :env => "test")
133
+
134
+ fire_hook :after_migrate
135
+
136
+ end
137
+
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,7 @@
1
+ desc "preps the testing environment"
2
+ task :build_dummy do
3
+ require 'dummier'
4
+ dir = `pwd`.strip
5
+ puts dir.inspect
6
+ Dummier::AppGenerator.new(dir).run!
7
+ end
@@ -0,0 +1,3 @@
1
+ module Dummier
2
+ VERSION = "0.1.0.rc1"
3
+ end
@@ -0,0 +1,12 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require "active_model/railtie"
4
+ require "active_record/railtie"
5
+ require "action_controller/railtie"
6
+ require "action_view/railtie"
7
+ require "action_mailer/railtie"
8
+
9
+ Bundler.require
10
+ require "<%= extension %>"
11
+
12
+ <%= application_definition %>
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ gemfile = File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ if File.exist?(gemfile)
5
+ ENV['BUNDLE_GEMFILE'] = gemfile
6
+ require 'bundler'
7
+ Bundler.setup
8
+ end
9
+
10
+ $:.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,16 @@
1
+ require 'fileutils'
2
+ require 'spork'
3
+
4
+ Spork.prefork do
5
+
6
+ require 'bundler/setup'
7
+ Bundler.require(:default, :test)
8
+ require 'shoulda'
9
+
10
+ end
11
+
12
+ Spork.each_run do
13
+
14
+ #Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
15
+
16
+ end
@@ -0,0 +1,55 @@
1
+ require_relative '../test_helper'
2
+
3
+ class DummierTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @root = File.expand_path("../../../", __FILE__)
7
+ @dummy = File.join(@root, "test/dummy")
8
+ end
9
+
10
+ def read_file(file)
11
+ File.read(File.join(@dummy, file))
12
+ end
13
+
14
+ should "have classes defined" do
15
+ assert defined?(Dummier)
16
+ assert defined?(Dummier::AppGenerator)
17
+ end
18
+
19
+ should "create test/dummy" do
20
+
21
+ # remove existing dummy
22
+ FileUtils.rm_r(@dummy) if File.exists?(@dummy)
23
+ assert !File.exists?(@dummy)
24
+
25
+ # run generator
26
+ Dummier::AppGenerator.new(@root).run!
27
+
28
+ # make sure the dummy is created
29
+ assert File.exists?(@dummy)
30
+
31
+ # make sure things that should get deleted do
32
+ files = %w(public/index.html public/images/rails.png Gemfile README doc test vendor)
33
+ files.each do |file|
34
+ assert !File.exists?(file)
35
+ end
36
+
37
+ # make sure application template is applied
38
+ rb = read_file('config/application.rb')
39
+ [ "require File.expand_path('../boot', __FILE__)", /require "dummier"/, /module Dummy/ ].each do |regex|
40
+ assert_match regex, rb
41
+ end
42
+
43
+ # make sure boot template is applied
44
+ rb = read_file('config/boot.rb')
45
+ [ "gemfile = File.expand_path('../../../../Gemfile', __FILE__)", "ENV['BUNDLE_GEMFILE'] = gemfile", "$:.unshift File.expand_path('../../../../lib', __FILE__)" ].each do |regex|
46
+ assert_match regex, rb
47
+ end
48
+
49
+ end
50
+
51
+ context "with some hooks" do
52
+ # todo
53
+ end
54
+
55
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dummier
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: 6
5
+ version: 0.1.0.rc1
6
+ platform: ruby
7
+ authors:
8
+ - Spencer Steffen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-05-11 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rails
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 3.0.0
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: shoulda
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 2.11.3
35
+ type: :development
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: spork
39
+ prerelease: false
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 0.9.0.rc7
46
+ type: :development
47
+ version_requirements: *id003
48
+ - !ruby/object:Gem::Dependency
49
+ name: spork-testunit
50
+ prerelease: false
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 0.0.5
57
+ type: :development
58
+ version_requirements: *id004
59
+ description: Dummier is a rails generator for automating the creation of rails testing applications.
60
+ email:
61
+ - spencer@citrusme.com
62
+ executables:
63
+ - dummier
64
+ extensions: []
65
+
66
+ extra_rdoc_files: []
67
+
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - LICENSE
72
+ - README.md
73
+ - Rakefile
74
+ - bin/dummier
75
+ - dummier.gemspec
76
+ - lib/dummier.rb
77
+ - lib/dummier/app_generator.rb
78
+ - lib/dummier/tasks/builder.rb
79
+ - lib/dummier/version.rb
80
+ - lib/templates/rails/application.rb
81
+ - lib/templates/rails/boot.rb
82
+ - test/test_helper.rb
83
+ - test/unit/dummier_test.rb
84
+ homepage: https://github.com/citrus/dummier
85
+ licenses: []
86
+
87
+ post_install_message:
88
+ rdoc_options: []
89
+
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: "0"
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ">"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.3.1
104
+ requirements: []
105
+
106
+ rubyforge_project: dummier
107
+ rubygems_version: 1.8.1
108
+ signing_key:
109
+ specification_version: 3
110
+ summary: Dummier generates a minimal rails testing application.
111
+ test_files:
112
+ - test/test_helper.rb
113
+ - test/unit/dummier_test.rb