Skip to content

Commit

Permalink
load config change
Browse files Browse the repository at this point in the history
  • Loading branch information
hotchpotch committed Dec 10, 2010
1 parent 016a878 commit 0f57f7b
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 4 deletions.
31 changes: 31 additions & 0 deletions examples/rails.prspecd
@@ -0,0 +1,31 @@

prefetch {
require 'pathname'
ENV["PRSPEC"] = 'true'
ENV["RAILS_ENV"] ||= 'test'
envfile = Pathname.new(File.expand_path(Dir.pwd + "/config/environments/#{ENV["RAILS_ENV"]}.rb"))
unless envfile.read.match(/ENV.+PRSPEC/)
color("!!! set cache_classes (for reload classes) !!!", 31)
warn "Please replace #{envfile} settings."
mes = " config.cache_classes = ENV.has_key?('PRSPEC') ? false : true "
warn '-' * mes.length
warn mes
warn '-' * mes.length
end
require File.expand_path(Dir.pwd + "/config/environment")
Rails.application.config.cache_classes = false
require 'rspec/rails'
}

before_run {
ActionDispatch::Callbacks.new(Proc.new {}, false).call({})
ActiveSupport::DescendantsTracker.clear
ActiveSupport::Dependencies.clear
Rails.application.config.cache_classes = true
ActiveSupport::Dependencies.mechanism = :require
require 'spec/spec_helper'
}

# after_run {
# }

29 changes: 25 additions & 4 deletions lib/prefetch_rspec.rb
Expand Up @@ -29,6 +29,8 @@ def optparse(args)
case arg
when /^--port=(\d+)$/
@options[:port] = $1.to_i
when /^--rails$/
@options[:rails] = true
when /^--bundler$/
@options[:bundler] = true
when /^--drb$/
Expand Down Expand Up @@ -221,18 +223,37 @@ def call_after_run(err, out)
end

def load_config_prspecd
require 'pathname'
dot_prspecd = Pathname.new(Dir.pwd).join('.prspecd')
if dot_prspecd.exist?
self.instance_eval dot_prspecd.read, dot_prspecd.to_s
color("load .prspecd")
else
color(".prspecd not found", 31)
end
end

def load_config(path)
if path.exist?
self.instance_eval path.read, path.to_s
color("#{path} loaded")
else
color("#{path} not found", 31)
self.class.force_exit!
end
end

def detect_load_config
require 'pathname'
if options[:rails]
load_config Pathname.new(File.expand_path(__FILE__)).parent.parent.join('examples/rails.prspecd')
elsif options[:args].first
load_config Pathname.new(Dir.pwd).join(args.first)
else
load_config(Pathname.new(Dir.pwd).join('.prspecd'))
end
end

def listen
load_config_prspecd
detect_load_config

begin
@drb_service = DRb.start_service(drb_uri, self)
rescue DRb::DRbConnError => e
Expand Down
7 changes: 7 additions & 0 deletions spec/prefetch_rspec_spec.rb
Expand Up @@ -7,6 +7,7 @@
it "default" do
options = PrefetchRspec::Base.new([]).options
options[:args].should be_empty
options[:rails].should be_nil
options[:port].should be_nil
options[:bundler].should be_nil
end
Expand All @@ -31,6 +32,11 @@
base = PrefetchRspec::Base.new(['--bundler', 'a'])
base.options[:bundler].should be_true
end

it "rails option" do
base = PrefetchRspec::Base.new(['--rails', 'a'])
base.options[:rails].should be_true
end
end
end

Expand All @@ -55,6 +61,7 @@ def server(args = [])
unless @server
@server = PrefetchRspec::Server.new(args)
@server.stub(:color)
@server.stub(:detect_load_config)
end
@server
end
Expand Down

0 comments on commit 0f57f7b

Please sign in to comment.