taza 0.8.0 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +7 -0
- data/Manifest.txt +14 -0
- data/{README.txt → README} +0 -0
- data/README.textile +1 -0
- data/VERSION.yml +4 -0
- data/generators/flow/templates/flow.rb.erb +2 -5
- data/generators/page/templates/functional_page_spec.rb.erb +1 -1
- data/generators/partial/partial_generator.rb +57 -0
- data/generators/partial/templates/partial.rb.erb +7 -0
- data/generators/site/site_generator.rb +1 -0
- data/lib/app_generators/taza/taza_generator.rb +12 -16
- data/lib/app_generators/taza/templates/rakefile.rb.erb +7 -0
- data/lib/extensions/array.rb +10 -0
- data/lib/extensions/hash.rb +5 -0
- data/lib/extensions/object.rb +24 -0
- data/lib/extensions/string.rb +11 -0
- data/lib/taza.rb +7 -24
- data/lib/taza/browser.rb +9 -16
- data/lib/taza/entity.rb +34 -0
- data/lib/taza/fixture.rb +66 -0
- data/lib/taza/flow.rb +10 -15
- data/lib/taza/page.rb +13 -8
- data/lib/taza/settings.rb +17 -6
- data/lib/taza/site.rb +25 -19
- data/lib/taza/tasks.rb +42 -26
- data/spec/array_spec.rb +16 -0
- data/spec/browser_spec.rb +14 -28
- data/spec/entity_spec.rb +9 -0
- data/spec/fixture_spec.rb +34 -0
- data/spec/fixtures_spec.rb +21 -0
- data/spec/flow_generator_spec.rb +0 -20
- data/spec/hash_spec.rb +12 -0
- data/spec/object_spec.rb +29 -0
- data/spec/page_generator_spec.rb +0 -1
- data/spec/page_spec.rb +14 -0
- data/spec/partial_generator_spec.rb +38 -0
- data/spec/project_generator_spec.rb +6 -1
- data/spec/sandbox/fixtures/examples.yml +8 -0
- data/spec/sandbox/fixtures/users.yml +2 -0
- data/spec/sandbox/flows/batman.rb +4 -1
- data/spec/sandbox/pages/foo/partials/partial_the_reckoning.rb +2 -0
- data/spec/settings_spec.rb +5 -5
- data/spec/site_generator_spec.rb +5 -1
- data/spec/site_spec.rb +19 -29
- data/spec/spec_helper.rb +12 -4
- data/spec/string_spec.rb +7 -0
- data/spec/taza_tasks_spec.rb +17 -1
- metadata +59 -45
- data/Rakefile +0 -125
- data/lib/taza/browsers/ie_watir.rb +0 -8
- data/lib/taza/browsers/safari_watir.rb +0 -8
- data/spec/platform/osx/browser_spec.rb +0 -14
- data/spec/platform/windows/browser_spec.rb +0 -14
- data/spec/unit_helper_spec.rb +0 -14
data/lib/taza/flow.rb
CHANGED
@@ -12,15 +12,15 @@ module Taza
|
|
12
12
|
#
|
13
13
|
# From here you can create the logic needed to perform these flows without ever referencing a browser object:
|
14
14
|
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
15
|
+
# module WidgetsOfTheFuture
|
16
|
+
# class WidgetsOfTheFuture < Taza::Site
|
17
|
+
# def create_an_account_flow(params={})
|
18
|
+
# home_page.create_an_account_link.click
|
19
|
+
# create_an_account_page do |cap|
|
20
|
+
# cap.email.set params[:email]
|
21
|
+
# cap.password.set params[:password]
|
22
|
+
# cap.submit.click
|
23
|
+
# end
|
24
24
|
# end
|
25
25
|
# end
|
26
26
|
# end
|
@@ -31,15 +31,10 @@ module Taza
|
|
31
31
|
# describe "Widgets of the Future" do
|
32
32
|
# it "should do widgety things so that we can make more monies" do
|
33
33
|
# WidgetsOfTheFuture.new do |w|
|
34
|
-
# w.
|
34
|
+
# w.create_an_account_flow :email => "i.am@the.widget.store.com", :password => "secret"
|
35
35
|
# end
|
36
36
|
# end
|
37
37
|
# end
|
38
38
|
class Flow
|
39
|
-
attr_reader :site
|
40
|
-
|
41
|
-
def initialize(site_instance)
|
42
|
-
@site = site_instance
|
43
|
-
end
|
44
39
|
end
|
45
40
|
end
|
data/lib/taza/page.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
module Taza
|
2
2
|
# An abstraction of a web page, place the elements you care about accessing in here as well as specify the filters that apply when trying to access the element.
|
3
|
-
#
|
3
|
+
#
|
4
4
|
# Example:
|
5
5
|
# require 'taza'
|
6
6
|
# class HomePage < Taza::Page
|
7
7
|
# element(:foo) {browser.element_by_xpath('some xpath')}
|
8
|
-
# filter :title_given, :foo
|
9
|
-
#
|
8
|
+
# filter :title_given, :foo
|
9
|
+
#
|
10
10
|
# def title_given
|
11
11
|
# browser.title.nil?
|
12
12
|
# end
|
13
13
|
# end
|
14
|
-
#
|
14
|
+
#
|
15
15
|
# homepage.foo will return the element specified in the block if the filter returned true
|
16
16
|
class Page
|
17
17
|
attr_accessor :browser
|
@@ -39,12 +39,12 @@ module Taza
|
|
39
39
|
# Example:
|
40
40
|
# class HomePage < Taza::Page
|
41
41
|
# element(:foo) {browser.element_by_xpath('some xpath')}
|
42
|
-
# filter :title_given, :foo
|
42
|
+
# filter :title_given, :foo
|
43
43
|
# #a filter will apply to all elements if none are specified
|
44
44
|
# filter :some_filter
|
45
45
|
# #a filter will also apply to all elements if the symbol :all is given
|
46
46
|
# filter :another_filter, :all
|
47
|
-
#
|
47
|
+
#
|
48
48
|
# def some_filter
|
49
49
|
# true
|
50
50
|
# end
|
@@ -66,6 +66,7 @@ module Taza
|
|
66
66
|
|
67
67
|
def initialize
|
68
68
|
add_element_methods
|
69
|
+
@active_filters = []
|
69
70
|
end
|
70
71
|
|
71
72
|
def add_element_methods # :nodoc:
|
@@ -83,10 +84,14 @@ module Taza
|
|
83
84
|
end
|
84
85
|
end
|
85
86
|
end
|
86
|
-
|
87
|
+
|
87
88
|
def check_filters(params) # :nodoc:
|
88
89
|
params[:filters].each do |filter_method|
|
89
|
-
|
90
|
+
unless @active_filters.include?(filter_method)
|
91
|
+
@active_filters << filter_method
|
92
|
+
raise FilterError, "#{filter_method} returned false for #{params[:element_name]}" unless send(filter_method)
|
93
|
+
@active_filters.delete(filter_method)
|
94
|
+
end
|
90
95
|
end
|
91
96
|
end
|
92
97
|
end
|
data/lib/taza/settings.rb
CHANGED
@@ -2,18 +2,29 @@ require 'activesupport'
|
|
2
2
|
|
3
3
|
module Taza
|
4
4
|
class Settings
|
5
|
+
# The config settings for a site.yml file. ENV variables will override the settings:
|
6
|
+
# Can override the browser in config via ENV['BROWSER']
|
7
|
+
# Can override the driver in config via ENV['DRIVER']
|
8
|
+
# Can override the timeout in config via ENV['TIMEOUT']
|
9
|
+
# Can override the server_ip in config via ENV['SERVER_IP']
|
10
|
+
# Can override the server_port in config via ENV['SERVER_PORT']
|
11
|
+
#
|
12
|
+
# Example:
|
13
|
+
# Taza::Settings.Config('google')
|
5
14
|
def self.config(site_name)
|
6
15
|
env_settings = {}
|
7
|
-
env_settings[:browser] = ENV['
|
8
|
-
env_settings[:driver] = ENV['
|
9
|
-
env_settings[:timeout] = ENV['
|
10
|
-
env_settings[:server_ip] = ENV['
|
11
|
-
env_settings[:server_port] = ENV['
|
16
|
+
env_settings[:browser] = ENV['BROWSER'].to_sym if ENV['BROWSER']
|
17
|
+
env_settings[:driver] = ENV['DRIVER'].to_sym if ENV['DRIVER']
|
18
|
+
env_settings[:timeout] = ENV['TIMEOUT'] if ENV['TIMEOUT']
|
19
|
+
env_settings[:server_ip] = ENV['SERVER_IP'] if ENV['SERVER_IP']
|
20
|
+
env_settings[:server_port] = ENV['SERVER_PORT'] if ENV['SERVER_PORT']
|
12
21
|
env_settings = {:browser=>:firefox,:driver=>:selenium}.merge(config_file.merge(env_settings))
|
13
22
|
site_file(site_name).merge(env_settings)
|
14
23
|
end
|
15
24
|
|
16
|
-
|
25
|
+
# Loads the config file for the entire project and returns the hash.
|
26
|
+
# Does not override settings from the ENV variables.
|
27
|
+
def self.config_file
|
17
28
|
YAML.load_file(config_file_path)
|
18
29
|
end
|
19
30
|
|
data/lib/taza/site.rb
CHANGED
@@ -45,10 +45,11 @@ module Taza
|
|
45
45
|
# Sites can take a couple of parameters in the constructor:
|
46
46
|
# :browser => a browser object to act on instead of creating one automatically
|
47
47
|
# :url => the url of where to start the site
|
48
|
-
def initialize(params={})
|
48
|
+
def initialize(params={},&block)
|
49
49
|
@module_name = self.class.parent.to_s
|
50
50
|
@class_name = self.class.to_s.split("::").last
|
51
51
|
define_site_pages
|
52
|
+
define_flows
|
52
53
|
config = Settings.config(@class_name)
|
53
54
|
if params[:browser]
|
54
55
|
@browser = params[:browser]
|
@@ -57,18 +58,20 @@ module Taza
|
|
57
58
|
@i_created_browser = true
|
58
59
|
end
|
59
60
|
@browser.goto(params[:url] || config[:url])
|
61
|
+
execute_block_and_close_browser(browser,&block) if block_given?
|
62
|
+
end
|
60
63
|
|
61
|
-
|
64
|
+
def execute_block_and_close_browser(browser)
|
65
|
+
begin
|
66
|
+
yield self
|
67
|
+
rescue => site_block_exception
|
68
|
+
ensure
|
62
69
|
begin
|
63
|
-
|
64
|
-
rescue =>
|
65
|
-
|
66
|
-
begin
|
67
|
-
@@before_browser_closes.call(browser)
|
68
|
-
rescue => before_browser_closes_block_exception
|
69
|
-
end
|
70
|
-
close_browser_and_raise_if site_block_exception || before_browser_closes_block_exception
|
70
|
+
@@before_browser_closes.call(browser)
|
71
|
+
rescue => before_browser_closes_block_exception
|
72
|
+
"" # so basically rcov has a bug where it would insist this block is uncovered when empty
|
71
73
|
end
|
74
|
+
close_browser_and_raise_if site_block_exception || before_browser_closes_block_exception
|
72
75
|
end
|
73
76
|
end
|
74
77
|
|
@@ -78,9 +81,7 @@ module Taza
|
|
78
81
|
|
79
82
|
def close_browser_and_raise_if original_error # :nodoc:
|
80
83
|
begin
|
81
|
-
if @i_created_browser
|
82
|
-
@browser.close
|
83
|
-
end
|
84
|
+
@browser.close if @i_created_browser
|
84
85
|
ensure
|
85
86
|
raise original_error if original_error
|
86
87
|
end
|
@@ -102,6 +103,12 @@ module Taza
|
|
102
103
|
end
|
103
104
|
end
|
104
105
|
|
106
|
+
def define_flows # :nodoc:
|
107
|
+
Dir.glob(flows_path) do |file|
|
108
|
+
require file
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
105
112
|
# This is used to call a flow belonging to the site
|
106
113
|
#
|
107
114
|
# Example:
|
@@ -118,14 +125,13 @@ module Taza
|
|
118
125
|
# google.submit.click
|
119
126
|
# end
|
120
127
|
# end
|
121
|
-
def flow(name,params={})
|
122
|
-
require File.join(path,'flows',name.to_s.underscore)
|
123
|
-
flow_class = "#{@module_name}::#{name.to_s.camelize}".constantize
|
124
|
-
flow_class.new(self).run(params)
|
125
|
-
end
|
126
128
|
|
127
129
|
def pages_path # :nodoc:
|
128
|
-
File.join(path,'pages','*.rb')
|
130
|
+
File.join(path,'pages','**','*.rb')
|
131
|
+
end
|
132
|
+
|
133
|
+
def flows_path # :nodoc:
|
134
|
+
File.join(path,'flows','*.rb')
|
129
135
|
end
|
130
136
|
|
131
137
|
def path # :nodoc:
|
data/lib/taza/tasks.rb
CHANGED
@@ -1,38 +1,54 @@
|
|
1
|
-
require 'rake'
|
2
|
-
require 'rake/testtask'
|
3
1
|
require 'rubygems'
|
2
|
+
require 'rake'
|
4
3
|
require 'taglob/rake/tasks'
|
5
4
|
require 'spec/rake/spectask'
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
dir_name = File.dirname(file_name)
|
11
|
-
FileUtils.mkdir_p(dir_name) unless File.directory?(dir_name)
|
12
|
-
["--format","html:#{file_name}","--format","p"]
|
13
|
-
end
|
6
|
+
def tags
|
7
|
+
ENV['TAGS']
|
8
|
+
end
|
14
9
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
20
|
-
desc "Run all integration specs"
|
21
|
-
Spec::Rake::SpecTask.new :integration do |t|
|
22
|
-
t.spec_files = 'spec/integration/**/*_spec.rb'
|
23
|
-
t.spec_opts << format_options("integration/all")
|
24
|
-
end
|
10
|
+
module Taza
|
11
|
+
module Rake
|
12
|
+
class Tasks
|
13
|
+
attr_accessor :spec_opts
|
25
14
|
|
26
|
-
|
27
|
-
|
28
|
-
|
15
|
+
def initialize
|
16
|
+
yield self if block_given?
|
17
|
+
define
|
18
|
+
end
|
29
19
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
20
|
+
def define_spec_task(name,glob_path)
|
21
|
+
Spec::Rake::SpecTask.new name do |t|
|
22
|
+
t.spec_files = Dir.taglob(glob_path,tags)
|
23
|
+
t.spec_opts << spec_opts
|
24
|
+
end
|
34
25
|
end
|
35
26
|
|
27
|
+
def define
|
28
|
+
namespace :spec do
|
29
|
+
desc "Run all functional specs"
|
30
|
+
define_spec_task(:functional,'spec/functional/**/*_spec.rb')
|
31
|
+
desc "Run all integration specs"
|
32
|
+
define_spec_task(:integration,'spec/integration/**/*_spec.rb')
|
33
|
+
|
34
|
+
namespace :functional do
|
35
|
+
Dir.glob('./spec/functional/*/').each do |dir|
|
36
|
+
site_name = File.basename(dir)
|
37
|
+
desc "Run all functional specs for #{site_name}"
|
38
|
+
define_spec_task(site_name,"#{dir}**/*_spec.rb")
|
39
|
+
|
40
|
+
namespace site_name do
|
41
|
+
Dir.glob("./spec/functional/#{site_name}/*_spec.rb").each do |page_spec_file|
|
42
|
+
page_name = File.basename(page_spec_file,'_spec.rb')
|
43
|
+
define_spec_task(page_name,page_spec_file)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
36
52
|
end
|
37
53
|
end
|
38
54
|
end
|
data/spec/array_spec.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe 'Array Extensions' do
|
4
|
+
it "should know if elements are not equivilent to a subset of those elements" do
|
5
|
+
[1,2,3].should_not be_equivalent([2,3])
|
6
|
+
end
|
7
|
+
it "should know if elements are not equivilent to a larger set including those elements" do
|
8
|
+
[1,2,3].should_not be_equivalent([1,2,3,4])
|
9
|
+
end
|
10
|
+
it "should know it is equivalent if the same order" do
|
11
|
+
[1,2,3].should be_equivalent([1,2,3])
|
12
|
+
end
|
13
|
+
it "should know it is equivalent if the different orders" do
|
14
|
+
[1,2,3].should be_equivalent([2,1,3])
|
15
|
+
end
|
16
|
+
end
|
data/spec/browser_spec.rb
CHANGED
@@ -2,37 +2,22 @@ require 'spec/spec_helper'
|
|
2
2
|
require 'taza/browser'
|
3
3
|
require 'taza/settings'
|
4
4
|
require 'selenium'
|
5
|
-
require '
|
5
|
+
require 'watir'
|
6
6
|
|
7
7
|
describe Taza::Browser do
|
8
8
|
|
9
9
|
before :each do
|
10
10
|
Taza::Settings.stubs(:config_file).returns({})
|
11
11
|
ENV['TAZA_ENV'] = 'isolation'
|
12
|
-
ENV['
|
13
|
-
ENV['
|
14
|
-
ENV['
|
15
|
-
ENV['
|
16
|
-
ENV['
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should be able to create a watir driver" do
|
20
|
-
Taza::Browser.expects(:create_watir_ie)
|
21
|
-
Taza::Browser.create(:browser => :ie, :driver => :watir)
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should be able to create a firewatir driver" do
|
25
|
-
Taza::Browser.expects(:create_watir_firefox)
|
26
|
-
Taza::Browser.create(:browser => :firefox,:driver => :watir)
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should be able to create a safariwatir driver" do
|
30
|
-
Taza::Browser.expects(:create_watir_safari)
|
31
|
-
Taza::Browser.create(:browser => :safari,:driver => :watir)
|
12
|
+
ENV['SERVER_PORT'] = nil
|
13
|
+
ENV['SERVER_IP'] = nil
|
14
|
+
ENV['BROWSER'] = nil
|
15
|
+
ENV['DRIVER'] = nil
|
16
|
+
ENV['TIMEOUT'] = nil
|
32
17
|
end
|
33
18
|
|
34
19
|
it "should raise unknown browser error for unsupported watir browsers" do
|
35
|
-
lambda { Taza::Browser.create(:browser => :foo_browser_9000,:driver => :watir) }.should raise_error(
|
20
|
+
lambda { Taza::Browser.create(:browser => :foo_browser_9000,:driver => :watir) }.should raise_error(StandardError)
|
36
21
|
end
|
37
22
|
|
38
23
|
it "should use params browser type when creating selenium" do
|
@@ -52,21 +37,22 @@ describe Taza::Browser do
|
|
52
37
|
|
53
38
|
it "should use environment settings for server port and ip" do
|
54
39
|
Taza::Settings.stubs(:path).returns(File.join('spec','sandbox'))
|
55
|
-
ENV['
|
56
|
-
ENV['
|
40
|
+
ENV['SERVER_PORT'] = 'server_port'
|
41
|
+
ENV['SERVER_IP'] = 'server_ip'
|
57
42
|
Selenium::SeleniumDriver.expects(:new).with('server_ip','server_port',anything,anything)
|
58
43
|
Taza::Browser.create(Taza::Settings.config("SiteName"))
|
59
44
|
end
|
60
45
|
|
61
46
|
it "should use environment settings for timeout" do
|
62
47
|
Taza::Settings.stubs(:path).returns(File.join('spec','sandbox'))
|
63
|
-
ENV['
|
48
|
+
ENV['TIMEOUT'] = 'timeout'
|
64
49
|
Selenium::SeleniumDriver.expects(:new).with(anything,anything,anything,'timeout')
|
65
50
|
Taza::Browser.create(Taza::Settings.config("SiteName"))
|
66
51
|
end
|
67
52
|
|
68
|
-
it "should
|
69
|
-
|
70
|
-
Taza::Browser.
|
53
|
+
it "should be able to give you the class of browser" do
|
54
|
+
Taza::Browser.expects(:watir_safari).returns(Object)
|
55
|
+
Taza::Browser.browser_class(:browser => :safari, :driver => :watir).should eql(Object)
|
71
56
|
end
|
57
|
+
|
72
58
|
end
|
data/spec/entity_spec.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
require 'taza'
|
3
|
+
|
4
|
+
describe Taza::Fixture do
|
5
|
+
|
6
|
+
it "should be able to load entries from fixtures" do
|
7
|
+
Taza::Fixture.any_instance.stubs(:base_path).returns('./spec/sandbox')
|
8
|
+
fixture = Taza::Fixture.new
|
9
|
+
fixture.load_all
|
10
|
+
example = fixture.get_fixture_entity(:examples,'first_example')
|
11
|
+
example.name.should eql("first")
|
12
|
+
example.price.should eql(1)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should use the spec folder as the base path" do
|
16
|
+
Taza::Fixture.new.base_path.should eql('./spec')
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should know if a pluralized fixture of that name exists" do
|
20
|
+
Taza::Fixture.any_instance.stubs(:base_path).returns('./spec/sandbox')
|
21
|
+
fixture = Taza::Fixture.new
|
22
|
+
fixture.load_all
|
23
|
+
fixture.pluralized_fixture_exists?('example').should be_true
|
24
|
+
fixture.pluralized_fixture_exists?('foo').should be_false
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should be able to get all fixtures loaded" do
|
28
|
+
Taza::Fixture.any_instance.stubs(:base_path).returns('./spec/sandbox')
|
29
|
+
fixture = Taza::Fixture.new
|
30
|
+
fixture.load_all
|
31
|
+
fixture.fixture_names.should be_equivalent([:examples,:users])
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
require 'taza/fixture'
|
3
|
+
|
4
|
+
describe Taza::Fixtures do
|
5
|
+
Taza::Fixture.any_instance.stubs(:base_path).returns('./spec/sandbox')
|
6
|
+
include Taza::Fixtures
|
7
|
+
|
8
|
+
it "should be able to look up a fixture entity off fixture_methods module" do
|
9
|
+
examples(:first_example).name.should eql('first')
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should still raise method missing error" do
|
13
|
+
lambda{zomgwtf(:first_example)}.should raise_error(NoMethodError)
|
14
|
+
end
|
15
|
+
|
16
|
+
#TODO: this test tests what is in entity's instance eval not happy with it being here
|
17
|
+
it "should be able to look up a fixture entity off fixture_methods module" do
|
18
|
+
examples(:first_example).user.name.should eql(users(:shatner).name)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|