forked from thoughtbot/shoulda-matchers
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Speed up running unit tests with Zeus
This is an effort to vastly decrease the time it takes to run a single unit test file and therefore increase productivity and happiness for people working on this project. If you want to run a unit test file, now you can use `zeus rspec` instead of `rspec` -- assuming you run `zeus start` first -- and it will run a LOT faster. Because test files tend to have long file paths, you can even use a shorter version of those paths. So instead of saying: zeus rspec spec/unit/shoulda/matchers/active_record/validate_uniqueness_of_matcher_spec.rb you can say: zeus rspec active_record/validate_uniqueness_of_matcher_spec.rb
- Loading branch information
Showing
17 changed files
with
191 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
require 'zeus/rails' | ||
require_relative 'spec/support/tests/current_bundle' | ||
|
||
class CustomPlan < Zeus::Plan | ||
def initialize | ||
super | ||
@rails_plan = Zeus::Rails.new | ||
end | ||
|
||
def boot | ||
ENV['BUNDLE_GEMFILE'] = File.expand_path( | ||
"../gemfiles/#{latest_appraisal}.gemfile", | ||
__FILE__ | ||
) | ||
|
||
require 'bundler/setup' | ||
|
||
$LOAD_PATH << File.expand_path('../lib', __FILE__) | ||
$LOAD_PATH << File.expand_path('../spec', __FILE__) | ||
|
||
require_relative 'spec/support/unit/load_environment' | ||
end | ||
|
||
def after_fork | ||
# @rails_plan.reconnect_activerecord | ||
end | ||
|
||
def test_environment | ||
require_relative 'spec/unit_spec_helper' | ||
end | ||
|
||
def rspec | ||
ARGV.replace(file_paths_to_run) | ||
RSpec::Core::Runner.invoke | ||
end | ||
|
||
private | ||
|
||
def latest_appraisal | ||
current_bundle.latest_appraisal | ||
end | ||
|
||
def current_bundle | ||
Tests::CurrentBundle.instance | ||
end | ||
|
||
def file_paths_to_run | ||
if given_file_paths.empty? | ||
['spec/unit'] | ||
else | ||
given_file_paths.map do |given_path| | ||
determine_file_path_to_run(given_path) | ||
end | ||
end | ||
end | ||
|
||
def determine_file_path_to_run(given_rspec_argument) | ||
expanded_file_path, location = | ||
expand_rspec_argument(given_rspec_argument) | ||
|
||
if File.exist?(expanded_file_path) | ||
if location | ||
expanded_file_path + location | ||
else | ||
expanded_file_path | ||
end | ||
else | ||
given_rspec_argument | ||
end | ||
end | ||
|
||
def expand_rspec_argument(rspec_argument) | ||
match = rspec_argument.match(/\A(.+?)(:\d+|\[[\d:]+\])?\Z/) | ||
file_path, location = match.captures | ||
expanded_file_path = File.expand_path( | ||
"../spec/unit/shoulda/matchers/#{file_path}", | ||
__FILE__ | ||
) | ||
|
||
[expanded_file_path, location] | ||
end | ||
|
||
def given_file_paths | ||
ARGV | ||
end | ||
end | ||
|
||
Zeus.plan = CustomPlan.new |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require_relative '../tests/current_bundle' | ||
require_relative 'rails_application' | ||
|
||
Tests::CurrentBundle.instance.assert_appraisal! | ||
|
||
$test_app = UnitTests::RailsApplication.new | ||
$test_app.create | ||
$test_app.load | ||
|
||
require 'active_record/base' | ||
|
||
ENV['RAILS_ENV'] = 'test' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"command": "ruby -rubygems -r./custom_plan -eZeus.go", | ||
|
||
"plan": { | ||
"boot": { | ||
"test_environment": { | ||
"rspec": [] | ||
} | ||
} | ||
} | ||
} |