Added Rspec and Webrat plugins and started porting Selenium on Rails tests to Rspec Plain Text Stories driving Webrat driving Selenium.

This commit is contained in:
Luke Melia 2008-06-18 02:57:57 -04:00
parent 0600756bbf
commit 0f7d6f7a1d
602 changed files with 47788 additions and 29 deletions

4
script/spec Executable file
View file

@ -0,0 +1,4 @@
#!/usr/bin/env ruby
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../vendor/plugins/rspec/lib"))
require 'spec'
exit ::Spec::Runner::CommandLine.run(::Spec::Runner::OptionParser.parse(ARGV, STDERR, STDOUT))

116
script/spec_server Executable file
View file

@ -0,0 +1,116 @@
#!/usr/bin/env ruby
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../vendor/plugins/rspec/lib' # For rspec installed as plugin
require 'rubygems'
require 'drb/drb'
require 'rbconfig'
require 'spec'
require 'optparse'
# This is based on Florian Weber's TDDMate
module Spec
module Runner
class RailsSpecServer
def run(argv, stderr, stdout)
$stdout = stdout
$stderr = stderr
base = ActiveRecord::Base
def base.clear_reloadable_connections!
active_connections.each do |name, conn|
if conn.requires_reloading?
conn.disconnect!
active_connections.delete(name)
end
end
end
if ActionController.const_defined?(:Dispatcher)
dispatcher = ::ActionController::Dispatcher.new($stdout)
dispatcher.cleanup_application
elsif ::Dispatcher.respond_to?(:reset_application!)
::Dispatcher.reset_application!
else
raise "Application reloading failed"
end
if Object.const_defined?(:Fixtures) && Fixtures.respond_to?(:reset_cache)
Fixtures.reset_cache
end
::Dependencies.mechanism = :load
require_dependency('application.rb') unless Object.const_defined?(:ApplicationController)
load File.dirname(__FILE__) + '/../spec/spec_helper.rb'
if in_memory_database?
load "#{RAILS_ROOT}/db/schema.rb" # use db agnostic schema by default
ActiveRecord::Migrator.up('db/migrate') # use migrations
end
::Spec::Runner::CommandLine.run(
::Spec::Runner::OptionParser.parse(
argv,
$stderr,
$stdout
)
)
end
def in_memory_database?
ENV["RAILS_ENV"] == "test" and
::ActiveRecord::Base.connection.class.to_s == "ActiveRecord::ConnectionAdapters::SQLite3Adapter" and
::Rails::Configuration.new.database_configuration['test']['database'] == ':memory:'
end
end
end
end
puts "Loading Rails environment"
ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'dispatcher'
def restart_test_server
puts "restarting"
config = ::Config::CONFIG
ruby = File::join(config['bindir'], config['ruby_install_name']) + config['EXEEXT']
command_line = [ruby, $0, ARGV].flatten.join(' ')
exec(command_line)
end
def daemonize(pid_file = nil)
return yield if $DEBUG
pid = Process.fork{
Process.setsid
Dir.chdir(RAILS_ROOT)
trap("SIGINT"){ exit! 0 }
trap("SIGTERM"){ exit! 0 }
trap("SIGHUP"){ restart_test_server }
File.open("/dev/null"){|f|
STDERR.reopen f
STDIN.reopen f
STDOUT.reopen f
}
yield
}
puts "spec_server launched. (PID: %d)" % pid
File.open(pid_file,"w"){|f| f.puts pid } if pid_file
exit! 0
end
options = Hash.new
opts = OptionParser.new
opts.on("-d", "--daemon"){|v| options[:daemon] = true }
opts.on("-p", "--pid PIDFILE"){|v| options[:pid] = v }
opts.parse!(ARGV)
puts "Ready"
exec_server = lambda {
trap("USR2") { restart_test_server } if Signal.list.has_key?("USR2")
DRb.start_service("druby://127.0.0.1:8989", Spec::Runner::RailsSpecServer.new)
DRb.thread.join
}
if options[:daemon]
daemonize(options[:pid], &exec_server)
else
exec_server.call
end

77
script/story Executable file
View file

@ -0,0 +1,77 @@
#!/usr/bin/env ruby
require 'rubygems'
class StoryCommand
ROOT_PATH = File.expand_path(File.dirname(__FILE__) + "/..")
STORIES_PATH = "#{ROOT_PATH}/stories"
STEP_MATCHERS_PATH = "#{ROOT_PATH}/stories/steps"
HELPER_PATH = "#{ROOT_PATH}/stories/helper"
DRIVER_MANAGER_PATH = "#{ROOT_PATH}/lib/selenium_driver_manager"
require DRIVER_MANAGER_PATH
def self.run
self.new.run
end
def run
if ARGV.reject { |a| a =~ /^-/ }.any?
run_story_files(ARGV.dup)
else
run_story_files(all_story_files)
end
ensure
SeleniumDriverManager.instance.stop
end
def all_story_files
Dir["#{STORIES_PATH}/**/*.story"].uniq
end
def clean_story_paths(paths)
paths.reject! { |path| path =~ /^-/ }
paths.map! { |path| File.expand_path(path) }
paths.map! { |path| path.gsub(/\.story$/, "") }
paths.map! { |path| path.gsub(/#{STORIES_PATH}\//, "") }
end
def run_story_files(stories)
clean_story_paths(stories).each do |story|
setup_and_run_story(File.readlines("#{STORIES_PATH}/#{story}.story"), story)
end
end
def setup_and_run_story(lines, story_name)
require HELPER_PATH
steps = steps_for_story(lines, story_name)
steps.reject! { |step| !File.exist?("#{STEP_MATCHERS_PATH}/#{step}.rb") }
steps.each { |step| require "#{STEP_MATCHERS_PATH}/#{step}" }
run_story(lines, steps)
end
def steps_for_story(lines, story_name)
if lines.first =~ /^# steps: /
lines.first.gsub(/^# steps: /, "").split(",").map(&:strip)
else
story_name.to_s.split("/")
end
end
def run_story(lines, steps)
tempfile = Tempfile.new("story")
lines.each do |line|
tempfile.puts line
end
tempfile.close
with_steps_for(*steps.map(&:to_sym)) do
run tempfile.path, :type => SeleniumRailsStory
end
end
end
StoryCommand.run