dummier 0.2.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  rvm:
2
2
  - 1.8.7
3
3
  - 1.9.2
4
+ - 1.9.3
4
5
  - rbx
5
- - rbx-2.0
6
6
  - ree
data/README.md CHANGED
@@ -10,83 +10,104 @@ Dummier is simple; just run the binary from your gem's root directory and it wil
10
10
 
11
11
  To catch the hooks, just create appropriately named files in `test/dummy_hooks` inside your gem. See **Hooks** below for more info.
12
12
 
13
-
13
+ ------------------------------------------------------------------------------
14
14
  Installation
15
- ------------
15
+ ------------------------------------------------------------------------------
16
16
 
17
17
  To install from RubyGems:
18
18
 
19
- gem install dummier
19
+ ```bash
20
+ gem install dummier
21
+ ```
22
+
20
23
 
21
24
  To install with bundler:
22
25
 
23
- gem 'dummier', '>= 0.2.4'
26
+ ```ruby
27
+ gem 'dummier', '>= 0.3.0'
28
+ ```
29
+
24
30
 
25
31
  To package for development in your gemspec:
26
-
27
- s.add_development_dependency('dummier', '>= 0.2.4')
32
+
33
+ ```ruby
34
+ s.add_development_dependency('dummier', '>= 0.3.0')
35
+ ```
28
36
 
29
37
 
38
+ ------------------------------------------------------------------------------
30
39
  Usage
31
- -----
40
+ ------------------------------------------------------------------------------
32
41
 
33
42
  After you've installed Dummier, just `cd` into the gem your developing and run the binary:
34
43
 
35
- dummier
44
+ ```bash
45
+ dummier
46
+ ```
36
47
 
37
48
  If you're in a gem that uses bundler, you may have to run the binary with `bundle exec`:
38
49
 
39
- bundle exec dummier
40
-
50
+ ```bash
51
+ bundle exec dummier
52
+ ```
41
53
 
54
+
55
+ ------------------------------------------------------------------------------
42
56
  Hooks
43
- -----
57
+ ------------------------------------------------------------------------------
44
58
 
45
- Dummier calls the following hooks along the way:
59
+ Dummier calls the following hooks along the way, in this order:
46
60
 
47
- before_delete
48
- before_app_generator
49
- after_app_generator
50
- before_migrate
51
- after_migrate
52
-
53
-
54
- Place appropriately named files ) in `test/dummy_hooks` and dummier will find and execute them automatically!
61
+ 1. before_delete
62
+ 2. before_app_generator
63
+ 3. after_app_generator
64
+ 4. before_migrate
65
+ 5. after_migrate
55
66
 
56
- You can use [Rails::Generators::Actions](http://api.rubyonrails.org/classes/Rails/Generators/Actions.html) as well as [Thor::Actions](http://textmate.rubyforge.org/thor/Thor/Actions.html) in your hooks. Also, since hooks are just `eval`'d into the [Dummer::AppGenerator](http://rubydoc.info/gems/dummier/0.2.2/Dummier/AppGenerator), you have access to all of [those methods](http://rubydoc.info/gems/dummier/0.2.2/Dummier/AppGenerator) as well.
67
+
68
+ Place appropriately named files in `test/dummy_hooks` and dummier will find and execute them automatically!
69
+
70
+ You can use [Rails::Generators::Actions](http://api.rubyonrails.org/classes/Rails/Generators/Actions.html) as well as [Thor::Actions](http://textmate.rubyforge.org/thor/Thor/Actions.html) in your hooks. Also, since hooks are just `eval`'d into the [Dummer::AppGenerator](http://rubydoc.info/gems/dummier/0.3.0/Dummier/AppGenerator), you have access to all of [those methods](http://rubydoc.info/gems/dummier/0.3.0/Dummier/AppGenerator) as well.
57
71
 
72
+ If a hook throws an error, Dummier will raise a `Dummier::HookException` and exit immediately.
73
+
58
74
 
59
75
  ### Simple Example
60
76
 
61
- Here's a `before_migrate.rb` hook that will install [Spree Commerce](https://github.com/spree/spree) by running some rake commands before migrating the `test/dummy` database.
77
+ Here's a `before_migrate.rb` hook that will install [Spree Commerce](https://github.com/spree/spree) by running a generator before migrating the `test/dummy` database.
78
+
79
+ ```ruby
80
+ # test/dummy_hooks/before_migrate.rb
81
+ run "rails g spree:install"
82
+ ```
62
83
 
63
- # test/dummy_hooks/before_migrate.rb
64
- say_status "installing", "spree_core, spree_auth and spree_sample"
65
- rake "spree_core:install spree_auth:install spree_sample:install"
66
-
67
84
 
68
85
  ### More Complex Example
69
86
 
70
87
  Here's an example taken from [has_magick_title](https://github.com/citrus/has_magick_title):
71
88
 
72
- # test/dummy_hooks/after_app_generator.rb
73
- run "rails g scaffold post title:string"
74
-
75
- gsub_file "app/models/post.rb", "end", %(
76
- has_magick_title
77
-
78
- end)
79
-
80
- gsub_file "config/routes.rb", "resources :posts", %(
81
- resources :posts
82
- root :to => "posts#index")
83
-
84
- gsub_file "app/views/posts/show.html.erb", "<%= @post.title %>", %(
85
- <%= magick_title_for @post %>)
86
89
 
90
+ ```ruby
91
+ # test/dummy_hooks/after_app_generator.rb
92
+ run "rails g scaffold post title:string"
93
+
94
+ gsub_file "app/models/post.rb", "end", %(
95
+ has_magick_title
96
+
97
+ end)
87
98
 
99
+ gsub_file "config/routes.rb", "resources :posts", %(
100
+ resources :posts
101
+ root :to => "posts#index")
102
+
103
+ gsub_file "app/views/posts/show.html.erb", "<%= @post.title %>", %(
104
+ <%= magick_title_for @post %>)
105
+ ```
106
+
107
+
108
+ ------------------------------------------------------------------------------
88
109
  Testing
89
- -------
110
+ ------------------------------------------------------------------------------
90
111
 
91
112
  To get setup for testing, clone this repo, bundle up and run rake.
92
113
 
@@ -99,8 +120,13 @@ To get setup for testing, clone this repo, bundle up and run rake.
99
120
  Enjoy!
100
121
 
101
122
 
123
+ ------------------------------------------------------------------------------
102
124
  Change Log
103
- ----------
125
+ ------------------------------------------------------------------------------
126
+
127
+ **0.3.0 - 2012/1/26**
128
+
129
+ * exit and raise a Dummier::HookException when a hook raises an exception
104
130
 
105
131
 
106
132
  **0.2.4 - 2011/9/7**
@@ -152,15 +178,17 @@ Change Log
152
178
  * it exists!
153
179
 
154
180
 
181
+ ------------------------------------------------------------------------------
155
182
  Contributors
156
- ------------
183
+ ------------------------------------------------------------------------------
157
184
 
158
185
  - Spencer Steffen ([@citrus](https://github.com/citrus))
159
186
  - Fritz Thielemann ([@fritzek](https://github.com/fritzek))
160
187
  - [@holdensmagicalunicorn](https://github.com/holdensmagicalunicorn)
161
188
 
162
189
 
190
+ ------------------------------------------------------------------------------
163
191
  License
164
- -------
192
+ ------------------------------------------------------------------------------
165
193
 
166
194
  Copyright (c) 2011 Spencer Steffen and Citrus, released under the New BSD License All rights reserved.
@@ -4,6 +4,6 @@ $:.unshift File.expand_path("../../lib", __FILE__)
4
4
  require 'dummier'
5
5
 
6
6
  dir = (ARGV.shift || `pwd`).strip
7
- puts "Getting dumb in #{dir.inspect}"
7
+ puts "Running dummier from #{dir.inspect}"
8
8
 
9
9
  Dummier::AppGenerator.new(dir).run!
@@ -3,6 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
  require "dummier/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
+
6
7
  s.name = "dummier"
7
8
  s.version = Dummier::VERSION
8
9
  s.platform = Gem::Platform::RUBY
@@ -21,7 +22,8 @@ Gem::Specification.new do |s|
21
22
 
22
23
  s.add_dependency('rails', '>= 3.0.0')
23
24
 
24
- s.add_development_dependency('shoulda', '>= 2.11.3')
25
- s.add_development_dependency('sqlite3', '>= 1.3.3')
26
-
25
+ s.add_development_dependency('minitest', '>= 2.0.0')
26
+ s.add_development_dependency('minitest_should', '>= 0.3.1')
27
+ s.add_development_dependency('sqlite3', '>= 1.3.3')
28
+
27
29
  end
@@ -1,7 +1,8 @@
1
1
  require 'dummier/app_generator'
2
+ require 'dummier/version'
2
3
 
3
4
  module Dummier
4
5
 
5
- # just a generator!
6
-
6
+ class HookException < Exception; end
7
+
7
8
  end
@@ -21,7 +21,7 @@ module Dummier
21
21
  @root_path = File.expand_path(root)
22
22
  @destination_stack = []
23
23
  @options = defaults.merge(options)
24
- self.source_paths << File.join(root_path, "test", "dummy_hooks", "templates")
24
+ self.source_paths << File.join(root_path, "test/dummy_hooks/templates")
25
25
  self.destination_root = File.join(test_path, name)
26
26
  raise "Invalid directory!" unless File.directory?(@root_path)
27
27
  end
@@ -80,7 +80,10 @@ module Dummier
80
80
  eval File.read(file) if File.exists?(file)
81
81
  rescue Exception => e
82
82
  say_status "failed", "#{hook_name} raised an exception", :red
83
+ say "*" * 60, :red
83
84
  say e.message.strip + "\n", :red
85
+ say e.backtrace.join("\n"), :red
86
+ raise ::Dummier::HookException, "Quitting, #{hook_name} raised an exception."
84
87
  end
85
88
  end
86
89
 
@@ -1,3 +1,3 @@
1
1
  module Dummier
2
- VERSION = "0.2.4"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -0,0 +1 @@
1
+ HookTestHelper.register :before_app_generator
@@ -0,0 +1 @@
1
+ raise Exception, "Before Delete"
@@ -0,0 +1,17 @@
1
+ class MiniTest::Should::TestCase
2
+
3
+ # Borrowed from thor .. thanks wycats! :)
4
+ def capture(stream)
5
+ begin
6
+ stream = stream.to_s
7
+ eval "$#{stream} = StringIO.new"
8
+ yield
9
+ result = eval("$#{stream}").string
10
+ ensure
11
+ eval("$#{stream} = #{stream.upcase}")
12
+ end
13
+
14
+ result
15
+ end
16
+
17
+ end
@@ -1,5 +1,8 @@
1
1
  require 'bundler/setup'
2
2
  Bundler.require(:default, :test)
3
- require 'shoulda'
3
+ require 'minitest/autorun'
4
+ require 'minitest/should'
4
5
  require 'fileutils'
5
- require File.expand_path('../support/hook_test_helper', __FILE__)
6
+
7
+ require 'support/test_case'
8
+ require 'support/hook_test_helper'
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class AppGeneratorTest < Test::Unit::TestCase
3
+ class AppGeneratorTest < MiniTest::Should::TestCase
4
4
 
5
5
  def setup
6
6
  @root = File.expand_path("../../dummy_gem", __FILE__)
@@ -34,35 +34,32 @@ class AppGeneratorTest < Test::Unit::TestCase
34
34
  context "when run" do
35
35
 
36
36
  setup do
37
- @generator.run!
37
+ capture(:stdout) { @generator.run! }
38
38
  end
39
39
 
40
- should "create test/dummy" do
41
- assert File.exists?(@dummy)
42
- end
40
+ should "create test/dummy and apply proper templates" do
41
+ # should create test/dummy
42
+ assert File.exists?(@dummy), "test/dummy should exist at #{@dummy}"
43
43
 
44
- should "remove unnecessary files" do
44
+ # should remove unnecessary files
45
45
  files = %w(public/index.html public/images/rails.png Gemfile README doc test vendor)
46
46
  files.each do |file|
47
- assert !File.exists?(file)
47
+ assert !File.exists?(file), "#{file} should have been deleted"
48
48
  end
49
- end
50
49
 
51
- should "apply application template" do
50
+ # should apply application template
52
51
  rb = read_file('config/application.rb')
53
52
  [ "require File.expand_path('../boot', __FILE__)", /require "dummy_gem"/, /module Dummy/ ].each do |regex|
54
- assert_match regex, rb
53
+ assert_match regex, rb, "config/application should have had #{rb.inspect} applied."
55
54
  end
56
- end
57
55
 
58
- should "apply the boot template" do
56
+ # should apply the boot template
59
57
  rb = read_file('config/boot.rb')
60
58
  [ "gemfile = File.expand_path('../../../../Gemfile', __FILE__)", "ENV['BUNDLE_GEMFILE'] = gemfile", "$:.unshift File.expand_path('../../../../lib', __FILE__)" ].each do |regex|
61
- assert_match regex, rb
59
+ assert_match regex, rb, "config/boot.rb should have had #{rb.inspect} applied."
62
60
  end
63
- end
64
61
 
65
- should "fire hooks in proper order" do
62
+ # should fire hooks in proper order
66
63
  assert_equal [ :before_delete, :before_app_generator, :after_app_generator, :before_migrate, :after_migrate ], HookTestHelper.hooks
67
64
  end
68
65
 
@@ -73,26 +70,56 @@ class AppGeneratorTest < Test::Unit::TestCase
73
70
  setup do
74
71
  @features = File.join(@root, "features")
75
72
  FileUtils.mkdir(@features)
76
- @generator.run!
73
+ capture(:stdout) { @generator.run! }
77
74
  end
78
75
 
79
76
  teardown do
80
77
  FileUtils.rm_r(@features) if File.directory?(@features)
81
78
  end
82
79
 
83
- should "apply cucumber database config" do
80
+ should "apply cucumber support" do
81
+ # should write database config
84
82
  yml = read_file('config/database.yml')
85
83
  [ "test: &test", "cucumber:", " <<: *test" ].each do |regex|
86
- assert_match regex, yml
84
+ assert_match regex, yml, "config/database.yml should have had #{yml.inspect} applied"
87
85
  end
88
- end
89
86
 
90
- should "apply cucumber environment" do
91
- assert File.exists?(File.join(@dummy, "config/environments/cucumber.rb"))
87
+ # should apply cucumber environment
88
+ env = "config/environments/cucumber.rb"
89
+ assert File.exists?(File.join(@dummy, env)), "#{env.inspect} should have been created"
92
90
  end
93
91
 
94
92
  end
95
-
93
+
94
+ end
95
+
96
+ context "A doomed to fail app generator" do
97
+
98
+ setup do
99
+ # create a failed destiny
100
+ @hooks = File.join(@root, "test/dummy_hooks")
101
+ @tmp = File.join(@root, "test/tmp_dummy_hooks")
102
+ @err = File.join(@root, "test/erroneous_dummy_hooks")
103
+ FileUtils.mv @hooks, @tmp
104
+ FileUtils.mv @err, @hooks
105
+ @generator = Dummier::AppGenerator.new(@root)
106
+ end
107
+
108
+ teardown do
109
+ # revert to sanity
110
+ FileUtils.mv @hooks, @err
111
+ FileUtils.mv @tmp, @hooks
112
+ end
113
+
114
+ should "error and exit if a hook throws an exception" do
115
+ # ensure exception is raised
116
+ assert_raises Dummier::HookException do
117
+ capture(:stdout) { @generator.run! }
118
+ end
119
+ # ensure the generator didn't make it any farther
120
+ assert HookTestHelper.hooks.empty?
121
+ end
122
+
96
123
  end
97
124
 
98
125
  end
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class DummierTest < Test::Unit::TestCase
3
+ class DummierTest < MiniTest::Should::TestCase
4
4
 
5
5
  def setup
6
6
  @root = File.expand_path("../../../", __FILE__)
metadata CHANGED
@@ -1,60 +1,69 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: dummier
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
4
5
  prerelease:
5
- version: 0.2.4
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Spencer Steffen
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-09-07 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2012-01-27 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: rails
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70265410791360 !ruby/object:Gem::Requirement
19
17
  none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
23
21
  version: 3.0.0
24
22
  type: :runtime
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
27
- name: shoulda
28
23
  prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *70265410791360
25
+ - !ruby/object:Gem::Dependency
26
+ name: minitest
27
+ requirement: &70265410787140 !ruby/object:Gem::Requirement
30
28
  none: false
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
34
- version: 2.11.3
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 2.0.0
35
33
  type: :development
36
- version_requirements: *id002
37
- - !ruby/object:Gem::Dependency
38
- name: sqlite3
39
34
  prerelease: false
40
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *70265410787140
36
+ - !ruby/object:Gem::Dependency
37
+ name: minitest_should
38
+ requirement: &70265410778440 !ruby/object:Gem::Requirement
41
39
  none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: 0.3.1
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70265410778440
47
+ - !ruby/object:Gem::Dependency
48
+ name: sqlite3
49
+ requirement: &70265410777740 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
45
54
  version: 1.3.3
46
55
  type: :development
47
- version_requirements: *id003
48
- description: Dummier is a rails generator for automating the creation of rails testing applications.
49
- email:
56
+ prerelease: false
57
+ version_requirements: *70265410777740
58
+ description: Dummier is a rails generator for automating the creation of rails testing
59
+ applications.
60
+ email:
50
61
  - spencer@citrusme.com
51
- executables:
62
+ executables:
52
63
  - dummier
53
64
  extensions: []
54
-
55
65
  extra_rdoc_files: []
56
-
57
- files:
66
+ files:
58
67
  - .gitignore
59
68
  - .travis.yml
60
69
  - Gemfile
@@ -76,38 +85,44 @@ files:
76
85
  - test/dummy_gem/test/dummy_hooks/before_app_generator.rb
77
86
  - test/dummy_gem/test/dummy_hooks/before_delete.rb
78
87
  - test/dummy_gem/test/dummy_hooks/before_migrate.rb
88
+ - test/dummy_gem/test/erroneous_dummy_hooks/before_app_generator.rb
89
+ - test/dummy_gem/test/erroneous_dummy_hooks/before_delete.rb
79
90
  - test/support/hook_test_helper.rb
91
+ - test/support/test_case.rb
80
92
  - test/test_helper.rb
81
93
  - test/unit/app_generator_test.rb
82
94
  - test/unit/dummier_test.rb
83
95
  homepage: https://github.com/citrus/dummier
84
96
  licenses: []
85
-
86
97
  post_install_message:
87
98
  rdoc_options: []
88
-
89
- require_paths:
99
+ require_paths:
90
100
  - lib
91
- required_ruby_version: !ruby/object:Gem::Requirement
101
+ required_ruby_version: !ruby/object:Gem::Requirement
92
102
  none: false
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: "0"
97
- required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ segments:
108
+ - 0
109
+ hash: 2889636280236080648
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
111
  none: false
99
- requirements:
100
- - - ">="
101
- - !ruby/object:Gem::Version
102
- version: "0"
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ segments:
117
+ - 0
118
+ hash: 2889636280236080648
103
119
  requirements: []
104
-
105
120
  rubyforge_project: dummier
106
121
  rubygems_version: 1.8.10
107
122
  signing_key:
108
123
  specification_version: 3
109
124
  summary: Dummier generates a minimal rails testing application.
110
- test_files:
125
+ test_files:
111
126
  - test/dummy_gem/Gemfile
112
127
  - test/dummy_gem/dummy_gem.gemspec
113
128
  - test/dummy_gem/lib/dummy_gem.rb
@@ -116,7 +131,10 @@ test_files:
116
131
  - test/dummy_gem/test/dummy_hooks/before_app_generator.rb
117
132
  - test/dummy_gem/test/dummy_hooks/before_delete.rb
118
133
  - test/dummy_gem/test/dummy_hooks/before_migrate.rb
134
+ - test/dummy_gem/test/erroneous_dummy_hooks/before_app_generator.rb
135
+ - test/dummy_gem/test/erroneous_dummy_hooks/before_delete.rb
119
136
  - test/support/hook_test_helper.rb
137
+ - test/support/test_case.rb
120
138
  - test/test_helper.rb
121
139
  - test/unit/app_generator_test.rb
122
140
  - test/unit/dummier_test.rb