Skip to content

Instantly share code, notes, and snippets.

@dkubb
Last active December 19, 2015 02:49
Show Gist options
  • Save dkubb/6ae4bacedb5b7c11615a to your computer and use it in GitHub Desktop.
Save dkubb/6ae4bacedb5b7c11615a to your computer and use it in GitHub Desktop.
A metrics:rake task for rails (WIP)
# 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
@mbj
Copy link

mbj commented Jul 2, 2013

@dkubb A mutant rails integration would basically ad a "--rails" flag calling the following loc?

# path maybe needs a fix
require File.expand_path('../../../config/environment', __FILE__)
Rails.application.eager_load!

The rest is scenario specific?

@mockdeep
Copy link

undefined method `init_project' for Devtools:Module

@mockdeep
Copy link

@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.

@dkubb
Copy link
Author

dkubb commented Oct 19, 2013

@mockdeep I've updated the rake task with the latest version of my mutant task.

@mockdeep
Copy link

Excellent. This is going to be really helpful. Thanks!

@mockdeep
Copy link

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