I need to create 1500+ ruby files from a template for some testing I'm doing with Selenium.
The template looks like this:
class $CLASS_NAME
require "spec"
attr_accessor :title
include Spec::Example::ExampleGroupMethods
include Spec::Matchers
def initialize
@title = "$OLD_URL -> $NEW_URL"
end
def execute(selenium)
selenium.open "$OLD_URL"
sleep 1
puts 'Opening...'
sleep 1
url = selenium.get_location
puts 'Grabbing location...'
sleep 1
puts 'The URL is ' + url
puts 'Doing match...'
sleep 1
/$NEW_URL/.match(url).should_not be nil
puts "\n##### Success! #####\n\r"
end # execute
I have a load of URL's I need to insert - one into each file, replacing '$OLD_URL' and '$NEW_URL'.
Is there anyway to do something like this?
x = 0
while (x < 1500)
{
open template.rb
find all instances of $CLASS_NAME and replace with xxx from classnames.txt
find all instances of $OLD_URL and replace with xxx from listofurls.csv
find all instances of $NEW_URL and replace with xxx from listofurls.csv
save file as ('redirect_' + 'x++')
x++
}