diff --git a/examples/rails.prspecd b/examples/rails.prspecd new file mode 100644 index 0000000..977f479 --- /dev/null +++ b/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 { +# } + diff --git a/lib/prefetch_rspec.rb b/lib/prefetch_rspec.rb index 8ecdd74..28ebebc 100644 --- a/lib/prefetch_rspec.rb +++ b/lib/prefetch_rspec.rb @@ -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 diff --git a/spec/prefetch_rspec_spec.rb b/spec/prefetch_rspec_spec.rb index 57783c1..fcd6e05 100644 --- a/spec/prefetch_rspec_spec.rb +++ b/spec/prefetch_rspec_spec.rb @@ -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