You are currently browsing the tag archive for the 'Test' tag.
If you noticed spork startup getting slower when switching to Rails 2.3, your not alone
- Views are eager loaded
- app/ is eager loaded (when config.cache_classes is on)
Without hack: 18s startup
With hack: 2s startup
Try it
#spec/spec_helper.rb
begin
require 'spork/app_framework/rails'
module Spork::AppFramework::Rails::NinjaPatcher
# views are preloaded spork must be restarted for view changes
def delay_eager_view_loading
puts "removed because i am too slow..."
end
# do not preload application files
# alternatively urn off config.cache_classes
def delay_app_preload
::Rails::Initializer.send(:define_method, :load_application_classes) do
end
end
end
rescue
end
Spork.prefork do
...
If you got a big project, chances are spec_helper is required through different ways, File.expand_path / File.join() / … which results in it being loaded several times!
Try it:
#spec_helper.rb print "YEP!"
rake spec -> “YEP!YEP!YEP!YEP!YEP!YEP!YEP!YEP!……”
So how to prevent it ?
Unify!
Unify it to ’spec/spec_helper’ which is dead-simple, can be copied without modification (like adding ‘../../’) and prevents duplicate spec_helper calls
#unify_spec_helper.rb
require 'rake'
files = FileList["spec/**/*_spec.rb"].reject{|file|File.directory?(file)}
files.each do |file|
lines = File.readlines(file)
lines = lines.map do |line|
if line =~ /require.*spec_helper/
"require 'spec/spec_helper'\n"
else
line
end
end
File.open(file,'w'){|f| f.write lines.join('') }
end
Run: ruby unify_spec_helper.rb
On my new project we had the problem that some specs failed when ran on their own, and some specs produces strange output (like “use object_id”), so I build a helper that runs each test on its own and could pinpoint the problem.
rake spec:one_by_one
it is now included in the single test rails plugin
Autotest until recently only had one flaw: it could not be used for large test suites, since after each red-green cycle I had to wait x minutes for all tests to pass, which made autotest really frustrating.
So grep autotest (the ‘without ZenTest version’) from github and enjoy “autotest -c” (also works with auospec).
And remember kids: always run autospec with script/spec_server and its twice the fun
All of the sudden some columns began to misbehave in cucumber tests, claiming that “Attempt to call private method (NoMethodError)” on normal column attributes!
A simple fix for this, essentially saying that a method is not private when its a column:
#features/support/ar_private_fix.rb required from env.rb
unless ActiveRecord::Base.methods.include?('private_method_defined_with_fix?')
class ActiveRecord::Base
class << self
def private_method_defined_with_fix?(method)
return false if columns_hash.keys.include?(method.to_s)
private_method_defined_without_fix?(method)
end
alias_method_chain :private_method_defined?, :fix
end
end
end
