engine_cart 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +25 -14
- data/Rakefile +18 -2
- data/lib/engine_cart.rb +47 -2
- data/lib/engine_cart/tasks/engine_cart.rake +34 -32
- data/lib/engine_cart/version.rb +1 -1
- data/lib/generators/engine_cart/install_generator.rb +60 -0
- data/spec/integration/engine_cart_spec.rb +48 -1
- metadata +4 -9
- data/lib/generators/engine_cart/engine_cart_generator.rb +0 -42
- data/spec/test_app_templates/Gemfile.extra +0 -0
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cfba3a7001960007e707eeb273a884ea0660d53e
|
4
|
+
data.tar.gz: 85c1f0df4dd3264fd0aecf3927b5c61cace587f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b245365eed9f9bb511641d9f543e48281e6e406b3a6394be326892294933fe7515b699d83fefaead2c8e9dd57d8073bf1205ef4319e8840dca0bc2eff6f8fef4
|
7
|
+
data.tar.gz: e28e5f5c22d33c4805fb01b0d9ef378d8c9255da47f25f4b772de4786937268df63ba426924ef58a3e16dea76fad26d897499602001d9f5558e33a6978d7e08b
|
data/README.md
CHANGED
@@ -1,6 +1,17 @@
|
|
1
1
|
# EngineCart
|
2
2
|
|
3
|
-
|
3
|
+
Rake tasks to generate a test application for a Rails Engine gem.
|
4
|
+
|
5
|
+
If you have a Rails Engine and want to test it, the suggested approach is a small dummy application that loads up a Rails application with your engine loaded. This dummy application is usually checked into source control and maintained with the application. This works great, until you want to test:
|
6
|
+
|
7
|
+
- different versions of Ruby (e.g. MRI and JRuby)
|
8
|
+
- different versions of Rails (Rails 3.x, 4.0 and 4.1)
|
9
|
+
- different deployment environments (with and without devise, etc)
|
10
|
+
|
11
|
+
where each scenario may involve different configurations, Gemfiles, etc.
|
12
|
+
|
13
|
+
EngineCart helps by adding Rake tasks to your Engine that builds a test application for you using Rails generators (and/or application templates).
|
14
|
+
|
4
15
|
|
5
16
|
## Installation
|
6
17
|
|
@@ -16,17 +27,22 @@ Or install it yourself as:
|
|
16
27
|
|
17
28
|
$ gem install engine_cart
|
18
29
|
|
19
|
-
|
20
30
|
## Usage
|
21
31
|
|
32
|
+
Engine Cart comes with a generator to set up your engine to use Engine Cart. It is also packaged as a rake task:
|
33
|
+
|
34
|
+
```
|
35
|
+
$ rake engine_cart:prepare
|
36
|
+
```
|
37
|
+
|
22
38
|
In your Rakefile you can generate the Rails application using, e.g.:
|
23
39
|
|
24
40
|
```ruby
|
25
|
-
|
41
|
+
require 'engine_cart/rake_task'
|
26
42
|
|
27
|
-
|
28
|
-
|
29
|
-
|
43
|
+
task :ci => ['engine_cart:generate'] do
|
44
|
+
# run the tests
|
45
|
+
end
|
30
46
|
```
|
31
47
|
|
32
48
|
And in your e.g. spec_helper.rb, initialize EngineCart:
|
@@ -37,19 +53,14 @@ And in your e.g. spec_helper.rb, initialize EngineCart:
|
|
37
53
|
|
38
54
|
## Configuration
|
39
55
|
|
40
|
-
You can configure where the test app is created by setting the `
|
56
|
+
You can configure where the test app is created by setting the `ENGINE_CART_DESTINATION` env variable, e.g.:
|
41
57
|
|
42
58
|
```ruby
|
43
|
-
|
59
|
+
ENGINE_CART_DESTINATION="/tmp/generate-the-test-app-into-tmp-instead-of-your-app" rake ci
|
44
60
|
```
|
45
61
|
|
46
|
-
|
47
|
-
|
48
|
-
Gemfile.extra
|
49
|
-
|
50
|
-
test_app generator
|
62
|
+
After creating the test application, Engine Cart will run the test app generator (located in ./spec/test_app_templates/lib/generators). By default, it will attempt to run the `install` generator for your engine. If you do not have an `install` generator, or want to add additional steps (e.g. to install additional gems), you can add them to the `TestAppGenerator`.
|
51
63
|
|
52
|
-
within_test_app
|
53
64
|
|
54
65
|
## Contributing
|
55
66
|
|
data/Rakefile
CHANGED
@@ -13,15 +13,31 @@ task :generate_test_gem => ['engine_cart:setup'] do
|
|
13
13
|
system("rails plugin new spec/internal_gem")
|
14
14
|
system("mv spec/internal_gem spec/internal")
|
15
15
|
Rake::Task['engine_cart:inject_gemfile_extras'].invoke
|
16
|
-
within_test_app do
|
16
|
+
EngineCart.within_test_app do
|
17
17
|
system "git init"
|
18
18
|
FileUtils.touch('.gitignore')
|
19
19
|
Dir.mkdir('spec')
|
20
|
+
File.open('spec/spec_helper.rb', 'w') do |f|
|
21
|
+
f.puts <<-EOF
|
22
|
+
require 'engine_cart'
|
23
|
+
EngineCart.load_application!
|
24
|
+
|
25
|
+
require 'rspec/rails'
|
26
|
+
require 'rspec/autorun'
|
27
|
+
|
28
|
+
require 'internal_gem'
|
29
|
+
RSpec.configure do |config|
|
30
|
+
|
31
|
+
end
|
32
|
+
EOF
|
33
|
+
end
|
34
|
+
|
20
35
|
system "bundle install"
|
21
36
|
system "echo 'require \"engine_cart/rake_task\"\n' >> Rakefile"
|
22
37
|
|
23
38
|
system("rake engine_cart:prepare")
|
24
|
-
system
|
39
|
+
system "echo '\ngem \"rspec-rails\"\n' >> Gemfile"
|
40
|
+
system "bundle install"
|
25
41
|
end
|
26
42
|
end
|
27
43
|
|
data/lib/engine_cart.rb
CHANGED
@@ -1,8 +1,53 @@
|
|
1
1
|
require "engine_cart/version"
|
2
|
+
|
2
3
|
module EngineCart
|
3
4
|
require "engine_cart/engine" if defined? Rails
|
4
|
-
|
5
|
+
|
6
|
+
class << self
|
7
|
+
|
8
|
+
##
|
9
|
+
# Name of the engine we're testing
|
10
|
+
attr_accessor :engine_name
|
11
|
+
|
12
|
+
##
|
13
|
+
# Destination to generate the test app into
|
14
|
+
attr_accessor :destination
|
15
|
+
|
16
|
+
##
|
17
|
+
# Path to a Rails application template
|
18
|
+
attr_accessor :template
|
19
|
+
|
20
|
+
##
|
21
|
+
# Path to test app templates to make available to
|
22
|
+
# the test app generator
|
23
|
+
attr_accessor :templates_path
|
24
|
+
|
25
|
+
|
26
|
+
##
|
27
|
+
# Additional options when generating a test rails application
|
28
|
+
attr_accessor :rails_options
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
self.engine_name = ENV["CURRENT_ENGINE_NAME"]
|
33
|
+
self.destination = ENV['ENGINE_CART_DESTINATION'] || ENV['RAILS_ROOT'] || "./spec/internal"
|
34
|
+
self.template = ENV["ENGINE_CART_TEMPLATE"] || (File.expand_path('template.rb') if File.exists? 'template.rb')
|
35
|
+
self.templates_path = ENV['ENGINE_CART_TEMPLATES_PATH'] || "./spec/test_app_templates"
|
36
|
+
self.rails_options = ENV['ENGINE_CART_RAILS_OPTIONS']
|
37
|
+
|
38
|
+
def self.current_engine_name
|
39
|
+
engine_name || File.basename(Dir.glob("*.gemspec").first, '.gemspec')
|
40
|
+
end
|
41
|
+
|
5
42
|
def self.load_application! path = nil
|
6
|
-
require File.expand_path("config/environment", path ||
|
43
|
+
require File.expand_path("config/environment", path || EngineCart.destination)
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.within_test_app
|
47
|
+
Dir.chdir(EngineCart.destination) do
|
48
|
+
Bundler.with_clean_env do
|
49
|
+
yield
|
50
|
+
end
|
51
|
+
end
|
7
52
|
end
|
8
53
|
end
|
@@ -1,22 +1,23 @@
|
|
1
|
+
require 'engine_cart'
|
2
|
+
require 'generators/engine_cart/install_generator'
|
3
|
+
|
1
4
|
namespace :engine_cart do
|
2
5
|
|
3
6
|
desc "Prepare a gem for using engine_cart"
|
4
7
|
task :prepare do
|
5
|
-
|
6
|
-
generator = EngineCartGenerator.new
|
8
|
+
generator = EngineCart::InstallGenerator.new
|
7
9
|
generator.create_test_app_templates
|
8
10
|
generator.ignore_test_app
|
11
|
+
generator.add_gemfile_include
|
9
12
|
end
|
10
13
|
|
11
14
|
task :setup do
|
12
|
-
TEST_APP_TEMPLATES = 'spec/test_app_templates' unless defined? TEST_APP_TEMPLATES
|
13
|
-
TEST_APP = 'spec/internal' unless defined? TEST_APP
|
14
15
|
end
|
15
16
|
|
16
17
|
desc "Clean out the test rails app"
|
17
18
|
task :clean => [:setup] do
|
18
19
|
puts "Removing sample rails app"
|
19
|
-
`rm -rf #{
|
20
|
+
`rm -rf #{EngineCart.destination}`
|
20
21
|
end
|
21
22
|
|
22
23
|
task :create_test_rails_app => [:setup] do
|
@@ -28,59 +29,60 @@ namespace :engine_cart do
|
|
28
29
|
end
|
29
30
|
|
30
31
|
Bundler.with_clean_env do
|
31
|
-
`rails #{version} new internal`
|
32
|
+
`rails #{version} new internal #{EngineCart.rails_options} #{"-m #{EngineCart.template}" if EngineCart.template}`
|
32
33
|
end
|
34
|
+
|
33
35
|
unless $?
|
34
36
|
raise "Error generating new rails app. Aborting."
|
35
37
|
end
|
36
38
|
end
|
37
39
|
|
38
|
-
FileUtils.move "#{dir}/internal", "#{
|
40
|
+
FileUtils.move "#{dir}/internal", "#{EngineCart.destination}"
|
39
41
|
|
40
42
|
end
|
41
43
|
end
|
42
44
|
|
43
45
|
task :inject_gemfile_extras => [:setup] do
|
44
46
|
# Add our gem and extras to the generated Rails app
|
45
|
-
open(File.expand_path('Gemfile',
|
46
|
-
gemfile_extras_path = File.expand_path("Gemfile.extra",
|
47
|
+
open(File.expand_path('Gemfile', EngineCart.destination), 'a') do |f|
|
48
|
+
gemfile_extras_path = File.expand_path("Gemfile.extra", EngineCart.templates_path)
|
47
49
|
|
48
50
|
f.write <<-EOF
|
49
|
-
gem '#{current_engine_name}', :path => '#{File.expand_path('.')}'
|
50
|
-
|
51
|
-
if File.exists?("#{gemfile_extras_path}")
|
52
|
-
eval File.read("#{gemfile_extras_path}"), nil, "#{gemfile_extras_path}"
|
53
|
-
end
|
51
|
+
gem '#{EngineCart.current_engine_name}', :path => '#{File.expand_path('.')}'
|
54
52
|
EOF
|
55
53
|
end
|
56
54
|
end
|
57
55
|
|
58
56
|
desc "Create the test rails app"
|
59
57
|
task :generate => [:setup] do
|
58
|
+
return if File.exists? File.expand_path('.generated_engine_cart', EngineCart.destination)
|
60
59
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
system "rake db:migrate db:test:prepare"
|
72
|
-
end
|
73
|
-
puts "Done generating test app"
|
60
|
+
# Create a new test rails app
|
61
|
+
Rake::Task['engine_cart:create_test_rails_app'].invoke
|
62
|
+
|
63
|
+
system "bundle install"
|
64
|
+
|
65
|
+
Rake::Task['engine_cart:inject_gemfile_extras'].invoke
|
66
|
+
|
67
|
+
# Copy our test app generators into the app and prepare it
|
68
|
+
if File.exists? "#{EngineCart.templates_path}/lib/generators"
|
69
|
+
system "cp -r #{EngineCart.templates_path}/lib/generators #{EngineCart.destination}/lib"
|
74
70
|
end
|
75
|
-
end
|
76
|
-
end
|
77
71
|
|
78
|
-
|
79
|
-
|
72
|
+
within_test_app do
|
73
|
+
system "bundle install"
|
74
|
+
system "(rails g | grep test_app) && rails generate test_app"
|
75
|
+
system "rake db:migrate db:test:prepare"
|
76
|
+
end
|
77
|
+
|
78
|
+
File.open(File.expand_path('.generated_engine_cart', EngineCart.destination), 'w') { |f| f.puts true }
|
79
|
+
|
80
|
+
puts "Done generating test app"
|
81
|
+
end
|
80
82
|
end
|
81
83
|
|
82
84
|
def within_test_app
|
83
|
-
Dir.chdir(
|
85
|
+
Dir.chdir(EngineCart.destination) do
|
84
86
|
Bundler.with_clean_env do
|
85
87
|
yield
|
86
88
|
end
|
data/lib/engine_cart/version.rb
CHANGED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
##
|
4
|
+
# EngineCartGenerator sets up an engine to
|
5
|
+
# use engine_cart-generated test apps
|
6
|
+
module EngineCart
|
7
|
+
class InstallGenerator < Rails::Generators::Base
|
8
|
+
def create_test_app_templates
|
9
|
+
empty_directory EngineCart.templates_path
|
10
|
+
|
11
|
+
empty_directory File.expand_path("lib/generators", EngineCart.templates_path)
|
12
|
+
|
13
|
+
create_file File.expand_path("lib/generators/test_app_generator.rb", EngineCart.templates_path), :skip => true do
|
14
|
+
<<-EOF
|
15
|
+
require 'rails/generators'
|
16
|
+
|
17
|
+
class TestAppGenerator < Rails::Generators::Base
|
18
|
+
source_root "#{EngineCart.templates_path}"
|
19
|
+
|
20
|
+
# if you need to generate any additional configuration
|
21
|
+
# into the test app, this generator will be run immediately
|
22
|
+
# after setting up the application
|
23
|
+
|
24
|
+
def install_engine
|
25
|
+
generate '#{EngineCart.current_engine_name}:install'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
EOF
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def ignore_test_app
|
34
|
+
# Ignore the generated test app in the gem's .gitignore file
|
35
|
+
git_root = (`git rev-parse --show-toplevel` rescue '.').strip
|
36
|
+
|
37
|
+
# If we don't have a .gitignore file already, don't worry about it
|
38
|
+
return unless File.exists? File.expand_path('.gitignore', git_root)
|
39
|
+
|
40
|
+
# If the directory is already ignored (somehow) don't worry about it
|
41
|
+
return if (system('git', 'check-ignore', TEST_APP, '-q') rescue false)
|
42
|
+
|
43
|
+
append_file File.expand_path('.gitignore', git_root) do
|
44
|
+
"#{EngineCart.destination}\n"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def add_gemfile_include
|
49
|
+
append_file "Gemfile" do
|
50
|
+
<<-EOF
|
51
|
+
file = File.expand_path("Gemfile", ENV['ENGINE_CART_DESTINATION'] || ENV['RAILS_ROOT'] || File.expand_path("../spec/internal", __FILE__))
|
52
|
+
if File.exists?(file)
|
53
|
+
puts "Loading \#{file} ..." if $DEBUG # `ruby -d` or `bundle -v`
|
54
|
+
instance_eval File.read(file)
|
55
|
+
end
|
56
|
+
EOF
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -12,10 +12,57 @@ describe "EngineCart powered application" do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should have a engine_cart:generate rake task available" do
|
15
|
-
|
15
|
+
EngineCart.within_test_app do
|
16
|
+
`rake -T | grep "engine_cart:generate"`
|
17
|
+
expect($?).to eq 0
|
18
|
+
end
|
16
19
|
end
|
17
20
|
|
18
21
|
it "should create a rails app when the engine_cart:generate is invoked" do
|
22
|
+
EngineCart.within_test_app do
|
23
|
+
`rake engine_cart:generate`
|
24
|
+
expect(File).to exist(File.expand_path("spec/internal"))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should be able to test the application controller from the internal app" do
|
29
|
+
EngineCart.within_test_app do
|
30
|
+
File.open('spec/some_spec.rb', 'w') do |f|
|
31
|
+
f.puts <<-EOF
|
32
|
+
require 'spec_helper'
|
33
|
+
|
34
|
+
describe ApplicationController do
|
35
|
+
it "should be able to test the application controller from the internal app" do
|
36
|
+
expect(subject).to be_a_kind_of(ActionController::Base)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
EOF
|
41
|
+
end
|
42
|
+
|
43
|
+
`bundle exec rspec spec/some_spec.rb`
|
44
|
+
expect($?).to eq 0
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should be able to run specs that reference gems provided by the test app" do
|
49
|
+
EngineCart.within_test_app do
|
50
|
+
File.open('spec/require_spec.rb', 'w') do |f|
|
51
|
+
f.puts <<-EOF
|
52
|
+
require 'spec_helper'
|
53
|
+
require 'coffee-rails'
|
54
|
+
|
55
|
+
describe ApplicationController do
|
56
|
+
it "should be able to run specs that reference gems provided by the test app" do
|
57
|
+
expect(true).to be_true
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
EOF
|
62
|
+
end
|
19
63
|
|
64
|
+
`bundle exec rspec spec/require_spec.rb`
|
65
|
+
expect($?).to eq 0
|
66
|
+
end
|
20
67
|
end
|
21
68
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: engine_cart
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Beer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -84,11 +84,9 @@ files:
|
|
84
84
|
- lib/engine_cart/rake_task.rb
|
85
85
|
- lib/engine_cart/tasks/engine_cart.rake
|
86
86
|
- lib/engine_cart/version.rb
|
87
|
-
- lib/generators/engine_cart/
|
87
|
+
- lib/generators/engine_cart/install_generator.rb
|
88
88
|
- spec/integration/engine_cart_spec.rb
|
89
89
|
- spec/spec_helper.rb
|
90
|
-
- spec/test_app_templates/Gemfile.extra
|
91
|
-
- spec/test_app_templates/lib/generators/test_app_generator.rb
|
92
90
|
homepage: https://github.com/cbeer/engine_cart
|
93
91
|
licenses:
|
94
92
|
- MIT
|
@@ -109,13 +107,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
107
|
version: '0'
|
110
108
|
requirements: []
|
111
109
|
rubyforge_project:
|
112
|
-
rubygems_version: 2.2.
|
110
|
+
rubygems_version: 2.2.2
|
113
111
|
signing_key:
|
114
112
|
specification_version: 4
|
115
113
|
summary: Helper for testing Rails Engines sanely
|
116
114
|
test_files:
|
117
115
|
- spec/integration/engine_cart_spec.rb
|
118
116
|
- spec/spec_helper.rb
|
119
|
-
- spec/test_app_templates/Gemfile.extra
|
120
|
-
- spec/test_app_templates/lib/generators/test_app_generator.rb
|
121
|
-
has_rdoc:
|
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'rails/generators'
|
2
|
-
|
3
|
-
class EngineCartGenerator < Rails::Generators::Base
|
4
|
-
TEST_APP_TEMPLATES = 'spec/test_app_templates' unless defined? TEST_APP_TEMPLATES
|
5
|
-
TEST_APP = 'spec/internal' unless defined? TEST_APP
|
6
|
-
|
7
|
-
def create_test_app_templates
|
8
|
-
empty_directory TEST_APP_TEMPLATES
|
9
|
-
create_file File.expand_path("Gemfile.extra", TEST_APP_TEMPLATES), :skip => true do
|
10
|
-
"# extra gems to load into the test app go here"
|
11
|
-
end
|
12
|
-
|
13
|
-
empty_directory File.expand_path("lib/generators", TEST_APP_TEMPLATES)
|
14
|
-
|
15
|
-
create_file File.expand_path("lib/generators/test_app_generator.rb", TEST_APP_TEMPLATES), :skip => true do
|
16
|
-
<<-EOF
|
17
|
-
require 'rails/generators'
|
18
|
-
|
19
|
-
class TestAppGenerator < Rails::Generators::Base
|
20
|
-
source_root "#{TEST_APP_TEMPLATES}"
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
EOF
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def ignore_test_app
|
29
|
-
# Ignore the generated test app in the gem's .gitignore file
|
30
|
-
git_root = (`git rev-parse --show-toplevel` rescue '.').strip
|
31
|
-
|
32
|
-
# If we don't have a .gitignore file already, don't worry about it
|
33
|
-
return unless File.exists? File.expand_path('.gitignore', git_root)
|
34
|
-
|
35
|
-
# If the directory is already ignored (somehow) don't worry about it
|
36
|
-
return if (system('git', 'check-ignore', TEST_APP, '-q') rescue false)
|
37
|
-
|
38
|
-
append_file File.expand_path('.gitignore', git_root) do
|
39
|
-
"#{TEST_APP}\n"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
File without changes
|