mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-25 02:06:10 +01:00
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:
parent
7b432a74ed
commit
2c09db45c5
602 changed files with 47788 additions and 29 deletions
77
script/story
Executable file
77
script/story
Executable 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue