multiengine 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source :rubygems
2
+
3
+ # gemspec
4
+
5
+ gem "sqlite3"
6
+ gem "rspec", ">= 2.5"
7
+ gem "rspec-rails", ">= 2.5"
8
+ gem "capybara", "~> 0.4"
@@ -0,0 +1,20 @@
1
+ Copyright 2010 José Valim http://blog.plataformatec.com.br
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,57 @@
1
+ h1. Multi App Engine
2
+
3
+ Similar to "enginex":https://github.com/josevalim/enginex but can generate and setup multiple individual dummy apps (configured for either Mongoid or Active Record) for testing your gem.
4
+
5
+ h2. Usage
6
+
7
+ @$ mengine ENGINE_NAME [options]@
8
+
9
+ Use _--help_ to see supported options.
10
+
11
+ h2. Example usage
12
+
13
+ Create a default engine called 'MyEngine'
14
+
15
+ @$ mengine my-engine@
16
+
17
+ Dummy apps:
18
+ * _dummy-active_record_
19
+
20
+ h2. Dummies for ORMs
21
+
22
+ Create engine named 'MyEngine' and dummy apps configured for A.R and Mongoid
23
+
24
+ @$ mengine my-engine --orms mongoid ar@
25
+
26
+ Dummy apps:
27
+ * _dummy-mongoid_
28
+ * _dummy-active_record_
29
+
30
+ h2. Testing framework
31
+
32
+ Create engine named 'Demox' and a single dummy app configured for Mongoid.
33
+ Use Rspec as the testing framework for the engine.
34
+
35
+ @$ mengine demox --orms mongoid -t rspec@
36
+
37
+ Dummy apps:
38
+ * dummy-mongoid
39
+
40
+ h2. Dummy application types
41
+
42
+ Create engine named 'Demox' and create dummy apps for cancan and devise (types).
43
+ For each type create dummy apps for A.R and Mongoid. Use Rspec as the testing framework.
44
+
45
+ @$ mengine demo --orms mongoid ar --types cancan devise -t rspec@
46
+
47
+ Dummy apps:
48
+ * _dummy-cancan-mongoid_
49
+ * _dummy-cancan-active_record_
50
+ * _dummy-devise-mongoid_
51
+ * _dummy-devise-active_record_
52
+
53
+ h2. Bugs and Feedback
54
+
55
+ If you discover any bugs, feel free to send me a message or create an issue on GitHub tracker
56
+
57
+ MIT License. Copyright 2011 Kristian Mandrup
@@ -0,0 +1,43 @@
1
+ # encoding: UTF-8
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ require 'rake/rdoctask'
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << 'lib'
8
+ t.libs << 'test'
9
+ t.pattern = 'test/*_test.rb'
10
+ t.verbose = true
11
+ end
12
+
13
+ Rake::RDocTask.new(:rdoc) do |rdoc|
14
+ rdoc.rdoc_dir = 'rdoc'
15
+ rdoc.title = 'Multi Engine'
16
+ rdoc.options << '--line-numbers' << '--inline-source'
17
+ rdoc.rdoc_files.include('README.rdoc')
18
+ rdoc.rdoc_files.include('lib/**/*.rb')
19
+ end
20
+
21
+ begin
22
+ require 'jeweler'
23
+ Jeweler::Tasks.new do |s|
24
+ s.name = "multiengine"
25
+ s.version = "0.5.0"
26
+ s.summary = "Creates a Rails 3 engine configuration with multiple dummy apps for testing"
27
+ s.email = "kmandrup@gmail.com"
28
+ s.homepage = "http://github.com/kristianmandrup/multiapp-engine"
29
+ s.description = "Creates a Rails 3 engine configuration with multiple dummy apps and test framework configured and ready to go"
30
+ s.authors = ['Kristian Mandrup']
31
+ s.files = FileList["[A-Z]*", "lib/**/*", "bin/*"]
32
+ s.bindir = "bin"
33
+ s.executables = %w(mengine)
34
+ s.add_dependency "thor", "~> 0.14.6"
35
+ s.add_dependency "rails", "~> 3.1.0.rc1"
36
+ s.add_dependency "rake", "~> 0.9"
37
+ s.add_dependency "sugar-high", "~> 0.4"
38
+ end
39
+
40
+ Jeweler::GemcutterTasks.new
41
+ rescue LoadError
42
+ puts "Jeweler, or one of its dependencies, is not available. Install it with: gem install jeweler"
43
+ end
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- mode: ruby -*-
3
+
4
+ require 'multi_engine'
5
+
6
+ ARGV << "--help" if ARGV.empty?
7
+
8
+ MultiEngine.start
@@ -0,0 +1,355 @@
1
+ require "thor/group"
2
+ require "active_support"
3
+ require "active_support/version"
4
+ require "active_support/core_ext/string"
5
+
6
+ require "rails/generators"
7
+ require "rails/generators/rails/app/app_generator"
8
+
9
+ require "sugar-high/file"
10
+ require 'fileutils'
11
+
12
+ class MultiEngine < Thor::Group
13
+ include Thor::Actions
14
+ check_unknown_options!
15
+
16
+ def self.source_root
17
+ @_source_root ||= File.expand_path('../templates', __FILE__)
18
+ end
19
+
20
+ def self.say_step(message)
21
+ @step = (@step || 0) + 1
22
+ class_eval <<-METHOD, __FILE__, __LINE__ + 1
23
+ def step_#{@step}
24
+ #{"puts" if @step > 1}
25
+ say_status "STEP #{@step}", #{message.inspect}
26
+ end
27
+ METHOD
28
+ end
29
+
30
+ argument :path, :type => :string,
31
+ :desc => "Path to the engine to be created"
32
+
33
+ class_option :test_framework, :default => "rspec", :aliases => "-t",
34
+ :desc => "Test framework to use. test_unit or rspec."
35
+
36
+ class_option :orms, :type => :array, :default => [],
37
+ :desc => "Datastore frameworks to use. mongoid or active_record."
38
+
39
+ class_option :types, :type => :array, :default => [],
40
+ :desc => "Dummy application names"
41
+
42
+ class_option :tu, :type => :boolean, :default => true,
43
+ :desc => "Skip testunit generation for dummy apps."
44
+
45
+ class_option :js, :type => :boolean, :default => true,
46
+ :desc => "Skip javascript generation for dummy apps."
47
+
48
+
49
+ desc "Creates a Rails 3 engine with Rakefile, Gemfile and running tests."
50
+
51
+ say_step "Creating gem skeleton"
52
+
53
+ def create_root
54
+ self.destination_root = File.expand_path(path, destination_root)
55
+ set_accessors!
56
+
57
+ directory "root", "."
58
+ FileUtils.cd(destination_root)
59
+ end
60
+
61
+ def create_tests_or_specs
62
+ directory test_path
63
+ end
64
+
65
+ def change_gitignore
66
+ template "gitignore", ".gitignore"
67
+ end
68
+
69
+ def invoke_rails_app_generators
70
+ say "Vendoring Rails applications at #{test_path}/dummy-apps"
71
+ types.each do |type|
72
+ say "Creating #{type} apps"
73
+ self.current_type = type
74
+ orms.each do |orm|
75
+ self.current_orm = translate(orm)
76
+
77
+ say "Creating #{type} dummy Rails app with #{orm_name}", :green
78
+ # say "Location: #{dummy_app_path}"
79
+ command = "rails new #{app_args.join(' ')} -f" # force overwrite
80
+ say command
81
+
82
+ exec_command command
83
+
84
+ #invoke Rails::Generators::AppGenerator, app_args
85
+
86
+ say "Configuring Rails app"
87
+ change_config_files
88
+
89
+ # say "Removing unneeded files"
90
+ remove_uneeded_rails_files
91
+
92
+ send orm_config_method if respond_to?(orm_config_method)
93
+
94
+ say "Configuring testing framework for #{orm_name}"
95
+ set_orm_helpers
96
+
97
+ ensure_app_class_name
98
+
99
+ FileUtils.cd(destination_root)
100
+ end
101
+ end
102
+ end
103
+
104
+ protected
105
+
106
+ attr_accessor :current_orm, :current_type
107
+
108
+ def ensure_app_class_name
109
+ File.replace_content_from application_file, :where => /Dummy\S+/, :with => dummy_app_class_name
110
+ end
111
+
112
+ def orm_name
113
+ translate current_orm
114
+ end
115
+
116
+ def translate orm
117
+ case orm.to_sym
118
+ when :ar
119
+ 'active_record'
120
+ else
121
+ orm
122
+ end
123
+ end
124
+
125
+ def dummy_app_path
126
+ dummy_path
127
+ end
128
+
129
+ def dummy_app_name
130
+ name = "dummy"
131
+ name << "-#{current_type}" if current_type && !current_type.blank?
132
+ name << "-#{current_orm}"
133
+ name
134
+ end
135
+
136
+ def dummy_path
137
+ "#{test_path}/dummy-apps/#{dummy_app_name}"
138
+ end
139
+
140
+ def orms
141
+ @orms ||= !options[:orms].empty? ? options[:orms] : ['active_record']
142
+ end
143
+
144
+ def types
145
+ @types ||= !options[:types].empty? ? options[:types] : [""]
146
+ end
147
+
148
+ def set_orm_helpers
149
+ # say "Configuring testing files for #{current_orm} app"
150
+ inside test_path do
151
+ unless File.directory? dummy_app_integration_test_dir
152
+ empty_directory dummy_app_integration_test_dir
153
+ end
154
+
155
+ copy_orm_helper
156
+
157
+ if File.exist?(navigation_file) || File.exist?(dummy_file)
158
+ # say "Copying test files into /#{dummy_app_name}"
159
+ copy_test_files navigation_file, dummy_file
160
+ inside app_specs_dummy_dir do
161
+ # say "Inside #{app_specs_dummy_dir}"
162
+ replace_orm_in navigation_file
163
+ replace_orm_in dummy_file
164
+ end
165
+ end
166
+ end
167
+ end
168
+
169
+ def copy_orm_helper
170
+ file = "#{current_orm}_helper.rb"
171
+ target_file = "#{app_specs_dummy_dir}/#{file}"
172
+ # say "From #{test_helper_path} copy"
173
+ FileUtils.cp("#{test_helper_path}/orm/#{file}", target_file)
174
+ File.replace_content_from target_file, :where => '#dummy_app_name#', :with => dummy_app_name
175
+ end
176
+
177
+ def test_helper_path
178
+ File.join(File.dirname(__FILE__), 'test_helpers', test_path).gsub /.+\/\//, ''
179
+ end
180
+
181
+ def app_specs_dummy_dir
182
+ "app_specs/#{dummy_app_name}"
183
+ end
184
+
185
+ def dummy_app_integration_test_dir
186
+ "#{app_specs_dummy_dir}/integration"
187
+ end
188
+
189
+ def copy_test_files *files
190
+ files.each do |file|
191
+ target_file = "#{app_specs_dummy_dir}/#{file}"
192
+ src_file = File.join(test_helper_path, file)
193
+ # say "Copy #{file} to #{target_file}"
194
+ FileUtils.cp(src_file, target_file) if File.exist?(file)
195
+ end
196
+ end
197
+
198
+ def replace_orm_in file
199
+ return if !File.exist?(file)
200
+ # say "Replacing #orm# with #{current_orm} inside #{file}"
201
+ File.replace_content_from file, :where => '#orm#', :with => current_orm
202
+ File.replace_content_from file, :where => '#path#', :with => app_specs_dummy_dir
203
+ File.replace_content_from file, :where => '#camelized#', :with => dummy_app_class_name
204
+ end
205
+
206
+ def navigation_file
207
+ "integration/navigation_#{test_ext}.rb"
208
+ end
209
+
210
+ def dummy_file
211
+ "dummy_#{test_ext}.rb"
212
+ end
213
+
214
+ def dummy_app_test_path
215
+ File.join(dummy_app_path, test_path)
216
+ end
217
+
218
+ def orm_config_method
219
+ "config_#{current_orm}"
220
+ end
221
+
222
+ def config_mongoid
223
+ return if !current_orm == 'mongoid'
224
+
225
+ say "Configuring app for #{current_orm}"
226
+ inside dummy_app_path do
227
+ gemfile = 'Gemfile'
228
+
229
+ # File.insert_into gemfile, :after => 'gem "sqlite3"' do
230
+ # %q{gem "mongoid"
231
+ # gem "bson_ext"
232
+ # }
233
+ # end
234
+
235
+ append_to_file gemfile do
236
+ %q{gem "mongoid"
237
+ gem "bson_ext"
238
+ }
239
+ end
240
+ File.remove_content_from gemfile, :where => 'gem "sqlite3"'
241
+
242
+ if File.exist? 'config/database.yml'
243
+ # say "Delete database.yml"
244
+ File.delete! 'config/database.yml'
245
+ end
246
+
247
+ # say "Remove active record from #{application_file}"
248
+ File.remove_content_from 'config/application.rb', :where => 'require "active_record/railtie"'
249
+
250
+ exec_command 'bundle install'
251
+ exec_command 'rails g mongoid:config'
252
+ end
253
+ end
254
+
255
+ def exec_command command
256
+ Kernel::system command
257
+ end
258
+
259
+ def remove_uneeded_rails_files
260
+ inside dummy_app_path do
261
+ remove_file ".gitignore"
262
+ # remove_file "db/seeds.rb"
263
+ remove_file "doc"
264
+ # remove_file "Gemfile"
265
+ remove_file "lib/tasks"
266
+ remove_file "public/images/rails.png"
267
+ remove_file "public/index.html"
268
+ remove_file "public/robots.txt"
269
+ remove_file "README"
270
+ remove_file "test"
271
+ remove_file "vendor"
272
+ end
273
+ end
274
+
275
+ def change_config_files
276
+ store_application_definition!
277
+ template "rails/boot.rb", "#{dummy_app_path}/config/boot.rb", :force => true
278
+ template "rails/application.rb", "#{dummy_app_path}/config/application.rb", :force => true
279
+ end
280
+
281
+ def app_args
282
+ args = [dummy_app_path] # skip test unit
283
+ args << "-T" if skip_testunit?
284
+ args << "-J" if skip_javascript?
285
+ # skip active record is orm is set to another datastore
286
+ args << "-O" if !active_record?
287
+ args
288
+ end
289
+
290
+ def active_record?
291
+ !current_orm || ['active_record', 'ar'].include?(current_orm)
292
+ end
293
+
294
+ def skip_testunit?
295
+ options[:tu]
296
+ end
297
+
298
+ def skip_javascript?
299
+ options[:js]
300
+ end
301
+
302
+ def rspec?
303
+ options[:test_framework] == "rspec"
304
+ end
305
+
306
+ def test_unit?
307
+ options[:test_framework] == "test_unit"
308
+ end
309
+
310
+ def test_path
311
+ rspec? ? "spec" : "test"
312
+ end
313
+ alias_method :test_ext, :test_path
314
+
315
+ def self.banner
316
+ self_task.formatted_usage(self, false)
317
+ end
318
+
319
+ def application_definition
320
+ contents = File.read(config_app_file)
321
+ index = (contents.index("module #{dummy_app_class_name}")) || 0
322
+ contents[index..-1]
323
+ end
324
+ alias :store_application_definition! :application_definition
325
+
326
+ def dummy_app_class_name
327
+ dummy_app_name.underscore.camelize
328
+ end
329
+
330
+ def config_app_file
331
+ File.expand_path(application_file, destination_root)
332
+ end
333
+
334
+ def application_file
335
+ "#{dummy_app_path}/config/application.rb"
336
+ end
337
+
338
+ # Cache accessors since we are changing the directory
339
+ def set_accessors!
340
+ self.name
341
+ self.class.source_root
342
+ end
343
+
344
+ def name
345
+ @name ||= File.basename(destination_root)
346
+ end
347
+
348
+ def camelized
349
+ @camelized ||= underscored.camelize
350
+ end
351
+
352
+ def underscored
353
+ @underscored ||= name.underscore
354
+ end
355
+ end
@@ -0,0 +1,6 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ <%= test_path %>/dummy/db/*.sqlite3
5
+ <%= test_path %>/dummy/log/*.log
6
+ <%= test_path %>/dummy/tmp/
@@ -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 "<%= underscored %>"
11
+
12
+ <%= application_definition %>
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ dir = '../../../../../'
3
+ gemfile = File.expand_path("#{dir}Gemfile", __FILE__)
4
+
5
+ if File.exist?(gemfile)
6
+ ENV['BUNDLE_GEMFILE'] = gemfile
7
+ require 'bundler'
8
+ Bundler.setup
9
+ end
10
+
11
+ $:.unshift File.expand_path("#{dir}lib", __FILE__)
@@ -0,0 +1,9 @@
1
+ # Provide a simple gemspec so you can easily use your enginex
2
+ # project in your rails apps through git.
3
+ Gem::Specification.new do |s|
4
+ s.name = "<%= underscored %>"
5
+ s.summary = "Insert <%= camelized %> summary."
6
+ s.description = "Insert <%= camelized %> description."
7
+ s.files = Dir["{app,lib,config}/**/*"] + ["MIT-LICENSE", "Rakefile", "Gemfile", "README.rdoc"]
8
+ s.version = "0.0.1"
9
+ end
@@ -0,0 +1,12 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "rails", "<%= ActiveSupport::VERSION::STRING %>"
4
+ gem "capybara", ">= 0.4.0"
5
+ gem "sqlite3"
6
+ <%- if rspec? %>
7
+ gem "rspec-rails", ">= 2.0.0.beta"
8
+ <% end -%>
9
+
10
+ # To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
11
+ # gem 'ruby-debug'
12
+ # gem 'ruby-debug19'
@@ -0,0 +1,20 @@
1
+ Copyright <%= Date.today.year %> YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,3 @@
1
+ = <%= camelized %>
2
+
3
+ This project rocks and uses MIT-LICENSE.
@@ -0,0 +1,36 @@
1
+ # encoding: UTF-8
2
+ require 'rubygems'
3
+ begin
4
+ require 'bundler/setup'
5
+ rescue LoadError
6
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
8
+
9
+ require 'rake'
10
+ require 'rake/rdoctask'
11
+
12
+ <% if rspec? -%>
13
+ require 'rspec/core'
14
+ require 'rspec/core/rake_task'
15
+
16
+ RSpec::Core::RakeTask.new(:spec)
17
+ <% else -%>
18
+ require 'rake/testtask'
19
+
20
+ Rake::TestTask.new(:test) do |t|
21
+ t.libs << 'lib'
22
+ t.libs << 'test'
23
+ t.pattern = 'test/**/*_test.rb'
24
+ t.verbose = false
25
+ end
26
+ <% end -%>
27
+
28
+ task :default => :<%= test_path %>
29
+
30
+ Rake::RDocTask.new(:rdoc) do |rdoc|
31
+ rdoc.rdoc_dir = 'rdoc'
32
+ rdoc.title = '<%= camelized %>'
33
+ rdoc.options << '--line-numbers' << '--inline-source'
34
+ rdoc.rdoc_files.include('README.rdoc')
35
+ rdoc.rdoc_files.include('lib/**/*.rb')
36
+ end
@@ -0,0 +1,2 @@
1
+ module <%= camelized %>
2
+ end
@@ -0,0 +1,20 @@
1
+ # Load support files
2
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
3
+
4
+ RSpec.configure do |config|
5
+ # Remove this line if you don't want RSpec's should and should_not
6
+ # methods or matchers
7
+ require 'rspec/expectations'
8
+ config.include RSpec::Matchers
9
+
10
+ # == Mock Framework
11
+ config.mock_with :rspec
12
+
13
+ # # include MyHelpers module in every acceptance spec
14
+ # config.include MyHelpers, :type => :acceptance
15
+ #
16
+ # config.before(:each, :type => :acceptance) do
17
+ # # Some code to run before any acceptance spec
18
+ # end
19
+
20
+ end
@@ -0,0 +1,33 @@
1
+ # Configure Rails Envinronment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
+ require "rails/test_help"
6
+ require "rspec/rails"
7
+
8
+ ActionMailer::Base.delivery_method = :test
9
+ ActionMailer::Base.perform_deliveries = true
10
+ ActionMailer::Base.default_url_options[:host] = "test.com"
11
+
12
+ Rails.backtrace_cleaner.remove_silencers!
13
+
14
+ # Configure capybara for integration testing
15
+ require "capybara/rails"
16
+ Capybara.default_driver = :rack_test
17
+ Capybara.default_selector = :css
18
+
19
+ # Run any available migration
20
+ ActiveRecord::Migrator.migrate File.expand_path("../dummy/db/migrate/", __FILE__)
21
+
22
+ # Load support files
23
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
24
+
25
+ RSpec.configure do |config|
26
+ # Remove this line if you don't want RSpec's should and should_not
27
+ # methods or matchers
28
+ require 'rspec/expectations'
29
+ config.include RSpec::Matchers
30
+
31
+ # == Mock Framework
32
+ config.mock_with :rspec
33
+ end
@@ -0,0 +1,13 @@
1
+ require "rails/test_help"
2
+ require "rspec/rails"
3
+
4
+ ActionMailer::Base.delivery_method = :test
5
+ ActionMailer::Base.perform_deliveries = true
6
+ ActionMailer::Base.default_url_options[:host] = "test.com"
7
+
8
+ Rails.backtrace_cleaner.remove_silencers!
9
+
10
+ # Configure capybara for integration testing
11
+ require "capybara/rails"
12
+ Capybara.default_driver = :rack_test
13
+ Capybara.default_selector = :css
@@ -0,0 +1,7 @@
1
+ require 'orm/#orm#_helper'
2
+
3
+ class <%= camelized %>Test < ActiveSupport::TestCase
4
+ test "truth" do
5
+ assert_kind_of Module, <%= camelized %>
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ # Load support files
2
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
3
+
@@ -0,0 +1,15 @@
1
+ # Configure Rails Envinronment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require "rails/test_help"
5
+
6
+ ActionMailer::Base.delivery_method = :test
7
+ ActionMailer::Base.perform_deliveries = true
8
+ ActionMailer::Base.default_url_options[:host] = "test.com"
9
+
10
+ Rails.backtrace_cleaner.remove_silencers!
11
+
12
+ # Configure capybara for integration testing
13
+ require "capybara/rails"
14
+ Capybara.default_driver = :rack_test
15
+ Capybara.default_selector = :css
@@ -0,0 +1,7 @@
1
+ require 'orm/#orm#_helper'
2
+
3
+ class NavigationTest < ActiveSupport::IntegrationCase
4
+ test "truth" do
5
+ assert_kind_of Dummy::Application, Rails.application
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ # Configure Rails Envinronment
2
+ ENV["RAILS_ENV"] = "test"
3
+ require File.expand_path("../../dummy_apps/<%= current_app_name %>/config/environment.rb", __FILE__)
4
+
5
+ require 'spec_helper/init'
6
+
7
+ # Run any available migration
8
+ migrations_dir = File.expand_path("../../dummy-apps/<%= current_app_name %>/db/migrate/", __FILE__)
9
+
10
+ ActiveRecord::Migrator.migrate migrations_dir
11
+
12
+ require 'spec_helper/config'
@@ -0,0 +1,4 @@
1
+ # Configure Rails Envinronment
2
+ ENV["RAILS_ENV"] = "test"
3
+ require 'spec_helper/init'
4
+ require 'spec_helper/config'
@@ -0,0 +1,5 @@
1
+ # Define a bare test case to use with Capybara
2
+ class ActiveSupport::IntegrationCase < ActiveSupport::TestCase
3
+ include Capybara
4
+ include Rails.application.routes.url_helpers
5
+ end
@@ -0,0 +1,22 @@
1
+ # Configure Rails Envinronment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
+ require "rails/test_help"
6
+
7
+ ActionMailer::Base.delivery_method = :test
8
+ ActionMailer::Base.perform_deliveries = true
9
+ ActionMailer::Base.default_url_options[:host] = "test.com"
10
+
11
+ Rails.backtrace_cleaner.remove_silencers!
12
+
13
+ # Configure capybara for integration testing
14
+ require "capybara/rails"
15
+ Capybara.default_driver = :rack_test
16
+ Capybara.default_selector = :css
17
+
18
+ # Run any available migration
19
+ ActiveRecord::Migrator.migrate File.expand_path("../dummy/db/migrate/", __FILE__)
20
+
21
+ # Load support files
22
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
@@ -0,0 +1,7 @@
1
+ require '#path#/#orm#_helper'
2
+
3
+ describe #camelized# do
4
+ it "should be valid" do
5
+ #camelized#.should be_a(Module)
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ require '#path#/#orm#_helper'
2
+
3
+ describe "Navigation" do
4
+ include Capybara
5
+
6
+ it "should be a valid app" do
7
+ ::Rails.application.should be_a(#camelized#::Application)
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ # Configure Rails Envinronment
2
+ ENV["RAILS_ENV"] = "test"
3
+ require 'dummy-apps/#dummy_app_name#/config/environment.rb'
4
+ require 'spec_init'
5
+ # Run any available migration
6
+ ActiveRecord::Migrator.migrate 'dummy-apps/#dummy_app_name#/db/migrate'
7
+ require 'spec_config'
@@ -0,0 +1,5 @@
1
+ # Configure Rails Envinronment
2
+ ENV["RAILS_ENV"] = "test"
3
+ require 'dummy-apps/#dummy_app_name#/config/environment.rb'
4
+ require 'spec_init'
5
+ require 'spec_config'
@@ -0,0 +1,256 @@
1
+ require "thor/group"
2
+ require "active_support"
3
+ require "active_support/version"
4
+ require "active_support/core_ext/string"
5
+
6
+ require "rails/generators"
7
+ require "rails/generators/rails/app/app_generator"
8
+
9
+ require "sugar-high/file"
10
+ require 'fileutils'
11
+
12
+ class DummyApp < Thor::Group
13
+ include Thor::Actions
14
+ check_unknown_options!
15
+
16
+ def self.source_root
17
+ @_source_root ||= File.expand_path('../templates', __FILE__)
18
+ end
19
+
20
+ argument :types, :type => :array, :default => [], :desc => "Dummy application names"
21
+
22
+ class_option :test_framework, :default => "test_unit", :aliases => "-t",
23
+ :desc => "Test framework to use. test_unit or rspec."
24
+
25
+ class_option :orms, :type => :array, :default => [],
26
+ :desc => "Datastore frameworks to use. mongoid or active_record."
27
+
28
+
29
+ class_option :tu, :type => :boolean, :default => true,
30
+ :desc => "Skip testunit generation for dummy apps."
31
+
32
+ class_option :js, :type => :boolean, :default => true,
33
+ :desc => "Skip javascript generation for dummy apps."
34
+
35
+
36
+ desc "Creates a Rails 3 engine with Rakefile, Gemfile and running tests."
37
+
38
+
39
+ def invoke_rails_app_generators
40
+ if !File.directory? "dummy-apps"
41
+ say "xdummy must be run from the Rails application root or the test/rspec folder", :red
42
+ end
43
+
44
+ FileUtils.cd "dummy-apps"
45
+
46
+ say "Vendoring Rails applications at #{test_path}/dummy-apps"
47
+ types.each do |type|
48
+ say "Creating #{type} apps"
49
+ @current_type = type
50
+ orms.each do |orm|
51
+ @current_orm = translate(orm)
52
+
53
+ say "Creating dummy Rails app with #{orm}"
54
+ invoke Rails::Generators::AppGenerator, app_args
55
+
56
+ say "Configuring Rails app"
57
+ change_config_files
58
+
59
+ say "Removing unneeded files"
60
+ remove_uneeded_rails_files
61
+
62
+ send orm_config_method if respond_to?(orm_config_method)
63
+
64
+ say "Configuring testing framework for #{orm}"
65
+ set_orm_helpers
66
+
67
+ FileUtils.cd(destination_root)
68
+ end
69
+ end
70
+ end
71
+
72
+ protected
73
+
74
+ attr_reader :current_orm, :current_type
75
+
76
+ def
77
+ !File.directory? "dummy-apps"
78
+
79
+ def translate orm
80
+ case orm.to_sym
81
+ when :ar
82
+ 'active_record'
83
+ else
84
+ orm
85
+ end
86
+ end
87
+
88
+ def dummy_app_path
89
+ File.expand_path(dummy_path, destination_root)
90
+ end
91
+
92
+ def dummy_app_name
93
+ name = "dummy-#{current_orm}"
94
+ name << "-#{current_type}" if current_type && !current_type.blank?
95
+ name
96
+ end
97
+
98
+ def dummy_path
99
+ "dummy-apps/#{dummy_app_name}"
100
+ end
101
+
102
+ def orms
103
+ @orms ||= options[:orms] || ['active_record']
104
+ end
105
+
106
+ def set_orm_helpers
107
+ say "Configuring testing files for #{current_orm} app"
108
+ inside test_path do
109
+ unless File.directory? dummy_app_integration_test_dir
110
+ empty_directory dummy_app_integration_test_dir
111
+ end
112
+ if File.exist?(navigation_file) || File.exist?(underscored_file)
113
+ say "Moving test files into /#{dummy_app_name}"
114
+ move_test_files navigation_file, underscored_file
115
+ inside dummy_app_name do
116
+ replace_orm_in navigation_file
117
+ replace_orm_in underscored_file
118
+ end
119
+ end
120
+ end
121
+ end
122
+
123
+ def dummy_app_integration_test_dir
124
+ "#{dummy_app_name}/integration"
125
+ end
126
+
127
+ def navigation_file
128
+ "integration/navigation_#{test_ext}.rb"
129
+ end
130
+
131
+ def underscored_file
132
+ "#{underscored}_#{test_ext}.rb"
133
+ end
134
+
135
+ def move_test_files *files
136
+ files.each do |file|
137
+ FileUtils.mv(file, "#{dummy_app_name}/#{file}") if File.exist?(file)
138
+ end
139
+ end
140
+
141
+ def replace_orm_in file
142
+ return if !File.exist?(file)
143
+ File.replace_content_from file, :where => '#orm#', :with => current_orm
144
+ end
145
+
146
+ def dummy_app_test_path
147
+ File.join(dummy_app_path, test_path)
148
+ end
149
+
150
+ def orm_config_method
151
+ "config_#{current_orm}"
152
+ end
153
+
154
+ def config_mongoid
155
+ return if !current_orm == 'mongoid'
156
+
157
+ say "Configuring app for #{current_orm}"
158
+ inside dummy_app_path do
159
+ gemfile = 'Gemfile'
160
+ File.insert_into gemfile, :after => 'gem "sqlite3"' do
161
+ %q{gem "mongoid"
162
+ gem "bson_ext"
163
+ }
164
+ end
165
+ File.remove_content_from gemfile, :where => 'gem "sqlite3"'
166
+ `bundle install`
167
+ `rails g mongoid:config`
168
+ end
169
+ end
170
+
171
+ def remove_uneeded_rails_files
172
+ inside dummy_app_path do
173
+ remove_file ".gitignore"
174
+ # remove_file "db/seeds.rb"
175
+ remove_file "doc"
176
+ # remove_file "Gemfile"
177
+ remove_file "lib/tasks"
178
+ remove_file "public/images/rails.png"
179
+ remove_file "public/index.html"
180
+ remove_file "public/robots.txt"
181
+ remove_file "README"
182
+ remove_file "test"
183
+ remove_file "vendor"
184
+ end
185
+ end
186
+
187
+ def change_config_files
188
+ store_application_definition!
189
+ template "rails/boot.rb", "#{dummy_app_path}/config/boot.rb", :force => true
190
+ template "rails/application.rb", "#{dummy_app_path}/config/application.rb", :force => true
191
+ end
192
+
193
+ def app_args
194
+ args = [dummy_app_path, "-T"] # skip test unit
195
+ args << "-T" if skip_testunit?
196
+ args << "-J" if skip_javascript?
197
+ # skip active record is orm is set to another datastore
198
+ args << "-O" if !active_record?
199
+ args
200
+ end
201
+
202
+ def active_record?
203
+ !current_orm || ['active_record', 'ar'].include?(current_orm)
204
+ end
205
+
206
+ def skip_testunit?
207
+ options[:tu]
208
+ end
209
+
210
+ def skip_javascript?
211
+ options[:js]
212
+ end
213
+
214
+ def rspec?
215
+ options[:test_framework] == "rspec"
216
+ end
217
+
218
+ def test_unit?
219
+ options[:test_framework] == "test_unit"
220
+ end
221
+
222
+ def test_path
223
+ rspec? ? "spec" : "test"
224
+ end
225
+ alias_method :test_ext, :test_path
226
+
227
+ def self.banner
228
+ self_task.formatted_usage(self, false)
229
+ end
230
+
231
+ def application_definition
232
+ @application_definition ||= begin
233
+ contents = File.read(File.expand_path("#{dummy_app_path}/config/application.rb", destination_root))
234
+ contents[(contents.index("module Dummy"))..-1]
235
+ end
236
+ end
237
+ alias :store_application_definition! :application_definition
238
+
239
+ # Cache accessors since we are changing the directory
240
+ def set_accessors!
241
+ self.name
242
+ self.class.source_root
243
+ end
244
+
245
+ def name
246
+ @name ||= File.basename(destination_root)
247
+ end
248
+
249
+ def camelized
250
+ @camelized ||= name.camelize
251
+ end
252
+
253
+ def underscored
254
+ @underscored ||= name.underscore
255
+ end
256
+ end
metadata ADDED
@@ -0,0 +1,166 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: multiengine
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kristian Mandrup
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-05-24 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sqlite3
16
+ requirement: &2156671740 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2156671740
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &2156671200 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '2.5'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *2156671200
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec-rails
38
+ requirement: &2156670640 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '2.5'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *2156670640
47
+ - !ruby/object:Gem::Dependency
48
+ name: capybara
49
+ requirement: &2156670060 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '0.4'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *2156670060
58
+ - !ruby/object:Gem::Dependency
59
+ name: thor
60
+ requirement: &2156669420 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 0.14.6
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: *2156669420
69
+ - !ruby/object:Gem::Dependency
70
+ name: rails
71
+ requirement: &2156668880 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: 3.1.0.rc1
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: *2156668880
80
+ - !ruby/object:Gem::Dependency
81
+ name: rake
82
+ requirement: &2156668360 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ version: '0.9'
88
+ type: :runtime
89
+ prerelease: false
90
+ version_requirements: *2156668360
91
+ - !ruby/object:Gem::Dependency
92
+ name: sugar-high
93
+ requirement: &2156667800 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ~>
97
+ - !ruby/object:Gem::Version
98
+ version: '0.4'
99
+ type: :runtime
100
+ prerelease: false
101
+ version_requirements: *2156667800
102
+ description: Creates a Rails 3 engine configuration with multiple dummy apps and test
103
+ framework configured and ready to go
104
+ email: kmandrup@gmail.com
105
+ executables:
106
+ - mengine
107
+ extensions: []
108
+ extra_rdoc_files:
109
+ - README.textile
110
+ files:
111
+ - Gemfile
112
+ - MIT-LICENSE
113
+ - README.textile
114
+ - Rakefile
115
+ - bin/mengine
116
+ - lib/multi_engine.rb
117
+ - lib/templates/gitignore
118
+ - lib/templates/rails/application.rb
119
+ - lib/templates/rails/boot.rb
120
+ - lib/templates/root/%underscored%.gemspec.tt
121
+ - lib/templates/root/Gemfile.tt
122
+ - lib/templates/root/MIT-LICENSE.tt
123
+ - lib/templates/root/README.rdoc.tt
124
+ - lib/templates/root/Rakefile.tt
125
+ - lib/templates/root/lib/%underscored%.rb.tt
126
+ - lib/templates/spec/spec_config.rb.tt
127
+ - lib/templates/spec/spec_helper.rb
128
+ - lib/templates/spec/spec_init.rb.tt
129
+ - lib/templates/test/%underscored%_test.rb.tt
130
+ - lib/templates/test/config.rb.tt
131
+ - lib/templates/test/init.rb.tt
132
+ - lib/templates/test/integration/navigation_test.rb.tt
133
+ - lib/templates/test/orm/active_record_helper.rb.tt
134
+ - lib/templates/test/orm/mongoid_helper.rb.tt
135
+ - lib/templates/test/support/integration_case.rb
136
+ - lib/templates/test/test_helper.rb
137
+ - lib/test_helpers/spec/dummy_spec.rb
138
+ - lib/test_helpers/spec/integration/navigation_spec.rb
139
+ - lib/test_helpers/spec/orm/active_record_helper.rb
140
+ - lib/test_helpers/spec/orm/mongoid_helper.rb
141
+ - lib/xdummy.rb.inprogress
142
+ homepage: http://github.com/kristianmandrup/multiapp-engine
143
+ licenses: []
144
+ post_install_message:
145
+ rdoc_options: []
146
+ require_paths:
147
+ - lib
148
+ required_ruby_version: !ruby/object:Gem::Requirement
149
+ none: false
150
+ requirements:
151
+ - - ! '>='
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ required_rubygems_version: !ruby/object:Gem::Requirement
155
+ none: false
156
+ requirements:
157
+ - - ! '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ requirements: []
161
+ rubyforge_project:
162
+ rubygems_version: 1.8.3
163
+ signing_key:
164
+ specification_version: 3
165
+ summary: Creates a Rails 3 engine configuration with multiple dummy apps for testing
166
+ test_files: []