Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test setup and helpers very verbose atm
- Loading branch information
1 parent
85b6f86
commit 646194c
Showing
5 changed files
with
61 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
# A sample Guardfile | ||
# More info at https://github.com/guard/guard#readme | ||
|
||
guard :test do | ||
guard :test, :cli => '-v v' do | ||
watch(%r{^lib/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" } | ||
watch(%r{^test/.+_test\.rb$}) | ||
watch('test/test_helper.rb') { "test" } | ||
|
||
end |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
#!/usr/bin/env rake | ||
require "bundler/gem_tasks" | ||
require 'appraisal' |
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 |
---|---|---|
@@ -1,50 +1,64 @@ | ||
|
||
module CompassRails | ||
module Test | ||
module RailsHelpers | ||
VENDORED_RAILS_PATH = File.expand_path('../../fixtures/rails_versions', __FILE__) | ||
include FileHelper | ||
include DebugHelper | ||
include CommandHelper | ||
|
||
def debug(message) | ||
puts message if ENV['DEBUG'] | ||
end | ||
RAILS_3_1 = "3.1" | ||
RAILS_3 = "3.0" | ||
RAILS_2 = "2.3" | ||
|
||
def mkdir_p(dir) | ||
debug("Creating Directory: #{dir}") | ||
::FileUtils.make_dir dir | ||
end | ||
|
||
def new_rails_app(named, version='3.1', &block) | ||
working_dir = File.expand_path('../../fixtures/rails-temp', __FILE__) | ||
mkdir_p working_dir | ||
Dir.chdir(working_dir) do | ||
generate_rails_app(named, working_dir) | ||
WORKING_DIR = File.join(ROOT_PATH, 'rails-temp') | ||
GEMFILES = { | ||
RAILS_3_1 => GEMFILES_DIR.join("rails31.gemfile").to_s, | ||
RAILS_3 => GEMFILES_DIR.join("rails3.gemfile").to_s, | ||
RAILS_2 => GEMFILES_DIR.join("rails2.gemfile").to_s | ||
} | ||
|
||
GENERTOR_OPTIONS = { | ||
RAILS_3_1 => ['-q', '-G', '-O', '--skip-bundle'], | ||
RAILS_3 => ['-q', '-G', '-O', '--skip-bundle'], | ||
RAILS_2 => ['-q'] | ||
} | ||
|
||
GENERATOR_COMMAND = { | ||
RAILS_3_1 => 'new', | ||
RAILS_3 => 'new', | ||
RAILS_2 => '' | ||
} | ||
|
||
def rails_command(options, version) | ||
debug("Running Rails command with: rails #{options.join(' ')}".foreground(:cyan)) | ||
capture_output do | ||
run_command("rails #{options.join(' ')}", GEMFILES[version]) | ||
end | ||
end | ||
|
||
# Generate a rails application without polluting our current set of requires | ||
# with the rails libraries. This will allow testing against multiple versions of rails | ||
# by manipulating the load path. | ||
def generate_rails_app(name, version='3.1') | ||
system "rails _#{version}_ new #{name}" | ||
def generate_rails_app(name, version, options=[]) | ||
options += GENERTOR_OPTIONS[version] | ||
rails_command([GENERATOR_COMMAND[version], name, *options], version) | ||
end | ||
|
||
private | ||
|
||
def find_rails_version_executable(version) | ||
folder = find_rails_version_folder(version) | ||
File.join(folder, 'bin', 'rails') | ||
end | ||
|
||
def find_rails_version_folder(version) | ||
versions = Dir["VENDORED_RAILS_PATH/*"].map {|name| File.basename(name) } | ||
unless path = versions.sort.detect { |v| v.include?(version)} | ||
raise "Rails Version Not Found: #{version}" | ||
def within_rails_app(named, version, run_bundler=false, &block) | ||
dir = "#{named}-#{version}" | ||
rm_rf File.join(WORKING_DIR, dir) | ||
mkdir_p WORKING_DIR | ||
cd(WORKING_DIR) do | ||
generate_rails_app(dir, version) | ||
cd(dir) do | ||
bundle if run_bundler | ||
yield dir | ||
end | ||
end | ||
File.join(VENDORED_RAILS_PATH, path) | ||
rm_rf File.join(WORKING_DIR, dir) | ||
end | ||
|
||
|
||
|
||
end | ||
end | ||
end |
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 |
---|---|---|
@@ -1 +1,11 @@ | ||
require 'compass-rails' | ||
require 'rainbow' | ||
module CompassRails | ||
module Test | ||
ROOT_PATH = File.expand_path('../../', __FILE__) | ||
end | ||
end | ||
|
||
%w(debug file command rails).each do |helper| | ||
require File.join(File.expand_path('../', __FILE__), 'helpers', "#{helper}_helper") | ||
end |