dummier 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
- Dummier
2
- =======
1
+ # Dummier [![Build Status](https://travis-ci.org/citrus/dummier.png)](http://travis-ci.org/citrus/dummier)
2
+
3
3
 
4
4
  A smart gem with a dumb name; Dummier is a rails generator for automating the creation of rails testing applications.
5
5
 
@@ -21,11 +21,11 @@ To install from RubyGems:
21
21
 
22
22
  To install with bundler:
23
23
 
24
- gem 'dummier', '>= 0.2.2'
24
+ gem 'dummier', '>= 0.2.3'
25
25
 
26
26
  To package for development in your gemspec:
27
27
 
28
- s.add_development_dependency('dummier', '>= 0.2.2')
28
+ s.add_development_dependency('dummier', '>= 0.2.3')
29
29
 
30
30
 
31
31
  Usage
@@ -104,6 +104,12 @@ Change Log
104
104
  ----------
105
105
 
106
106
 
107
+ **0.2.3 - 2011/9/6**
108
+
109
+ * refactored AppGenerator#run!
110
+ * new app generator tests
111
+
112
+
107
113
  **0.2.2 - 2011/8/31**
108
114
 
109
115
  * added to travis-ci.org
@@ -6,4 +6,4 @@ require 'dummier'
6
6
  dir = (ARGV.shift || `pwd`).strip
7
7
  puts "Getting dumb in #{dir.inspect}"
8
8
 
9
- Dummier::AppGenerator.new(dir).run!
9
+ Dummier::AppGenerator.new(dir).run!
@@ -11,6 +11,7 @@ module Dummier
11
11
 
12
12
  source_root File.expand_path('../../templates', __FILE__)
13
13
 
14
+ # Default generator options
14
15
  def defaults
15
16
  { :verbose => false }
16
17
  end
@@ -69,72 +70,90 @@ module Dummier
69
70
  end
70
71
  alias :store_application_definition! :application_definition
71
72
 
72
- # loads a hook file and evalutes its contents.
73
+ # Loads a hook file and evalutes its contents.
73
74
  # rescues any exceptions and logs their message.
74
- # store hooks in your_extension/lib/dummy_hooks
75
+ # Store hooks in gem_root/test/dummy_hooks
75
76
  def fire_hook(hook_name)
76
77
  begin
77
78
  file = File.join(root_path, "test/dummy_hooks/#{hook_name}.rb")
78
79
  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
80
+ eval File.read(file) if File.exists?(file)
83
81
  rescue Exception => e
84
82
  say_status "failed", "#{hook_name} raised an exception", :red
85
83
  say e.message.strip + "\n", :red
86
- end
84
+ end
87
85
  end
88
86
 
89
-
90
-
91
87
  # Runs the generator
92
88
  def run!
93
-
94
89
  fire_hook :before_delete
95
-
96
- # remove existing test app
97
- FileUtils.rm_r(destination_path) if File.directory?(destination_path)
98
-
90
+ remove_existing_dummy
99
91
  fire_hook :before_app_generator
100
-
101
- # run the base app generator
102
- Rails::Generators::AppGenerator.start([destination_path])
103
-
92
+ run_base_generator
104
93
  fire_hook :after_app_generator
105
-
106
94
  inside destination_path do
107
-
108
- # remove unnecessary files
95
+ remove_unnecessary_files
96
+ replace_boot_templates
97
+ add_cucumber_support if has_features?
98
+ fire_hook :before_migrate
99
+ run_migration
100
+ fire_hook :after_migrate
101
+ end
102
+ end
103
+
104
+ private
105
+
106
+ # Removes existing test app
107
+ def remove_existing_dummy
108
+ FileUtils.rm_r(destination_path) if File.directory?(destination_path)
109
+ end
110
+
111
+ # Runs the base app generator
112
+ def run_base_generator
113
+ Rails::Generators::AppGenerator.start([destination_path])
114
+ end
115
+
116
+ # Removes unnecessary files from test/dummy
117
+ def remove_unnecessary_files
109
118
  files = %w(public/index.html public/images/rails.png Gemfile README doc test vendor)
110
119
  files.each do |file|
111
120
  say_status "delete", file
112
121
  FileUtils.rm_r(file) if File.exists?(file)
113
122
  end
123
+ end
114
124
 
115
- # replace crucial templates
125
+ # Replaces application.rb and boot.rb with dummier's templates
126
+ def replace_boot_templates
116
127
  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 = File.directory?(File.join(root_path, "features"))
121
- if cukes
128
+ template "rails/boot.rb", "config/boot.rb", :force => true
129
+ end
130
+
131
+ # Add cucumber config to database.yml
132
+ def add_cucumber_support
133
+ unless File.read(File.join(destination_path, "config/database.yml")) =~ /cucumber/
134
+ gsub_file "config/database.yml", "test:", "test: &test"
122
135
  append_file "config/database.yml" do
123
136
  %(
124
137
  cucumber:
125
138
  <<: *test
126
- )
139
+ )
127
140
  end
128
141
  end
129
-
130
- fire_hook :before_migrate
131
-
142
+ env = "config/environments/cucumber.rb"
143
+ unless File.exists?(File.join(destination_path, env))
144
+ FileUtils.cp(File.join(destination_path, "config/environments/test.rb"), env)
145
+ end
146
+ end
147
+
148
+ # Runs db:migrate on the test database
149
+ def run_migration
132
150
  rake("db:migrate", :env => "test")
133
-
134
- fire_hook :after_migrate
135
-
136
- end
151
+ end
137
152
 
138
- end
153
+ # Checks for ./features within the gem's root path
154
+ def has_features?
155
+ File.directory?(File.join(root_path, "features"))
156
+ end
157
+
139
158
  end
140
159
  end
@@ -1,3 +1,3 @@
1
1
  module Dummier
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
@@ -0,0 +1,17 @@
1
+ module HookTestHelper
2
+
3
+ extend self
4
+
5
+ def register(hook)
6
+ hooks << hook
7
+ end
8
+
9
+ def hooks
10
+ @hooks ||= []
11
+ end
12
+
13
+ def reset!
14
+ @hooks = []
15
+ end
16
+
17
+ end
@@ -1,4 +1,5 @@
1
1
  require 'bundler/setup'
2
2
  Bundler.require(:default, :test)
3
3
  require 'shoulda'
4
- require 'fileutils'
4
+ require 'fileutils'
5
+ require File.expand_path('../support/hook_test_helper', __FILE__)
@@ -0,0 +1,98 @@
1
+ require 'test_helper'
2
+
3
+ class AppGeneratorTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @root = File.expand_path("../../dummy_gem", __FILE__)
7
+ @dummy = File.join(@root, "test/dummy")
8
+ Dir.chdir(@root)
9
+ HookTestHelper.reset!
10
+ # remove existing dummy
11
+ FileUtils.rm_r(@dummy) if File.directory?(@dummy)
12
+ assert !File.directory?(@dummy)
13
+ end
14
+
15
+ def read_file(file)
16
+ File.read(File.join(@dummy, file))
17
+ end
18
+
19
+ should "have classes defined" do
20
+ assert defined?(Dummier)
21
+ assert defined?(Dummier::AppGenerator)
22
+ end
23
+
24
+ context "A new app generator" do
25
+
26
+ setup do
27
+ @generator = Dummier::AppGenerator.new(@root)
28
+ end
29
+
30
+ should "include test/dummy_hooks/templates in the generators source paths" do
31
+ assert @generator.source_paths.include?(File.join(@root, "test/dummy_hooks/templates"))
32
+ end
33
+
34
+ context "when run" do
35
+
36
+ setup do
37
+ @generator.run!
38
+ end
39
+
40
+ should "create test/dummy" do
41
+ assert File.exists?(@dummy)
42
+ end
43
+
44
+ should "remove unnecessary files" do
45
+ files = %w(public/index.html public/images/rails.png Gemfile README doc test vendor)
46
+ files.each do |file|
47
+ assert !File.exists?(file)
48
+ end
49
+ end
50
+
51
+ should "apply application template" do
52
+ rb = read_file('config/application.rb')
53
+ [ "require File.expand_path('../boot', __FILE__)", /require "dummy_gem"/, /module Dummy/ ].each do |regex|
54
+ assert_match regex, rb
55
+ end
56
+ end
57
+
58
+ should "apply the boot template" do
59
+ rb = read_file('config/boot.rb')
60
+ [ "gemfile = File.expand_path('../../../../Gemfile', __FILE__)", "ENV['BUNDLE_GEMFILE'] = gemfile", "$:.unshift File.expand_path('../../../../lib', __FILE__)" ].each do |regex|
61
+ assert_match regex, rb
62
+ end
63
+ end
64
+
65
+ should "fire hooks in proper order" do
66
+ assert_equal [ :before_delete, :before_app_generator, :after_app_generator, :before_migrate, :after_migrate ], HookTestHelper.hooks
67
+ end
68
+
69
+ end
70
+
71
+ context "with cucumber features, when run" do
72
+
73
+ setup do
74
+ @features = File.join(@root, "features")
75
+ FileUtils.mkdir(@features)
76
+ @generator.run!
77
+ end
78
+
79
+ teardown do
80
+ FileUtils.rm_r(@features) if File.directory?(@features)
81
+ end
82
+
83
+ should "apply cucumber database config" do
84
+ yml = read_file('config/database.yml')
85
+ [ "test: &test", "cucumber:", " <<: *test" ].each do |regex|
86
+ assert_match regex, yml
87
+ end
88
+ end
89
+
90
+ should "apply cucumber environment" do
91
+ assert File.exists?(File.join(@dummy, "config/environments/cucumber.rb"))
92
+ end
93
+
94
+ end
95
+
96
+ end
97
+
98
+ end
@@ -1,74 +1,18 @@
1
1
  require 'test_helper'
2
2
 
3
- module HookTestHelper
4
- extend self
5
-
6
- def register(hook)
7
- hooks << hook
8
- end
9
-
10
- def hooks
11
- @hooks ||= []
12
- end
13
-
14
- end
15
-
16
-
17
3
  class DummierTest < Test::Unit::TestCase
18
4
 
19
5
  def setup
20
- @root = File.expand_path("../../dummy_gem", __FILE__)
21
- @dummy = File.join(@root, "test/dummy")
6
+ @root = File.expand_path("../../../", __FILE__)
22
7
  end
23
8
 
24
- def read_file(file)
25
- File.read(File.join(@dummy, file))
9
+ should "include executable" do
10
+ assert File.executable?(File.join(@root, "bin/dummier"))
26
11
  end
27
-
12
+
28
13
  should "have classes defined" do
29
14
  assert defined?(Dummier)
30
15
  assert defined?(Dummier::AppGenerator)
31
16
  end
32
-
33
- should "create test/dummy" do
34
-
35
- # remove existing dummy
36
- FileUtils.rm_r(@dummy) if File.exists?(@dummy)
37
- assert !File.exists?(@dummy)
38
-
39
- # create a generator
40
- @generator = Dummier::AppGenerator.new(@root)
41
-
42
- # make sure our gem's dummy_hooks/templates folder is accessible
43
- assert @generator.source_paths.include?(File.join(@root, "test/dummy_hooks/templates"))
44
-
45
- # run the generator
46
- @generator.run!
47
-
48
- # make sure the dummy is created
49
- assert File.exists?(@dummy)
50
-
51
- # make sure things that should get deleted do
52
- files = %w(public/index.html public/images/rails.png Gemfile README doc test vendor)
53
- files.each do |file|
54
- assert !File.exists?(file)
55
- end
56
-
57
- # make sure application template is applied
58
- rb = read_file('config/application.rb')
59
- [ "require File.expand_path('../boot', __FILE__)", /require "dummy_gem"/, /module Dummy/ ].each do |regex|
60
- assert_match regex, rb
61
- end
62
-
63
- # make sure boot template is applied
64
- rb = read_file('config/boot.rb')
65
- [ "gemfile = File.expand_path('../../../../Gemfile', __FILE__)", "ENV['BUNDLE_GEMFILE'] = gemfile", "$:.unshift File.expand_path('../../../../lib', __FILE__)" ].each do |regex|
66
- assert_match regex, rb
67
- end
68
-
69
- # make sure hooks are all registered and in proper order
70
- assert_equal [:before_delete, :before_app_generator, :after_app_generator, :before_migrate, :after_migrate], HookTestHelper.hooks
71
-
72
- end
73
-
74
- end
17
+
18
+ end
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dummier
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
5
4
  prerelease:
6
- segments:
7
- - 0
8
- - 2
9
- - 2
10
- version: 0.2.2
5
+ version: 0.2.3
11
6
  platform: ruby
12
7
  authors:
13
8
  - Spencer Steffen
@@ -15,8 +10,7 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2011-08-31 00:00:00 -07:00
19
- default_executable:
13
+ date: 2011-09-07 00:00:00 Z
20
14
  dependencies:
21
15
  - !ruby/object:Gem::Dependency
22
16
  name: rails
@@ -26,11 +20,6 @@ dependencies:
26
20
  requirements:
27
21
  - - ">="
28
22
  - !ruby/object:Gem::Version
29
- hash: 7
30
- segments:
31
- - 3
32
- - 0
33
- - 0
34
23
  version: 3.0.0
35
24
  type: :runtime
36
25
  version_requirements: *id001
@@ -42,11 +31,6 @@ dependencies:
42
31
  requirements:
43
32
  - - ">="
44
33
  - !ruby/object:Gem::Version
45
- hash: 37
46
- segments:
47
- - 2
48
- - 11
49
- - 3
50
34
  version: 2.11.3
51
35
  type: :development
52
36
  version_requirements: *id002
@@ -58,11 +42,6 @@ dependencies:
58
42
  requirements:
59
43
  - - ">="
60
44
  - !ruby/object:Gem::Version
61
- hash: 29
62
- segments:
63
- - 1
64
- - 3
65
- - 3
66
45
  version: 1.3.3
67
46
  type: :development
68
47
  version_requirements: *id003
@@ -97,9 +76,10 @@ files:
97
76
  - test/dummy_gem/test/dummy_hooks/before_app_generator.rb
98
77
  - test/dummy_gem/test/dummy_hooks/before_delete.rb
99
78
  - test/dummy_gem/test/dummy_hooks/before_migrate.rb
79
+ - test/support/hook_test_helper.rb
100
80
  - test/test_helper.rb
81
+ - test/unit/app_generator_test.rb
101
82
  - test/unit/dummier_test.rb
102
- has_rdoc: true
103
83
  homepage: https://github.com/citrus/dummier
104
84
  licenses: []
105
85
 
@@ -113,23 +93,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
113
93
  requirements:
114
94
  - - ">="
115
95
  - !ruby/object:Gem::Version
116
- hash: 3
117
- segments:
118
- - 0
119
96
  version: "0"
120
97
  required_rubygems_version: !ruby/object:Gem::Requirement
121
98
  none: false
122
99
  requirements:
123
100
  - - ">="
124
101
  - !ruby/object:Gem::Version
125
- hash: 3
126
- segments:
127
- - 0
128
102
  version: "0"
129
103
  requirements: []
130
104
 
131
105
  rubyforge_project: dummier
132
- rubygems_version: 1.4.2
106
+ rubygems_version: 1.8.10
133
107
  signing_key:
134
108
  specification_version: 3
135
109
  summary: Dummier generates a minimal rails testing application.
@@ -142,5 +116,7 @@ test_files:
142
116
  - test/dummy_gem/test/dummy_hooks/before_app_generator.rb
143
117
  - test/dummy_gem/test/dummy_hooks/before_delete.rb
144
118
  - test/dummy_gem/test/dummy_hooks/before_migrate.rb
119
+ - test/support/hook_test_helper.rb
145
120
  - test/test_helper.rb
121
+ - test/unit/app_generator_test.rb
146
122
  - test/unit/dummier_test.rb