Created
July 21, 2011 16:54
-
-
Save kennethkalmer/1097617 to your computer and use it in GitHub Desktop.
Helper files for migrating from rspec-rails 1.3 to rspec-rails 2.6
This file contains 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
#!/usr/bin/env ruby | |
# | |
# Migrate from old assigns[]= to assign() | |
Dir["spec/**/*_spec.rb"].each do |file| | |
changed = File.readlines( file ).map do |line| | |
pattern = /assigns\[(:[\w\d_]+)\] = (.+)$/ | |
if line =~ pattern | |
puts "Match: #{line}" | |
puts "Assign: #{$1}" | |
puts "Value: #{$2}" | |
replacement = line.gsub( pattern, "assign( #{$1.strip}, #{$2.strip} )" ) | |
puts "Replacement: #{replacement}" | |
puts | |
replacement | |
else | |
line | |
end | |
end | |
File.open( file, 'w+' ) { |f| f.write( changed.join ) } | |
end |
This file contains 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
#!/usr/bin/env ruby | |
# | |
# Fix rspec's be_close deprecations | |
Dir["spec/**/*_spec.rb"].each do |file| | |
changed = File.readlines( file ).map do |line| | |
pattern = /be_close\(([\s\d\.]+),([\s\d\.]+)\)/ | |
if line =~ pattern | |
puts "Match: #{line}" | |
puts "Number: #{$1}" | |
puts "Variance: #{$2}" | |
replacement = line.gsub( pattern, "be_within( #{$2.strip} ).of( #{$1.strip} )" ) | |
puts "Replacement: #{replacement}" | |
puts | |
replacement | |
else | |
line | |
end | |
end | |
File.open( file, 'w+' ) { |f| f.write( changed.join ) } | |
end |
This file contains 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
#!/usr/bin/env ruby | |
# | |
# Migrate from old has_tag('el', 'content') to have_selector('el', :content => 'content') | |
Dir["spec/**/*_spec.rb"].each do |file| | |
changed = File.readlines( file ).map do |line| | |
pattern = /have_tag\((['"\w\d\[\]=]+), (.*)\)$/ | |
if line =~ pattern | |
puts "Match: #{line}" | |
puts "Tag: #{$1}" | |
puts "Content: #{$2}" | |
replacement = line.gsub( pattern, "have_selector( #{$1.strip}, :content => #{$2.strip.gsub('/', '"')} )" ).gsub('response', 'rendered') | |
puts "Replacement: #{replacement}" | |
puts | |
replacement | |
else | |
line | |
end | |
end | |
File.open( file, 'w+' ) { |f| f.write( changed.join ) } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment