Skip to content

Instantly share code, notes, and snippets.

@lcpriest
Created May 16, 2018 02:35
Show Gist options
  • Select an option

  • Save lcpriest/c6e221b88a47d8ef8c5d4737a99b4f03 to your computer and use it in GitHub Desktop.

Select an option

Save lcpriest/c6e221b88a47d8ef8c5d4737a99b4f03 to your computer and use it in GitHub Desktop.

Revisions

  1. lcpriest created this gist May 16, 2018.
    32 changes: 32 additions & 0 deletions missing_tests.rake
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    namespace :missing_tests do
    def progress(name, x, y)
    print "\r #{name}: #{x}/#{y} %6.2f%%" % [x.to_f / y * 100]
    end

    def generate_files(name)
    kind = name.to_s.singularize
    collection = Dir.glob Rails.root.join('app', name.to_s, '**', '*').to_s
    root = Rails.root.join('app', name.to_s).to_s << '/'
    ext = case name
    when :controllers then '_controller.rb'
    when :models then '.rb'
    when :jobs then '_job.rb'
    when :mailers then '_mailer.rb'
    end

    count = collection.count
    collection.each_with_index do |filename, index|

    `rails g test_unit:#{kind} #{Regexp.last_match(1)} -s` if filename.match(/#{root}(.+)#{ext}/)
    progress name, index, count
    end
    end

    task generate_tests: :environment do
    generate_files :controllers
    generate_files :models
    generate_files :jobs
    generate_files :mailers
    end
    end