A simple solution to an annoying problem!
# Rakefile task "assets:precompile" => "db:migrate" if ENV['MIGRATE_ON_PRECOMPILE'] # run to enable heroku config:set MIGRATE_ON_PRECOMPILE=1
A simple solution to an annoying problem!
# Rakefile task "assets:precompile" => "db:migrate" if ENV['MIGRATE_ON_PRECOMPILE'] # run to enable heroku config:set MIGRATE_ON_PRECOMPILE=1
Compare 2 objects without having to repeat all their variables and potentially miss something, only thing dangerous is adding something like a inline method cache, which would then break equality.
def ==(other)
self.class == other.class && instance_variables.all? do |i|
instance_variable_get(i) == other.instance_variable_get(i)
end
end
We don’t want to compile assets during test runs, since that is slow, but we also don’t want the asset pipeline to fail because assets are missing.
This will not work if you plan on doing javascript integration tests, but everything else should work fine.
Rails 5.1 added a flag for this which prints deprecations and will be removed in rails 5.2 so that is not a elegant solution either.
config.assets.unknown_asset_fallback = true
So we are now using this fix to fake assets being available!:
# config/environments/test.rb
# make our tests fast by avoiding asset compilation
# but do not raise when assets are not compiled either
Rails.application.config.assets.compile = false
Sprockets::Rails::Helper.prepend(Module.new do
def resolve_asset_path(path, *)
super || path
end
end)
Socket.gethostbyname is usually fast if your local machine has a normal name, because it crashes early, but if you have a name that looks like a real domain things take 5s.
Internally webbrick/config.rb does:
ruby -r socket -e 'Socket.gethostbyname(Socket.gethostname)'
Which is slow … wait for https://bugs.ruby-lang.org/issues/13007 to resolve … or rename your localhost to something that does not look like a domain to ruby.
Flay is terribly useful, but has terribly usability …
If the repo was not such a mess I’d make PRs to fix it, but tests are not even runnable and PRs to make the Readme readabe got rejected … so I’m not going to bother … a small excerpt from Samson
More config options can be found on it’s homepage
Just wanted to share this useful rake task which found a bunch of duplication and already prevented me from adding new duplication twice 🙂
desc "Analyze for code duplication (large, identical syntax trees) with fuzzy matching."
task :flay do
require 'flay' # do not require in production
files = Dir["{config,lib,app/**/*.{rb,erb}"]
files -= [
# Things you want to ignore
]
flay = Flay.run([*files, '--mass', '25']) # mass threshold is shown mass / occurrences
abort "Code duplication found" if flay.report.any?
end