engine_cart 0.0.2 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1fd5cf56f5fd88e6c9c18b2fe3151450027a1492
4
- data.tar.gz: 5956ec04b0713e1c2d7ca8de696efd823aca7e10
3
+ metadata.gz: 227eee21a510de7524b223c48ad1c60dc06aeef2
4
+ data.tar.gz: 7db8fb738878c4915e558b09f207706d8392a894
5
5
  SHA512:
6
- metadata.gz: 0c865ee31d20c689fdeb02f5222ead8797cf11942f3548e911985a08af6529c09ae9c3e18e410f6530a8a14aeca44416e3321f32c013c6f65035a27e53080742
7
- data.tar.gz: b53c73fd101daaeb7d828765b11b11935c2175bb7d0394b389f1b69d96d66c214d176b754ead3de6f5a62ecaf41c576fadf0bd1761ba2eedf2346c15f469925c
6
+ metadata.gz: fabe070a9189917f8900285c0adc015736387a7e351b661ecfd9d55febd54c0ee17aca00223beaeb1e403460c3c4b9f2b056648d18202169d710936f07b1ff44
7
+ data.tar.gz: 5e42eb9eddf3ad41ca26520aca754b9f96b9392c8703bca26db6f35ca4ea0ec0dbea9a64ac8020b5219e2a9147b8596fbeff2697da9ae97862459f28dd52d6c8
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ spec/internal
data/README.md CHANGED
@@ -19,26 +19,37 @@ Or install it yourself as:
19
19
 
20
20
  ## Usage
21
21
 
22
- Add this to your Rakefile:
22
+ In your Rakefile you can generate the Rails application using, e.g.:
23
23
 
24
- # Path to the test app
25
- # TEST_APP = 'spec/internal'
26
- # Path to files to include in the test app
27
- # TEST_APP_TEMPLATES = 'spec/test_app_templates'
24
+ ```ruby
28
25
  require 'engine_cart/rake_task'
29
26
 
30
- In your rake tasks, you can require the test app get build first:
31
-
32
27
  task :ci => ['engine_cart:generate'] do
33
28
  # run the tests
34
29
  end
30
+ ```
35
31
 
32
+ And in your e.g. spec_helper.rb, initialize EngineCart:
36
33
 
37
- And in your e.g. spec_helper:
38
-
39
- require 'engine_cart'
34
+ ```ruby
40
35
  EngineCart.load_application!
36
+ ```
37
+
38
+ ## Configuration
39
+
40
+ You can configure where the test app is created by setting the `TEST_APP` constant, e.g.:
41
+
42
+ ```ruby
43
+ TEST_APP = "/tmp/generate-the-test-app-into-tmp-instead-of-your-app
44
+ ```
45
+
46
+ You can also inject additional gems, or run other Rails generators by adding files to the `TEST_APP_TEMPLATES` directory.
47
+
48
+ Gemfile.extra
49
+
50
+ test_app generator
41
51
 
52
+ within_test_app
42
53
 
43
54
  ## Contributing
44
55
 
data/Rakefile CHANGED
@@ -1 +1,28 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'engine_cart/rake_task'
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :ci => ['generate_test_gem', 'spec'] do
8
+
9
+ end
10
+
11
+ task :generate_test_gem => ['engine_cart:setup'] do
12
+ system("rm -rf spec/internal")
13
+ system("rails plugin new spec/internal_gem")
14
+ system("mv spec/internal_gem spec/internal")
15
+ Rake::Task['engine_cart:inject_gemfile_extras'].invoke
16
+ within_test_app do
17
+ system "git init"
18
+ FileUtils.touch('.gitignore')
19
+ Dir.mkdir('spec')
20
+ system "bundle install"
21
+ system "echo 'require \"engine_cart/rake_task\"\n' >> Rakefile"
22
+
23
+ system("rake engine_cart:prepare")
24
+ system("rake engine_cart:generate")
25
+ end
26
+ end
27
+
28
+ task :default => :ci
data/engine_cart.gemspec CHANGED
@@ -18,6 +18,9 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.add_dependency "rails"
22
+
21
23
  spec.add_development_dependency "bundler", "~> 1.3"
22
24
  spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
23
26
  end
@@ -0,0 +1,8 @@
1
+ module EngineCart
2
+ require 'rails'
3
+ class Engine < Rails::Engine
4
+ rake_tasks do
5
+ load "engine_cart/tasks/engine_cart.rake"
6
+ end
7
+ end
8
+ end
@@ -1,5 +1,13 @@
1
1
  namespace :engine_cart do
2
2
 
3
+ desc "Prepare a gem for using engine_cart"
4
+ task :prepare do
5
+ require 'generators/engine_cart/engine_cart_generator'
6
+ generator = EngineCartGenerator.new
7
+ generator.create_test_app_templates
8
+ generator.ignore_test_app
9
+ end
10
+
3
11
  task :setup do
4
12
  TEST_APP_TEMPLATES = 'spec/test_app_templates' unless defined? TEST_APP_TEMPLATES
5
13
  TEST_APP = 'spec/internal' unless defined? TEST_APP
@@ -11,23 +19,34 @@ namespace :engine_cart do
11
19
  `rm -rf #{TEST_APP}`
12
20
  end
13
21
 
14
- desc "Create the test rails app"
15
- task :generate => [:setup] do
22
+ task :create_test_rails_app => [:setup] do
23
+ system "rails new #{TEST_APP}"
24
+ end
16
25
 
17
- unless File.exists? File.expand_path('Rakefile', TEST_APP)
18
- system "rails new #{TEST_APP}"
19
- open(File.expand_path('Gemfile', TEST_APP), 'a') do |f|
20
- gemfile_extras_path = File.expand_path("Gemfile.extra", TEST_APP_TEMPLATES)
26
+ task :inject_gemfile_extras => [:setup] do
27
+ # Add our gem and extras to the generated Rails app
28
+ open(File.expand_path('Gemfile', TEST_APP), 'a') do |f|
29
+ gemfile_extras_path = File.expand_path("Gemfile.extra", TEST_APP_TEMPLATES)
21
30
 
22
- f.write <<-EOF
23
- gem '#{current_engine_name}', :path => '../../'
31
+ f.write <<-EOF
32
+ gem '#{current_engine_name}', :path => '#{File.expand_path('.')}'
24
33
 
25
34
  if File.exists?("#{gemfile_extras_path}")
26
35
  eval File.read("#{gemfile_extras_path}"), nil, "#{gemfile_extras_path}"
27
36
  end
28
37
  EOF
29
- end
38
+ end
39
+ end
40
+
41
+ desc "Create the test rails app"
42
+ task :generate => [:setup] do
30
43
 
44
+ unless File.exists? File.expand_path('Rakefile', TEST_APP)
45
+ # Create a new test rails app
46
+ Rake::Task['engine_cart:create_test_rails_app'].invoke
47
+ Rake::Task['engine_cart:inject_gemfile_extras'].invoke
48
+
49
+ # Copy our test app generators into the app and prepare it
31
50
  system "cp -r #{TEST_APP_TEMPLATES}/lib/generators #{TEST_APP}/lib"
32
51
  within_test_app do
33
52
  system "bundle install"
@@ -44,9 +63,9 @@ def current_engine_name
44
63
  end
45
64
 
46
65
  def within_test_app
47
- FileUtils.cd(TEST_APP)
48
- Bundler.with_clean_env do
49
- yield
66
+ Dir.chdir(TEST_APP) do
67
+ Bundler.with_clean_env do
68
+ yield
69
+ end
50
70
  end
51
- FileUtils.cd(APP_ROOT)
52
71
  end
@@ -1,3 +1,3 @@
1
1
  module EngineCart
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/engine_cart.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require "engine_cart/version"
2
-
3
2
  module EngineCart
4
- # Your code goes here...
3
+ require "engine_cart/engine"
4
+
5
5
  def self.load_application! path = nil
6
6
  require File.expand_path("config/environment", path || ENV['RAILS_ROOT'] || "./spec/internal")
7
7
  end
@@ -0,0 +1,42 @@
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
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe "EngineCart powered application" do
4
+ TEST_APP = File.expand_path("../internal", File.dirname(__FILE__))
5
+ it "should have the test_app_templates pre-generated" do
6
+ expect(File).to exist File.expand_path("spec/test_app_templates", TEST_APP)
7
+ end
8
+
9
+ it "should ignore the test app" do
10
+ git_ignore = File.expand_path(".gitignore", TEST_APP)
11
+ expect(File.read(git_ignore)).to match /spec\/internal/
12
+ end
13
+
14
+ it "should have a engine_cart:generate rake task available" do
15
+
16
+ end
17
+
18
+ it "should create a rails app when the engine_cart:generate is invoked" do
19
+
20
+ end
21
+ end
@@ -0,0 +1,6 @@
1
+ require 'engine_cart'
2
+ require 'rspec'
3
+
4
+ RSpec.configure do |config|
5
+
6
+ end
File without changes
@@ -0,0 +1,7 @@
1
+ require 'rails/generators'
2
+
3
+ class TestAppGenerator < Rails::Generators::Base
4
+ source_root "spec/test_app_templates"
5
+
6
+ end
7
+
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: engine_cart
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.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: 2013-10-02 00:00:00.000000000 Z
11
+ date: 2013-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +52,20 @@ dependencies:
38
52
  - - '>='
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
41
69
  description: Helper for testing Rails Engines sanely
42
70
  email:
43
71
  - cabeer@stanford.edu
@@ -52,9 +80,15 @@ files:
52
80
  - Rakefile
53
81
  - engine_cart.gemspec
54
82
  - lib/engine_cart.rb
83
+ - lib/engine_cart/engine.rb
55
84
  - lib/engine_cart/rake_task.rb
56
85
  - lib/engine_cart/tasks/engine_cart.rake
57
86
  - lib/engine_cart/version.rb
87
+ - lib/generators/engine_cart/engine_cart_generator.rb
88
+ - spec/integration/engine_cart_spec.rb
89
+ - spec/spec_helper.rb
90
+ - spec/test_app_templates/Gemfile.extra
91
+ - spec/test_app_templates/lib/generators/test_app_generator.rb
58
92
  homepage: https://github.com/cbeer/engine_cart
59
93
  licenses:
60
94
  - MIT
@@ -79,4 +113,8 @@ rubygems_version: 2.0.3
79
113
  signing_key:
80
114
  specification_version: 4
81
115
  summary: Helper for testing Rails Engines sanely
82
- test_files: []
116
+ test_files:
117
+ - spec/integration/engine_cart_spec.rb
118
+ - spec/spec_helper.rb
119
+ - spec/test_app_templates/Gemfile.extra
120
+ - spec/test_app_templates/lib/generators/test_app_generator.rb