Skip to content

Commit ad97fc7

Browse files
committed
Create test app generator
1 parent bb2c166 commit ad97fc7

File tree

4 files changed

+94
-0
lines changed

4 files changed

+94
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ spec/reports
1515
test/tmp
1616
test/version_tmp
1717
tmp
18+
spec/internal

Rakefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1+
#!/usr/bin/env rake
12
require "bundler/gem_tasks"
3+
4+
Dir.glob('tasks/*.rake').each { |r| import r }
5+
6+
ENV["RAILS_ROOT"] ||= 'spec/internal'
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
require 'rails/generators'
2+
3+
class TestAppGenerator < Rails::Generators::Base
4+
source_root File.expand_path("../../../../internal", __FILE__)
5+
def inject_css
6+
copy_file "app/assets/stylesheets/application.css", "app/assets/stylesheets/application.css.scss"
7+
remove_file "app/assets/stylesheets/application.css"
8+
insert_into_file "app/assets/stylesheets/application.css.scss", :after => '*/' do
9+
%{\n\n@import "browse_everything"}
10+
end
11+
end
12+
13+
def inject_javascript
14+
insert_into_file "app/assets/javascripts/application.js", :after => '//= require_tree .' do
15+
"\n//= require browse_everything"
16+
end
17+
end
18+
19+
def update_gemfile
20+
append_file "Gemfile" do
21+
"gem 'bootstrap-sass'\ngem 'font-awesome-rails'"
22+
end
23+
end
24+
25+
def inject_routes
26+
insert_into_file "config/routes.rb", :after => ".draw do" do
27+
"\n\nmount BrowseEverything::Engine => '/browse'\n\n"
28+
end
29+
end
30+
end

tasks/browse-everything-dev.rake

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
namespace :app do
2+
desc "Create the test rails app"
3+
task :generate do
4+
unless File.exists?('spec/internal/Rakefile')
5+
puts "Generating rails app"
6+
`rails new spec/internal`
7+
puts "Updating gemfile"
8+
9+
`echo "gem 'browse-everything', :path=>'../../../browse-everything'
10+
gem 'factory_girl_rails'
11+
" >> spec/internal/Gemfile`
12+
puts "Copying generator"
13+
`cp -r spec/support/lib/generators spec/internal/lib`
14+
Bundler.with_clean_env do
15+
within_test_app do
16+
puts "running test_app_generator"
17+
system "rails generate test_app"
18+
puts "Bundle install"
19+
`bundle install`
20+
puts "running migrations"
21+
puts `rake db:migrate db:test:prepare`
22+
end
23+
end
24+
end
25+
puts "Done generating test app"
26+
end
27+
28+
desc "Clean out the test rails app"
29+
task :clean do
30+
puts "Removing sample rails app"
31+
`rm -rf spec/internal`
32+
end
33+
34+
desc "Start the test rails app"
35+
task :start do
36+
Bundler.with_clean_env do
37+
within_test_app do
38+
puts "Starting test app"
39+
system "rails server -d"
40+
end
41+
end
42+
end
43+
44+
desc "Stop the test rails app"
45+
task :stop do
46+
within_test_app do
47+
pid = File.read('tmp/pids/server.pid')
48+
puts "Stopping pid #{pid}"
49+
system "kill -2 #{pid}"
50+
end
51+
end
52+
end
53+
54+
def within_test_app
55+
FileUtils.cd('spec/internal')
56+
yield
57+
FileUtils.cd('../..')
58+
end

0 commit comments

Comments
 (0)