Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.