Skip to content

Instantly share code, notes, and snippets.

@benzittlau
Created November 27, 2015 19:10
Show Gist options
  • Save benzittlau/b54a6d0f733f53892772 to your computer and use it in GitHub Desktop.
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
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