params[:id].present?
nil.present?
( the original post was a hack adding String.filled? / NilClass.filled? )
params[:id].present?
nil.present?
( the original post was a hack adding String.filled? / NilClass.filled? )
# descriptive raise
# normale: raise 1 == TypeError: exception class/object expected
# now: raise 1 == RuntimeError: 1
class Object
def raise_with_helpfulness(*args)
raise_without_helpfulness(*args)
rescue TypeError => e
raise_without_helpfulness args.first.inspect if ['exception class/object expected', 'exception object expected'].include?(e.to_s)
raise_without_helpfulness e
end
alias_method_chain :raise, :helpfulness
end
I recently did the switch and it was fun, and now I finally got everything working, here are the steps I took:
Benefits:
Drawbacks
If you noticed spork startup getting slower when switching to Rails 2.3, your not alone 😉
Without hack: 18s startup
With hack: 2s startup 😀
Try it
#spec/spec_helper.rb
require 'spork/app_framework/rails'
Spork::AppFramework::Rails::NinjaPatcher.class_eval do
# 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){}
end
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_helper’ for rspec or ‘./spec/spec_helper’ for minitest, which can be copied without modification (like adding ‘../../’) and prevents duplicate spec_helper calls
#unify_spec_helper.rb
files = Dir["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_helper'\n"
else
line
end
end
File.open(file,'w'){|f| f.write lines.join('') }
end
Run: ruby unify_spec_helper.rb