makevoid-taza 0.8.6
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +74 -0
- data/Manifest.txt +61 -0
- data/README +79 -0
- data/README.textile +1 -0
- data/VERSION.yml +4 -0
- data/bin/taza +17 -0
- data/generators/flow/flow_generator.rb +57 -0
- data/generators/flow/templates/flow.rb.erb +9 -0
- data/generators/page/page_generator.rb +58 -0
- data/generators/page/templates/functional_page_spec.rb.erb +8 -0
- data/generators/page/templates/page.rb.erb +8 -0
- data/generators/partial/partial_generator.rb +57 -0
- data/generators/partial/templates/partial.rb.erb +7 -0
- data/generators/site/site_generator.rb +56 -0
- data/generators/site/templates/site.rb.erb +10 -0
- data/generators/site/templates/site.yml.erb +3 -0
- data/lib/app_generators/taza/taza_generator.rb +74 -0
- data/lib/app_generators/taza/templates/config.yml.erb +3 -0
- data/lib/app_generators/taza/templates/rakefile.rb.erb +10 -0
- data/lib/app_generators/taza/templates/spec_helper.rb.erb +11 -0
- data/lib/extensions/array.rb +10 -0
- data/lib/extensions/hash.rb +15 -0
- data/lib/extensions/object.rb +33 -0
- data/lib/extensions/string.rb +11 -0
- data/lib/taza.rb +24 -0
- data/lib/taza/browser.rb +53 -0
- data/lib/taza/entity.rb +55 -0
- data/lib/taza/fixture.rb +68 -0
- data/lib/taza/fixtures.rb +24 -0
- data/lib/taza/flow.rb +40 -0
- data/lib/taza/page.rb +128 -0
- data/lib/taza/settings.rb +33 -0
- data/lib/taza/site.rb +150 -0
- data/lib/taza/tasks.rb +54 -0
- data/spec/array_spec.rb +17 -0
- data/spec/browser_spec.rb +86 -0
- data/spec/entity_spec.rb +35 -0
- data/spec/fixture_spec.rb +51 -0
- data/spec/fixtures_spec.rb +47 -0
- data/spec/flow_generator_spec.rb +50 -0
- data/spec/hash_spec.rb +15 -0
- data/spec/object_spec.rb +29 -0
- data/spec/page_generator_spec.rb +56 -0
- data/spec/page_module_spec.rb +165 -0
- data/spec/page_spec.rb +105 -0
- data/spec/partial_generator_spec.rb +38 -0
- data/spec/project_generator_spec.rb +56 -0
- data/spec/sandbox/config.yml +3 -0
- data/spec/sandbox/config/config.yml +1 -0
- data/spec/sandbox/config/site_name.yml +5 -0
- data/spec/sandbox/fixtures/examples.yml +15 -0
- data/spec/sandbox/fixtures/foo_site/bars.yml +2 -0
- data/spec/sandbox/fixtures/foos.yml +3 -0
- data/spec/sandbox/fixtures/users.yml +3 -0
- data/spec/sandbox/flows/batman.rb +5 -0
- data/spec/sandbox/flows/robin.rb +4 -0
- data/spec/sandbox/pages/foo/bar.rb +9 -0
- data/spec/sandbox/pages/foo/bay.rb +10 -0
- data/spec/sandbox/pages/foo/baz.rb +11 -0
- data/spec/sandbox/pages/foo/partials/partial_the_reckoning.rb +2 -0
- data/spec/settings_spec.rb +92 -0
- data/spec/site_fixtures_spec.rb +17 -0
- data/spec/site_generator_spec.rb +56 -0
- data/spec/site_spec.rb +268 -0
- data/spec/spec_helper.rb +57 -0
- data/spec/string_spec.rb +8 -0
- data/spec/taza_bin_spec.rb +13 -0
- data/spec/taza_tasks_spec.rb +56 -0
- data/taza.gemspec +46 -0
- metadata +196 -0
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rubigen'
|
3
|
+
require 'activesupport'
|
4
|
+
|
5
|
+
class SiteGenerator < RubiGen::Base
|
6
|
+
default_options :author => nil
|
7
|
+
attr_reader :name
|
8
|
+
|
9
|
+
def initialize(runtime_args, runtime_options = {})
|
10
|
+
super
|
11
|
+
usage if args.empty?
|
12
|
+
@name = args.shift
|
13
|
+
extract_options
|
14
|
+
end
|
15
|
+
|
16
|
+
def manifest
|
17
|
+
record do |m|
|
18
|
+
site_path = File.join('lib','sites')
|
19
|
+
m.template "site.rb.erb", File.join(site_path,"#{name.underscore}.rb")
|
20
|
+
m.directory File.join(site_path,"#{name.underscore}")
|
21
|
+
m.directory File.join(site_path,("#{name.underscore}"),"flows")
|
22
|
+
m.directory File.join(site_path,("#{name.underscore}"),"pages")
|
23
|
+
m.directory File.join(site_path,("#{name.underscore}"),"pages","partials")
|
24
|
+
m.directory File.join('spec','isolation',name.underscore)
|
25
|
+
m.template "site.yml.erb", File.join('config',"#{name.underscore}.yml")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
protected
|
30
|
+
def banner
|
31
|
+
<<-EOS
|
32
|
+
Creates a taza site.
|
33
|
+
|
34
|
+
USAGE: #{$0} #{spec.name} name
|
35
|
+
EOS
|
36
|
+
end
|
37
|
+
|
38
|
+
def add_options!(opts)
|
39
|
+
# opts.separator ''
|
40
|
+
# opts.separator 'Options:'
|
41
|
+
# For each option below, place the default
|
42
|
+
# at the top of the file next to "default_options"
|
43
|
+
# opts.on("-a", "--author=\"Your Name\"", String,
|
44
|
+
# "Some comment about this option",
|
45
|
+
# "Default: none") { |options[:author]| }
|
46
|
+
# opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
|
47
|
+
end
|
48
|
+
|
49
|
+
def extract_options
|
50
|
+
# for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
|
51
|
+
# Templates can access these value via the attr_reader-generated methods, but not the
|
52
|
+
# raw instance variable value.
|
53
|
+
# @author = options[:author]
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rubigen'
|
3
|
+
class TazaGenerator < RubiGen::Base
|
4
|
+
DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
|
5
|
+
Config::CONFIG['ruby_install_name'])
|
6
|
+
|
7
|
+
default_options :author => nil
|
8
|
+
|
9
|
+
attr_reader :name
|
10
|
+
|
11
|
+
def initialize(runtime_args, runtime_options = {})
|
12
|
+
super
|
13
|
+
usage if args.empty?
|
14
|
+
@destination_root = File.expand_path(args.shift)
|
15
|
+
@name = base_name
|
16
|
+
extract_options
|
17
|
+
end
|
18
|
+
|
19
|
+
def manifest
|
20
|
+
record do |m|
|
21
|
+
create_directories(m)
|
22
|
+
m.template "rakefile.rb.erb", "rakefile"
|
23
|
+
m.template "config.yml.erb", File.join("config","config.yml")
|
24
|
+
m.template "spec_helper.rb.erb", File.join("spec","spec_helper.rb")
|
25
|
+
m.dependency "install_rubigen_scripts", [destination_root, 'taza'],
|
26
|
+
:shebang => options[:shebang], :collision => :force
|
27
|
+
m.template "console.erb", File.join("script","console")
|
28
|
+
m.template "console.cmd.erb", File.join("script","console.cmd")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def create_directories(m)
|
33
|
+
BASEDIRS.each { |path| m.directory path }
|
34
|
+
m.directory File.join('lib','sites')
|
35
|
+
m.directory File.join('spec','isolation')
|
36
|
+
m.directory File.join('spec','integration')
|
37
|
+
m.directory File.join('spec','story')
|
38
|
+
m.directory 'script'
|
39
|
+
end
|
40
|
+
|
41
|
+
protected
|
42
|
+
def banner
|
43
|
+
<<-EOS
|
44
|
+
USAGE: #{spec.name} path/for/your/test/project [options]
|
45
|
+
EOS
|
46
|
+
end
|
47
|
+
|
48
|
+
def add_options!(opts)
|
49
|
+
opts.separator ''
|
50
|
+
opts.separator 'Options:'
|
51
|
+
# For each option below, place the default
|
52
|
+
# at the top of the file next to "default_options"
|
53
|
+
# opts.on("-a", "--author=\"Your Name\"", String,
|
54
|
+
# "Some comment about this option",
|
55
|
+
# "Default: none") { |options[:author]| }
|
56
|
+
opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
|
57
|
+
end
|
58
|
+
|
59
|
+
def extract_options
|
60
|
+
# for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
|
61
|
+
# Templates can access these value via the attr_reader-generated methods, but not the
|
62
|
+
# raw instance variable value.
|
63
|
+
# @author = options[:author]
|
64
|
+
end
|
65
|
+
|
66
|
+
# Installation skeleton. Intermediate directories are automatically
|
67
|
+
# created so don't sweat their absence here.
|
68
|
+
BASEDIRS = %w(
|
69
|
+
lib
|
70
|
+
config
|
71
|
+
script
|
72
|
+
spec
|
73
|
+
)
|
74
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<%= "#Generated at #{Time.now}" %>
|
2
|
+
require 'rubygems'
|
3
|
+
require 'taza/tasks'
|
4
|
+
|
5
|
+
Taza::Rake::Tasks.new do |t|
|
6
|
+
file_hole = "artifacts/#{Time.now.to_i}"
|
7
|
+
t.spec_opts = ["--format html:#{file_hole}/index.html",
|
8
|
+
"--format p",
|
9
|
+
"--format failing_examples:#{file_hole}/failing_examples.txt"]
|
10
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
ENV['TAZA_ENV'] = "isolation" if ENV['TAZA_ENV'].nil?
|
2
|
+
require 'rubygems'
|
3
|
+
require 'spec'
|
4
|
+
require 'mocha'
|
5
|
+
|
6
|
+
lib_path = File.expand_path("#{File.dirname(__FILE__)}/../lib/sites")
|
7
|
+
$LOAD_PATH.unshift lib_path unless $LOAD_PATH.include?(lib_path)
|
8
|
+
|
9
|
+
Spec::Runner.configure do |config|
|
10
|
+
config.mock_with :mocha
|
11
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class Array
|
2
|
+
# Returns true if the two arrays elements are equal ignoring order
|
3
|
+
# Example:
|
4
|
+
# [1,2].equivalent([2,1]) # => true
|
5
|
+
# [1,2,3].equivalent([2,1]) # => false
|
6
|
+
def equivalent?(other_array)
|
7
|
+
merged_array = self & other_array
|
8
|
+
merged_array.size == self.size && merged_array.size == other_array.size
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class Hash
|
2
|
+
def convert_hash_keys_to_methods(fixture) # :nodoc:
|
3
|
+
Taza::Entity.new(self,fixture)
|
4
|
+
end
|
5
|
+
|
6
|
+
# Recursively replace key names that should be symbols with symbols.
|
7
|
+
def key_strings_to_symbols!
|
8
|
+
result = Hash.new
|
9
|
+
self.each_pair do |key,value|
|
10
|
+
value.key_strings_to_symbols! if value.kind_of? Hash and value.respond_to? :key_strings_to_symbols!
|
11
|
+
result[key.to_sym] = value
|
12
|
+
end
|
13
|
+
self.replace(result)
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# instance_exec comes with >1.8.7 thankfully
|
2
|
+
if VERSION <= '1.8.6'
|
3
|
+
class Object
|
4
|
+
def metaclass
|
5
|
+
class << self; self; end
|
6
|
+
end
|
7
|
+
|
8
|
+
module InstanceExecHelper; end
|
9
|
+
include InstanceExecHelper
|
10
|
+
# instance_exec method evaluates a block of code relative to the specified object, with parameters whom come from outside the object.
|
11
|
+
def instance_exec(*args, &block)
|
12
|
+
begin
|
13
|
+
old_critical, Thread.critical = Thread.critical, true
|
14
|
+
n = 0
|
15
|
+
n += 1 while respond_to?(mname="__instance_exec#{n}")
|
16
|
+
InstanceExecHelper.module_eval{ define_method(mname, &block) }
|
17
|
+
ensure
|
18
|
+
Thread.critical = old_critical
|
19
|
+
end
|
20
|
+
begin
|
21
|
+
ret = send(mname, *args)
|
22
|
+
ensure
|
23
|
+
InstanceExecHelper.module_eval{ remove_method(mname) } rescue nil
|
24
|
+
end
|
25
|
+
ret
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
class Object
|
30
|
+
def metaclass
|
31
|
+
class << self; self; end
|
32
|
+
end
|
33
|
+
end
|
data/lib/taza.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'taza/page'
|
2
|
+
require 'taza/site'
|
3
|
+
require 'taza/browser'
|
4
|
+
require 'taza/settings'
|
5
|
+
require 'taza/flow'
|
6
|
+
require 'taza/entity'
|
7
|
+
require 'taza/fixtures'
|
8
|
+
require 'extensions/object'
|
9
|
+
require 'extensions/string'
|
10
|
+
require 'extensions/hash'
|
11
|
+
require 'extensions/array'
|
12
|
+
|
13
|
+
module ForwardInitialization
|
14
|
+
module ClassMethods
|
15
|
+
def new(*args,&block)
|
16
|
+
const_get("#{name.split("::").last}").new(*args,&block)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.included(klass)
|
21
|
+
klass.extend(ClassMethods)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
data/lib/taza/browser.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
module Taza
|
2
|
+
class Browser
|
3
|
+
|
4
|
+
# Create a browser instance depending on configuration. Configuration should be read in via Taza::Settings.config.
|
5
|
+
#
|
6
|
+
# Example:
|
7
|
+
# browser = Taza::Browser.create(Taza::Settings.config)
|
8
|
+
#
|
9
|
+
def self.create(params={})
|
10
|
+
self.send("create_#{params[:driver]}".to_sym,params)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.browser_class(params)
|
14
|
+
self.send("#{params[:driver]}_#{params[:browser]}".to_sym)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def self.create_watir(params)
|
20
|
+
method = "watir_#{params[:browser]}"
|
21
|
+
raise BrowserUnsupportedError unless self.respond_to?(method)
|
22
|
+
watir = self.send(method,params)
|
23
|
+
watir
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.create_selenium(params)
|
27
|
+
require 'selenium'
|
28
|
+
Selenium::SeleniumDriver.new(params[:server_ip],params[:server_port],'*' + params[:browser].to_s,params[:timeout])
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.watir_firefox(params)
|
32
|
+
require 'firewatir'
|
33
|
+
FireWatir::Firefox.new
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.watir_safari(params)
|
37
|
+
require 'safariwatir'
|
38
|
+
Watir::Safari.new
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.watir_ie(params)
|
42
|
+
require 'watir'
|
43
|
+
if params[:attach]
|
44
|
+
browser = Watir::IE.find(:title, //)
|
45
|
+
end
|
46
|
+
browser || Watir::IE.new
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# We don't know how to create the browser you asked for
|
51
|
+
class BrowserUnsupportedError < StandardError; end
|
52
|
+
end
|
53
|
+
|
data/lib/taza/entity.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
module Taza
|
2
|
+
|
3
|
+
class Entity
|
4
|
+
#Creates a entity, pass in a hash to be methodized and the fixture to look up other fixtures (not entirely happy with this abstraction)
|
5
|
+
def initialize(hash,fixture)
|
6
|
+
@hash = hash
|
7
|
+
@fixture = fixture
|
8
|
+
define_methods_for_hash_keys
|
9
|
+
end
|
10
|
+
|
11
|
+
#This method converts hash keys into methods onto the entity
|
12
|
+
def define_methods_for_hash_keys
|
13
|
+
@hash.keys.each do |key|
|
14
|
+
create_method(key) do
|
15
|
+
get_value_for_entry(key)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
#This method will lookup another fixture if a pluralized fixture exists otherwise return the value in the hash
|
21
|
+
def get_value_for_entry(key) # :nodoc:
|
22
|
+
if @fixture.nil?
|
23
|
+
create_entity_if_value_is_hash(key)
|
24
|
+
elsif @fixture.fixture_exists?(key)
|
25
|
+
@fixture.specific_fixture_entities(key.to_sym, @hash[key])
|
26
|
+
elsif @fixture.pluralized_fixture_exists?(key)
|
27
|
+
@fixture.get_fixture_entity(key.pluralize.to_sym,@hash[key])
|
28
|
+
else
|
29
|
+
create_entity_if_value_is_hash(key)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
alias :[] :get_value_for_entry
|
33
|
+
|
34
|
+
def create_entity_if_value_is_hash(key)
|
35
|
+
if (@fixture.nil? && @hash[key].is_a?(Hash))
|
36
|
+
Entity.new(@hash[key], nil)
|
37
|
+
elsif (!@fixture.nil? && @hash[key].is_a?(Hash))
|
38
|
+
Entity.new(@hash[key], @fixture)
|
39
|
+
else
|
40
|
+
@hash[key]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def to_hash
|
45
|
+
cloned_hash = @hash.clone
|
46
|
+
cloned_hash.key_strings_to_symbols!
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
def create_method(name, &block) # :nodoc:
|
51
|
+
self.class.send(:define_method, name, &block)
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
data/lib/taza/fixture.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'find'
|
2
|
+
require 'erb'
|
3
|
+
require 'extensions/hash'
|
4
|
+
require 'taza/entity'
|
5
|
+
|
6
|
+
module Taza
|
7
|
+
# The module that will mixin methods based on the fixture files in your 'spec/fixtures'
|
8
|
+
#
|
9
|
+
# Example:
|
10
|
+
# describe "something" do
|
11
|
+
# it "should test something" do
|
12
|
+
# users(:jane_smith).first_name.should eql("jane")
|
13
|
+
# end
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# where there is a spec/fixtures/users.yml file containing a entry of:
|
17
|
+
# jane_smith:
|
18
|
+
# first_name: jane
|
19
|
+
# last_name: smith
|
20
|
+
class Fixture # :nodoc:
|
21
|
+
|
22
|
+
def initialize # :nodoc:
|
23
|
+
@fixtures = {}
|
24
|
+
end
|
25
|
+
|
26
|
+
def load_fixtures_from(dir) # :nodoc:
|
27
|
+
Dir.glob(File.join(dir,'*.yml')) do |file|
|
28
|
+
templatized_fixture=ERB.new(File.read(file))
|
29
|
+
entitized_fixture = {}
|
30
|
+
YAML.load(templatized_fixture.result()).each do |key, value|
|
31
|
+
entitized_fixture[key] = value.convert_hash_keys_to_methods(self)
|
32
|
+
end
|
33
|
+
@fixtures[File.basename(file,'.yml').to_sym] = entitized_fixture
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def fixture_names # :nodoc:
|
38
|
+
@fixtures.keys
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_fixture(fixture_file_key)
|
42
|
+
@fixtures[fixture_file_key]
|
43
|
+
end
|
44
|
+
|
45
|
+
def get_fixture_entity(fixture_file_key,entity_key) # :nodoc:
|
46
|
+
@fixtures[fixture_file_key][entity_key]
|
47
|
+
end
|
48
|
+
|
49
|
+
def pluralized_fixture_exists?(singularized_fixture_name) # :nodoc:
|
50
|
+
fixture_exists?(singularized_fixture_name.pluralize.to_sym)
|
51
|
+
end
|
52
|
+
|
53
|
+
def specific_fixture_entities(fixture_key, select_array)
|
54
|
+
cloned_fixture = @fixtures[fixture_key].clone
|
55
|
+
cloned_fixture.delete_if {|key , value| !select_array.include?(key)}
|
56
|
+
end
|
57
|
+
|
58
|
+
def fixture_exists?(fixture_name)
|
59
|
+
fixture_names.include?(fixture_name.to_sym)
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.base_path # :nodoc:
|
63
|
+
File.join('.','spec','fixtures','')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|