Skip to content

Instantly share code, notes, and snippets.

@jonatas
Last active November 15, 2019 22:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jonatas/836eb9bff1c4fa20cfee1b58ac4ee27b to your computer and use it in GitHub Desktop.
Save jonatas/836eb9bff1c4fa20cfee1b58ac4ee27b to your computer and use it in GitHub Desktop.
Try to automated replace create for build_stubbed in specs
require 'rubygems'
require 'fast'
def nice_experiment_with(file)
parts = file.split('/')
dir = parts[0..-2]
filename = "experiment_#{parts[-1]}"
File.join(*dir, filename)
end
ignored =
if File.exist?('failed.txt')
File.readlines('failed.txt').map(&:chomp)
else
[]
end
def experiment(file, search, replacement)
ast = Fast.ast_from_file(file)
results = Fast.search(ast, search)
unless results.empty?
new_content = Fast.replace_file(file, search, replacement)
new_spec = nice_experiment_with(file)
return if File.exist?(new_spec)
File.open(new_spec, 'w+') { |f| f.puts new_content }
if system("bin/spring rspec #{new_spec}")
system "mv #{new_spec} #{file}"
puts "✅ #{file}"
else
puts "🔴 #{file}"
end
end
rescue
puts "🔴🔴 🔴 #{file}: #{$ERROR_INFO}"
end
`grep ' create' spec/**/*_spec.rb | awk -s: '{ print $1}'`.lines.map { |e| e[0..-3] }.uniq.each do |file|
next if ignored.include?(file)
next if file =~ /chewy/
puts file
experiment(file, '(send nil create)', ->(node) { replace(node.location.selector, 'build_stubbed') })
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment