Created
December 3, 2017 23:46
-
-
Save elliotlarson/50b8fae47dd5394ba50fb4a4366bf10e to your computer and use it in GitHub Desktop.
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
| 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