Created
November 27, 2015 19:10
-
-
Save benzittlau/b54a6d0f733f53892772 to your computer and use it in GitHub Desktop.
Searches for a certain set of files, and injects the same line into each line at a matching place
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
def inject_model_fixtures(filepath) | |
content = File.read(filepath).split("\n") | |
block_start = content.find_index{|l| l =~ /^RSpec.describe/} | |
return false if block_start.nil? | |
content.insert(block_start + 1, " include_context 'model_fixtures'") | |
File.open(filepath, 'wb') { |file| file.write(content.join("\n")) } | |
true | |
end | |
files = `ag junk_account -l`.split("\n") | |
files.each do |file| | |
puts "Couldn't find Rspec block for #{file}" unless inject_model_fixtures(file) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment