-
-
Save martinrehfeld/322570 to your computer and use it in GitHub Desktop.
optimized ENV for Culerity
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
require 'culerity' | |
$env_javascript_tag = ENV['CULERITY_JAVASCRIPT_TAG'] || '@javascript' | |
def set_jruby_env | |
rvm_jruby = ENV['CULERITY_RVM_JRUBY'] || 'jruby' | |
info = `rvm info #{rvm_jruby}` | |
gem_home = info =~ /GEM_HOME:\s?"([^"]*)"/ ? $1 : '' | |
gem_path = info =~ /GEM_PATH:\s?"([^"]*)"/ ? $1 : '' | |
my_ruby_home = info =~ /MY_RUBY_HOME:\s?"([^"]*)"/ ? $1 : '' | |
bin_path = my_ruby_home.blank? ? '' : "#{my_ruby_home}/bin" | |
$gem_home = ENV['GEM_HOME'] | |
$gem_path = ENV['GEM_PATH'] | |
$my_ruby_home = ENV['MY_RUBY_HOME'] | |
$os_path = ENV['PATH'] | |
ENV['GEM_HOME'] = gem_home | |
ENV['GEM_PATH'] = gem_path | |
ENV['MY_RUBY_HOME'] = my_ruby_home | |
ENV['PATH'] = "#{bin_path}:#{$os_path}" | |
end | |
def restore_env | |
ENV['GEM_HOME'] = $gem_home | |
ENV['GEM_PATH'] = $gem_path | |
ENV['MY_RUBY_HOME'] = $my_ruby_home | |
ENV['PATH'] = $os_path | |
end | |
def culerity_startup | |
$rails_server ||= Culerity::run_rails(:environment => 'culerity_development', :port => 3001) | |
$server ||= Culerity::run_server | |
@host = 'http://localhost:3001' | |
ActionMailer::Base.clear_deliveries | |
end | |
def culerity_shutdown | |
if $browser | |
$browser.close | |
$browser.exit | |
$browser = nil | |
end | |
if $server | |
$server.close | |
$server = nil | |
end | |
if $rails_server | |
Process.kill(6, $rails_server.pid.to_i) | |
$rails_server = nil | |
end | |
end | |
def start_browser(enable_javascript) | |
$javascript_enabled = enable_javascript | |
$browser = Culerity::RemoteBrowserProxy.new $server, { | |
:browser => :firefox3, | |
:status_code_exceptions => true, | |
:javascript_exceptions => enable_javascript, | |
:resynchronize => enable_javascript, | |
:javascript_enabled => enable_javascript | |
} | |
$browser.log_level = :warning | |
end | |
Before do | |
$env_javascript_enabled = ENV['CULERITY_ENABLE_JAVASCRIPT'] == 'TRUE' | |
env_using_rvm = ENV['CULERITY_USING_RVM'] == 'TRUE' | |
set_jruby_env if env_using_rvm | |
culerity_startup | |
restore_env if env_using_rvm | |
start_browser($env_javascript_enabled) | |
end | |
Before($env_javascript_tag) do | |
unless $javascript_enabled | |
start_browser(true) | |
end | |
end | |
Before("~#{$env_javascript_tag}") do | |
if $javascript_enabled && !$env_javascript_enabled | |
start_browser(false) | |
end | |
end | |
After do | |
$browser.wait # for javascript jobs | |
$browser.close | |
end | |
at_exit do | |
culerity_shutdown | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment