Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save elliotlarson/50b8fae47dd5394ba50fb4a4366bf10e to your computer and use it in GitHub Desktop.
Save elliotlarson/50b8fae47dd5394ba50fb4a4366bf10e to your computer and use it in GitHub Desktop.
require('fileutils')
require('tempfile')
class AddRspec
def self.call
new.call
end
def call
spec_filepaths.each { |spec_filepath| process_file(spec_filepath) }
end
private
def spec_filepaths
Dir.glob(File.join(current_dir, 'spec', '**', '*_spec.rb'))
end
def current_dir
File.dirname(File.expand_path(__FILE__))
end
def process_file(filepath)
tempfile = Tempfile.new
File.foreach(filepath) do |line|
line = line.gsub(/^/, 'RSpec.') if line =~ /^describe/
tempfile.puts(line)
end
tempfile.close
FileUtils.mv(tempfile.path, filepath)
end
end
AddRspec.call
puts('=> Done')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment