Skip to content

Commit 8e07084

Browse files
committed
Overhauling integration test mechanism.
1 parent bb0db21 commit 8e07084

File tree

170 files changed

+1807
-138
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

170 files changed

+1807
-138
lines changed

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
/Gemfile.lock
99
*.gem
1010
/.idea/
11-
.rvmrc
11+
/.rvmrc
1212
.bundle
1313
/.rbx
14+
/spec/integration/*/bin/
15+
/spec/integration/*/log/*
16+
!/spec/integration/*/log/.gitkeep
17+
/spec/integration/*/tmp/*
18+
!/spec/integration/*/tmp/.gitkeep
19+
/spec/integration/*/db/test.*

CHANGELOG.rdoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
* Added support for new FactoryGirl naming convention.
1616
* Fix behavior of route annotations in newer versions of Rake that don't spit
1717
out the CWD as their first line of output.
18+
* Overhauled integration testing system to be much easier to work with, better
19+
compartmentalized, and so forth -- at the cost that you must be using RVM to
20+
utilize it. (It'll spit out appropriate pending messages if you don't.)
21+
Also includes a mode for "tinkering" by hand with a scenario, and won't let
22+
you run it through rspect if the repo is in a dirty state. Added appropriate
23+
rake tasks to help with all of this.
1824
* Routes can now be appended, pre-pended, or removed -- and do sane things in
1925
all cases.
2026
* Expose all `position_*` variables as CLI params.

Rakefile

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,88 @@ RSpec::Core::RakeTask.new(:spec) do |t|
3131
t.rspec_opts = ['--backtrace', '--format d']
3232
end
3333

34+
# Placeholder for running bin/* in development...
35+
task :environment
36+
37+
task :integration_environment do
38+
require './spec/spec_helper'
39+
end
40+
41+
namespace :gemsets do
42+
desc "Completely empty any gemsets used by scenarios, so they'll be perfectly clean on the next run."
43+
task :empty => [:integration_environment] do
44+
Annotate::Integration::SCENARIOS.each do |test_rig, base_dir, test_name|
45+
Annotate::Integration.empty_gemset(test_rig)
46+
end
47+
end
48+
end
49+
task :clobber => :'gemsets:empty'
50+
51+
namespace :integration do
52+
desc "Remove any cruft generated by manual debugging runs which is .gitignore'd."
53+
task :clean => :integration_environment do
54+
Annotate::Integration.nuke_all_cruft
55+
end
56+
57+
desc "Reset any changed files, and remove any untracked files in spec/integration/*/, plus run integration:clean."
58+
task :clobber => [:integration_environment, :'integration:clean'] do
59+
Annotate::Integration.reset_dirty_files
60+
Annotate::Integration.clear_untracked_files
61+
end
62+
63+
task :symlink => [:integration_environment] do
64+
require 'digest/md5'
65+
66+
integration_dir = File.expand_path(File.join(File.dirname(__FILE__), 'spec', 'integration'))
67+
fixture_dir = File.expand_path(File.join(File.dirname(__FILE__), 'spec', 'fixtures'))
68+
target_dir = File.expand_path(ENV['TARGET']) if(ENV['TARGET'])
69+
raise "Must specify TARGET=x, where x is an integration test scenario!" unless(target_dir && Dir.exist?(target_dir))
70+
raise "TARGET directory must be within spec/integration/!" unless(target_dir.start_with?(integration_dir))
71+
candidates = {}
72+
FileList[
73+
"#{target_dir}/.rvmrc",
74+
"#{target_dir}/**/*"
75+
].select { |fname| !(File.symlink?(fname) || File.directory?(fname)) }.
76+
map { |fname| fname.sub(integration_dir, '') }.
77+
reject do |fname|
78+
fname =~ /\/\.gitkeep$/ ||
79+
fname =~ /\/app\/models\// ||
80+
fname =~ /\/routes\.rb$/ ||
81+
fname =~ /\/fixtures\// ||
82+
fname =~ /\/factories\// ||
83+
fname =~ /\.sqlite3$/ ||
84+
(fname =~ /\/test\// && fname !~ /_helper\.rb$/) ||
85+
(fname =~ /\/spec\// && fname !~ /_helper\.rb$/)
86+
end.
87+
map { |fname| "#{integration_dir}#{fname}"}.
88+
each do |fname|
89+
digest = Digest::MD5.hexdigest(File.read(fname))
90+
candidates[digest] ||= []
91+
candidates[digest] << fname
92+
end
93+
fixtures = {}
94+
FileList["spec/fixtures/**/*"].each do |fname|
95+
fixtures[Digest::MD5.hexdigest(File.read(fname))] = File.expand_path(fname)
96+
end
97+
98+
candidates.keys.each do |digest|
99+
if(fixtures.has_key?(digest))
100+
candidates[digest].each do |fname|
101+
# Double-check contents in case of hash collision...
102+
if(FileUtils.identical?(fname, fixtures[digest]))
103+
destination_dir = Pathname.new(File.dirname(fname))
104+
relative_target = Pathname.new(fixtures[digest]).relative_path_from(destination_dir)
105+
Dir.chdir(destination_dir) do
106+
sh("ln", "-sfn", relative_target.to_s, File.basename(fname))
107+
end
108+
end
109+
end
110+
end
111+
end
112+
end
113+
end
114+
task :clobber => :'integration:clobber'
115+
34116
require 'yard'
35117
YARD::Rake::YardocTask.new do |t|
36118
# t.files = ['features/**/*.feature', 'features/**/*.rb', 'lib/**/*.rb']
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class CreateTasks < ActiveRecord::Migration
2+
def change
3+
create_table :tasks do |t|
4+
t.string :content
5+
6+
t.timestamps
7+
end
8+
end
9+
end

spec/fixtures/database.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# SQLite version 3.x
2+
# gem install sqlite3
3+
#
4+
# Ensure the SQLite 3 gem is defined in your Gemfile
5+
# gem 'sqlite3'
6+
development:
7+
adapter: sqlite3
8+
database: db/development.sqlite3
9+
pool: 1
10+
timeout: 5000
11+
12+
test:
13+
adapter: sqlite3
14+
database: db/test.sqlite3
15+
pool: 1
16+
timeout: 5000

spec/fixtures/rails32_boot.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require 'rubygems'
2+
3+
# Set up gems listed in the Gemfile.
4+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
5+
6+
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# secret_token.rb
2+
TestApp::Application.config.secret_token = '4768b21141022d583b141fde0db7e0b31759321b7fce459963914fdd82db248ea0318d9568030dcde70d404d4e86003ce5f51a7a83c8130842e5a97062b68c3c'
3+
4+
# session_store.rb
5+
TestApp::Application.config.session_store :cookie_store, key: '_session'
6+
7+
# wrap_parameters.rb
8+
ActiveSupport.on_load(:active_record) { self.include_root_in_json = false }

spec/fixtures/rails_328_gemfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# This file is a hybrid file meant for live debugging without going through an
2+
# actual RSpec run, and for being used in an RSpec run. To change it, change
3+
# template.Gemfile and run 'rake templates:rebuild' which will do so for all
4+
# templates in all build scenarios.
5+
#
6+
# ALSO, be sure NOT to commit any changes that happen in app/* or config/*
7+
# when debugging this way as that will defeat the point of the automated tests!
8+
#
9+
# In fact, before running RSpec again after manual testing, you should run
10+
# 'rake integration:clober' to reset modified files to their pristine state,
11+
# and remove cruft that may interfere with the build.
12+
source 'https://rubygems.org'
13+
14+
gem 'rails', '3.2.8'
15+
16+
gem 'sqlite3'
17+
18+
group :development do
19+
if(ENV['AUTOMATED_TEST'] && ENV['AUTOMATED_TEST'] != '')
20+
gem 'annotate', :path => ENV['AUTOMATED_TEST']
21+
else
22+
gem 'annotate', :path => '../../..'
23+
end
24+
end

spec/fixtures/rails_328_gemfile.lock

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
PATH
2+
remote: ../../..
3+
specs:
4+
annotate (2.5.0.beta4)
5+
activesupport (>= 2.3.0)
6+
rake (>= 0.8.7)
7+
8+
GEM
9+
remote: https://rubygems.org/
10+
specs:
11+
actionmailer (3.2.8)
12+
actionpack (= 3.2.8)
13+
mail (~> 2.4.4)
14+
actionpack (3.2.8)
15+
activemodel (= 3.2.8)
16+
activesupport (= 3.2.8)
17+
builder (~> 3.0.0)
18+
erubis (~> 2.7.0)
19+
journey (~> 1.0.4)
20+
rack (~> 1.4.0)
21+
rack-cache (~> 1.2)
22+
rack-test (~> 0.6.1)
23+
sprockets (~> 2.1.3)
24+
activemodel (3.2.8)
25+
activesupport (= 3.2.8)
26+
builder (~> 3.0.0)
27+
activerecord (3.2.8)
28+
activemodel (= 3.2.8)
29+
activesupport (= 3.2.8)
30+
arel (~> 3.0.2)
31+
tzinfo (~> 0.3.29)
32+
activeresource (3.2.8)
33+
activemodel (= 3.2.8)
34+
activesupport (= 3.2.8)
35+
activesupport (3.2.8)
36+
i18n (~> 0.6)
37+
multi_json (~> 1.0)
38+
arel (3.0.2)
39+
builder (3.0.0)
40+
erubis (2.7.0)
41+
hike (1.2.1)
42+
i18n (0.6.0)
43+
journey (1.0.4)
44+
json (1.7.4)
45+
mail (2.4.4)
46+
i18n (>= 0.4.0)
47+
mime-types (~> 1.16)
48+
treetop (~> 1.4.8)
49+
mime-types (1.19)
50+
multi_json (1.3.6)
51+
polyglot (0.3.3)
52+
rack (1.4.1)
53+
rack-cache (1.2)
54+
rack (>= 0.4)
55+
rack-ssl (1.3.2)
56+
rack
57+
rack-test (0.6.1)
58+
rack (>= 1.0)
59+
rails (3.2.8)
60+
actionmailer (= 3.2.8)
61+
actionpack (= 3.2.8)
62+
activerecord (= 3.2.8)
63+
activeresource (= 3.2.8)
64+
activesupport (= 3.2.8)
65+
bundler (~> 1.0)
66+
railties (= 3.2.8)
67+
railties (3.2.8)
68+
actionpack (= 3.2.8)
69+
activesupport (= 3.2.8)
70+
rack-ssl (~> 1.3.2)
71+
rake (>= 0.8.7)
72+
rdoc (~> 3.4)
73+
thor (>= 0.14.6, < 2.0)
74+
rake (0.9.2.2)
75+
rdoc (3.12)
76+
json (~> 1.4)
77+
sprockets (2.1.3)
78+
hike (~> 1.2)
79+
rack (~> 1.0)
80+
tilt (~> 1.1, != 1.3.0)
81+
sqlite3 (1.3.6)
82+
thor (0.16.0)
83+
tilt (1.3.3)
84+
treetop (1.4.10)
85+
polyglot
86+
polyglot (>= 0.3.1)
87+
tzinfo (0.3.33)
88+
89+
PLATFORMS
90+
ruby
91+
92+
DEPENDENCIES
93+
annotate!
94+
rails (= 3.2.8)
95+
sqlite3

spec/fixtures/rails_32_development.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
TestApp::Application.configure do
2+
config.action_dispatch.best_standards_support = :builtin
3+
config.active_record.auto_explain_threshold_in_seconds = 0.5
4+
config.active_record.mass_assignment_sanitizer = :strict
5+
config.active_support.deprecation = :log
6+
config.cache_classes = false
7+
config.consider_all_requests_local = true
8+
config.whiny_nils = true
9+
end

0 commit comments

Comments
 (0)