Last active
November 15, 2019 22:55
-
-
Save jonatas/836eb9bff1c4fa20cfee1b58ac4ee27b to your computer and use it in GitHub Desktop.
Try to automated replace create for build_stubbed in specs
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 '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