Skip to content

Instantly share code, notes, and snippets.

@kennethkalmer
Created July 21, 2011 16:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kennethkalmer/1097617 to your computer and use it in GitHub Desktop.
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
#!/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
#!/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
#!/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