-
-
Save bogdanRada/117f51ef815407675865e4c76aaf3a6c to your computer and use it in GitHub Desktop.
common rails rake tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--no-doc | |
--style-measure 80 | |
--abc-max 9 | |
--abc-glob {rakefile,Gemfile,**/*.{rb,rake,example}} | |
--style-glob {rakefile,Gemfile,**/*.{rb,rake,example}} | |
--style-exclude db/schema.rb | |
--style-exclude config/initializers/secret_token.rb | |
--abc-exclude Class#method |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ['development', 'test', nil].include?(ENV['RAILS_ENV']) && defined?(Cane) | |
require 'cane/rake_task' | |
namespace :cane do | |
desc '' | |
Cane::RakeTask.new(:quality) do |cane| | |
cane.canefile = '.cane' | |
end | |
desc 'Check abc metrics with cane' | |
Cane::RakeTask.new(:warn) do |cane| | |
cane.canefile = '.cane' | |
cane.abc_max = 7 | |
cane.no_doc = true | |
cane.no_style = true | |
end | |
desc 'Check code quality metrics with cane for all files' | |
Cane::RakeTask.new(:all) do |cane| | |
cane.canefile = '.cane' | |
cane.style_exclude = [] | |
cane.abc_exclude = [] | |
end | |
end | |
desc 'Run cane to check quality metrics' | |
task :cane => 'cane:quality' | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
desc 'Generate a checksum for the current gem file' | |
task :checksum do |task| | |
require 'digest/sha2' | |
root = File.dirname(__FILE__) | |
gem_file = Dir[File.join(root, '..', '..', '*.gem')].first | |
checksum = Digest::SHA512.new.hexdigest(File.read(gem_file)) | |
checksum_file = File.basename(gem_file) | |
checksum_path = "checksum/#{checksum_file}.sha512" | |
puts checksum | |
File.open(checksum_path, 'w') do |file| | |
file.write checksum | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MyApp::RakeSupport end | |
class MyApp::RakeSupport::Jslint | |
class << self | |
def run | |
puts "Running jslint for #{all_items.join(', ')}." | |
all_items.each do |item| | |
system command_for(item) | |
@exit_code = $?.to_i | |
break unless @exit_code == 0 | |
end | |
exit_gracefully | |
end | |
private | |
def command | |
@command ||= | |
'jslint --indent 2 --maxlen 80 --browser --sloppy --maxerr 5' | |
end | |
def command_for(item) | |
if File.directory?(item) | |
"find #{item} -iname '*.js' | xargs #{command}" | |
else | |
"#{command} #{item}" | |
end | |
end | |
def all_items | |
@all ||= js_directories + js_files | |
end | |
def js_directories | |
@dirs ||= | |
['app/assets/javascripts'] + | |
Dir['spec/javascripts/**'] - | |
['spec/javascripts/support'] | |
end | |
def js_files | |
@files ||= [ | |
'spec/javascripts/support/karma_config.js', | |
] | |
end | |
def exit_gracefully | |
puts | |
exit(@exit_code.to_i) unless @exit_code == 0 | |
end | |
end | |
end | |
desc 'Run jslint' | |
task(:jslint) { MyApp::RakeSupport::Jslint.run } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MyApp::RakeSupport end | |
class MyApp::RakeSupport::Karma | |
class << self | |
def run | |
system command | |
@exit_code = $?.to_i | |
exit_gracefully | |
end | |
private | |
def command | |
"karma start #{config} --single-run" | |
end | |
def config | |
'spec/javascripts/support/karma_config.js' | |
end | |
def exit_gracefully | |
puts | |
exit(@exit_code.to_i) unless @exit_code == 0 | |
end | |
end | |
end | |
desc 'Run javascript specs' | |
task(:karma) { MyApp::RakeSupport::Karma.run } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function (config) { | |
config.set({ | |
// base path, that will be used to resolve files and exclude | |
basePath: '../../..', | |
// frameworks to use | |
frameworks: ['jasmine'], | |
// list of files / patterns to load in the browser | |
files: [ | |
'vendor/assets/javascripts/**/*.js', | |
'app/assets/javascripts/**/*.js', | |
'spec/javascripts/support/*.js', | |
'spec/javascripts/**/*_spec.js', | |
], | |
// Default is {'**/*.coffee': 'coffee'} | |
preprocessors: {}, | |
// list of files to exclude | |
exclude: [ | |
'spec/javascripts/support/karma_config.js', | |
], | |
// test results reporter to use | |
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage' | |
reporters: ['dots'], | |
// Start these browsers, currently available: | |
// - Chrome | |
// - ChromeCanary | |
// - Firefox | |
// - Opera | |
// - Safari (only Mac) | |
// - PhantomJS | |
// - IE (only Windows) | |
browsers: ['PhantomJS'], | |
}); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"devDependencies": { | |
"jslint": "~0.2.5", | |
"karma": "~0.10.8" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env rake | |
# Add your own tasks in files placed in lib/tasks ending in .rake, | |
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. | |
require File.expand_path('../config/application', __FILE__) | |
MyApp::Application.load_tasks | |
task :default => [] | |
Rake::Task[:default].clear_prerequisites | |
task :default => [:cane, 'spec:all'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ['development', 'test', nil].include?(ENV['RAILS_ENV']) | |
require 'rspec/core/rake_task' | |
namespace :spec do | |
desc 'Run all unit specs' | |
RSpec::Core::RakeTask.new :unit do |task| | |
task.pattern = Dir['spec/**/*_spec.rb'] - Dir['spec/features/**/*_spec.rb'] | |
end | |
desc 'Run all specs' | |
task :all => ['spec:unit', 'spec:features'] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment