Permalink
Browse files

load config change

  • Loading branch information...
1 parent 016a878 commit 0f57f7b7cc7ce873987bf3d1b6e37d7223234152 @hotchpotch hotchpotch committed Dec 10, 2010
Showing with 63 additions and 4 deletions.
  1. +31 −0 examples/rails.prspecd
  2. +25 −4 lib/prefetch_rspec.rb
  3. +7 −0 spec/prefetch_rspec_spec.rb
View
@@ -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 {
+# }
+
View
@@ -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$/
@@ -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
@@ -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
@@ -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
@@ -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

0 comments on commit 0f57f7b

Please sign in to comment.