-
-
Save dkubb/6ae4bacedb5b7c11615a to your computer and use it in GitHub Desktop.
A metrics:rake task for rails (WIP)
This file contains 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
# encoding: utf-8 | |
if defined?(::Devtools) | |
# Load all rake tasks | |
Rake.application.load_imports | |
# Remove metrics:mutant from devtools | |
task('metrics:mutant').clear | |
namespace :metrics do | |
allowed_versions = %w(mri-1.9.3 mri-2.0.0 rbx-1.9.3) | |
enabled = begin | |
require 'mutant' | |
defined?(Mutant) | |
rescue LoadError | |
false | |
end | |
config = Devtools.project.mutant | |
enabled &&= config.enabled? && !ENV['DEVTOOLS_SELF'] | |
if enabled && allowed_versions.include?(Devtools.rvm) | |
desc 'Run mutant' | |
task mutant: :coverage do | |
# Eager load application and dependencies | |
require File.expand_path('../../../config/environment', __FILE__) | |
# All classes in the system | |
original = ObjectSpace.each_object(Class).to_a | |
Rails.application.eager_load! | |
classes = (ObjectSpace.each_object(Class).to_a - original).map(&:name) | |
# Remove classes in namespaces that should not be mutation covered | |
classes -= classes.grep(/\A(?:ActionView|Devise|Spree)::/) | |
status = Mutant::CLI.run([*classes, config.strategy]) | |
if status.nonzero? | |
Devtools.notify 'Mutant task is not successful' | |
end | |
end | |
else | |
desc 'Run Mutant' | |
task mutant: :coverage do | |
$stderr.puts 'Mutant is disabled' | |
end | |
end | |
end | |
end |
undefined method `init_project' for Devtools:Module
@dkubb, do you still make use of this script? I've modified it somewhat: https://gist.github.com/mockdeep/7014387
But I'm still getting some issues. Stack trace posted here: mbj/mutant#21 (comment)
I'd love to get a better sense for how you're running mutant in rails.
@mockdeep I've updated the rake task with the latest version of my mutant task.
Excellent. This is going to be really helpful. Thanks!
Hmm, running into some issues with this. The problem is that I have testing gems like webmock and vcr that don't get loaded with the script. It's loading classes in dev mode. But then when I try to run in test mode everything is already loaded, so the difference in classes is empty. Not sure of a good way around it.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@dkubb A mutant rails integration would basically ad a "--rails" flag calling the following loc?
The rest is scenario specific?