taza 0.5.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +33 -0
- data/Manifest.txt +39 -9
- data/README.txt +29 -7
- data/Rakefile +72 -13
- data/bin/taza +16 -3
- data/generators/flow/flow_generator.rb +57 -0
- data/generators/flow/templates/flow.rb.erb +12 -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/site/site_generator.rb +55 -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 +76 -0
- data/lib/app_generators/taza/templates/config.yml.erb +3 -0
- data/lib/{taza/generators → app_generators/taza}/templates/rakefile.rb.erb +0 -0
- data/lib/app_generators/taza/templates/spec_helper.rb.erb +11 -0
- data/lib/taza.rb +44 -5
- data/lib/taza/browser.rb +40 -0
- data/lib/taza/browsers/ie_watir.rb +8 -0
- data/lib/taza/browsers/safari_watir.rb +8 -0
- data/lib/taza/flow.rb +45 -0
- data/lib/taza/page.rb +66 -19
- data/lib/taza/settings.rb +36 -0
- data/lib/taza/site.rb +122 -11
- data/lib/taza/tasks.rb +26 -34
- data/spec/browser_spec.rb +72 -0
- data/spec/flow_generator_spec.rb +70 -0
- data/spec/page_generator_spec.rb +57 -0
- data/spec/page_spec.rb +82 -0
- data/spec/platform/osx/browser_spec.rb +14 -0
- data/spec/platform/windows/browser_spec.rb +14 -0
- data/spec/project_generator_spec.rb +42 -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/flows/batman.rb +2 -0
- data/spec/sandbox/flows/robin.rb +4 -0
- data/spec/sandbox/pages/foo/bar.rb +9 -0
- data/spec/settings_spec.rb +88 -0
- data/spec/site_generator_spec.rb +53 -0
- data/spec/site_spec.rb +239 -0
- data/spec/spec_helper.rb +49 -0
- data/spec/taza_bin_spec.rb +14 -0
- data/spec/taza_spec.rb +12 -0
- data/spec/taza_tasks_spec.rb +27 -0
- data/spec/unit_helper_spec.rb +14 -0
- metadata +103 -13
- data/lib/taza/generators.rb +0 -4
- data/lib/taza/generators/base.rb +0 -33
- data/lib/taza/generators/page.rb +0 -22
- data/lib/taza/generators/project.rb +0 -18
- data/lib/taza/generators/site.rb +0 -24
- data/lib/taza/generators/templates/page.rb.erb +0 -6
- data/lib/taza/generators/templates/site.rb.erb +0 -6
data/spec/page_spec.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
require 'taza/page'
|
3
|
+
|
4
|
+
describe Taza::Page do
|
5
|
+
|
6
|
+
class ElementAndFilterContextExample < Taza::Page
|
7
|
+
element(:sample_element) {browser}
|
8
|
+
filter:sample_filter, :sample_element
|
9
|
+
def sample_filter
|
10
|
+
browser
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should execute an element's block with the params provided for its method" do
|
15
|
+
Taza::Page.element(:boo){|baz| baz}
|
16
|
+
Taza::Page.new.boo("rofl").should == "rofl"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should execute elements and filters in the context of the page instance" do
|
20
|
+
page = ElementAndFilterContextExample.new
|
21
|
+
page.browser = :something
|
22
|
+
page.sample_element.should eql(:something)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should add a filter to the classes filters" do
|
26
|
+
ElementAndFilterContextExample.filters.size.should eql(1)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should store the block given to the element method in a method with the name of the parameter" do
|
30
|
+
Taza::Page.element(:foo) do
|
31
|
+
"bar"
|
32
|
+
end
|
33
|
+
Taza::Page.new.foo.should == "bar"
|
34
|
+
end
|
35
|
+
|
36
|
+
class FilterAllElements < Taza::Page
|
37
|
+
element(:foo) {}
|
38
|
+
element(:apple) {}
|
39
|
+
filter :false_filter
|
40
|
+
|
41
|
+
def false_filter
|
42
|
+
false
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should filter all elements if element argument is not provided" do
|
47
|
+
lambda { FilterAllElements.new.apple }.should raise_error(Taza::FilterError)
|
48
|
+
lambda { FilterAllElements.new.foo }.should raise_error(Taza::FilterError)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should have empty elements on a new class" do
|
52
|
+
foo = Class::new(superclass=Taza::Page)
|
53
|
+
foo.elements.should_not be_nil
|
54
|
+
foo.elements.should be_empty
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should have empty filters on a new class" do
|
58
|
+
foo = Class::new(superclass=Taza::Page)
|
59
|
+
foo.filters.should_not be_nil
|
60
|
+
foo.filters.should be_empty
|
61
|
+
end
|
62
|
+
|
63
|
+
class FilterAnElement < Taza::Page
|
64
|
+
attr_accessor :called_element_method
|
65
|
+
element(:false_item) { @called_element_method = true}
|
66
|
+
filter :false_filter, :false_item
|
67
|
+
|
68
|
+
def false_filter
|
69
|
+
false
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should raise a error if an elements is called and its filter returns false" do
|
74
|
+
lambda { FilterAnElement.new.false_item }.should raise_error(Taza::FilterError)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should not call element block if filters fail" do
|
78
|
+
page = FilterAnElement.new
|
79
|
+
lambda { page.false_item }.should raise_error
|
80
|
+
page.called_element_method.should_not be_true
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
require 'taza/browser'
|
3
|
+
|
4
|
+
describe "Taza::Browser with Safari Watir" do
|
5
|
+
it "should be able to make a safari watir instance" do
|
6
|
+
browser = nil
|
7
|
+
begin
|
8
|
+
browser = Taza::Browser.create({:browser => :safari, :driver => :watir,:url =>'http://www.google.com'})
|
9
|
+
browser.should be_a_kind_of(Watir::Safari)
|
10
|
+
ensure
|
11
|
+
browser.close if browser.is_a?(Watir::Safari)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
require 'taza/browser'
|
3
|
+
|
4
|
+
describe "Taza::Browser with watir ie" do
|
5
|
+
it "should be able to make watir ie instance" do
|
6
|
+
browser = nil
|
7
|
+
begin
|
8
|
+
browser = Taza::Browser.create({:browser => :ie,:driver =>:watir,:url => 'http://www.google.com'})
|
9
|
+
browser.should be_a_kind_of(Watir::IE)
|
10
|
+
ensure
|
11
|
+
browser.close if browser.respond_to?(:close)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rake'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'taza'
|
6
|
+
require 'vendor/gems/gems/rubigen-1.3.2/test/test_generator_helper'
|
7
|
+
|
8
|
+
describe "Project Generator" do
|
9
|
+
include RubiGen::GeneratorTestHelper
|
10
|
+
|
11
|
+
before :all do
|
12
|
+
@spec_helper = File.join(TMP_ROOT,PROJECT_NAME,'spec','spec_helper.rb')
|
13
|
+
end
|
14
|
+
|
15
|
+
before :each do
|
16
|
+
bare_setup
|
17
|
+
end
|
18
|
+
|
19
|
+
after :each do
|
20
|
+
bare_teardown
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should generate a spec helper that can be required" do
|
24
|
+
run_generator('taza', [APP_ROOT], generator_sources)
|
25
|
+
system("ruby -c #{@spec_helper} > #{null_device}").should be_true
|
26
|
+
end
|
27
|
+
|
28
|
+
it "spec helper should set the TAZA_ENV variable if it is not provided" do
|
29
|
+
ENV['TAZA_ENV'] = nil
|
30
|
+
run_generator('taza', [APP_ROOT], generator_sources)
|
31
|
+
load @spec_helper
|
32
|
+
ENV['TAZA_ENV'].should eql("isolation")
|
33
|
+
end
|
34
|
+
|
35
|
+
it "spec helper should not override the TAZA_ENV variable if was provided" do
|
36
|
+
ENV['TAZA_ENV'] = 'orange pie? is there such a thing?'
|
37
|
+
run_generator('taza', [APP_ROOT], generator_sources)
|
38
|
+
load @spec_helper
|
39
|
+
ENV['TAZA_ENV'].should eql('orange pie? is there such a thing?')
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
:nothing: :something
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'taza'
|
4
|
+
|
5
|
+
describe Taza::Settings do
|
6
|
+
|
7
|
+
before :all do
|
8
|
+
@site_name = 'SiteName'
|
9
|
+
end
|
10
|
+
|
11
|
+
before :each do
|
12
|
+
ENV['TAZA_ENV'] = 'isolation'
|
13
|
+
ENV['browser'] = nil
|
14
|
+
ENV['driver'] = nil
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should use environment variable for browser settings" do
|
18
|
+
Taza::Settings.stubs(:path).returns("spec/sandbox")
|
19
|
+
ENV['browser'] = 'foo'
|
20
|
+
Taza::Settings.config(@site_name)[:browser].should eql(:foo)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should provide default values if no config file or environment settings provided" do
|
24
|
+
Taza::Settings.stubs(:path).returns("spec/sandbox")
|
25
|
+
Taza::Settings.config(@site_name)[:driver].should eql(:selenium)
|
26
|
+
Taza::Settings.config(@site_name)[:browser].should eql(:firefox)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should use environment variable for driver settings" do
|
30
|
+
Taza::Settings.stubs(:path).returns("spec/sandbox")
|
31
|
+
ENV['driver'] = 'bar'
|
32
|
+
Taza::Settings.config(@site_name)[:driver].should eql(:bar)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should be able to load the site yml" do
|
36
|
+
Taza::Settings.stubs(:path).returns("spec/sandbox")
|
37
|
+
Taza::Settings.config("SiteName")[:url].should eql('http://google.com')
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should be able to load a alternate site url" do
|
41
|
+
ENV['TAZA_ENV'] = 'clown_shoes'
|
42
|
+
Taza::Settings.stubs(:path).returns("spec/sandbox")
|
43
|
+
Taza::Settings.config("SiteName")[:url].should eql('http://clownshoes.com')
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should use the config file's variable for browser settings if no environment variable is set" do
|
47
|
+
Taza::Settings.expects(:config_file).returns({:browser => :fu})
|
48
|
+
Taza::Settings.stubs(:path).returns("spec/sandbox")
|
49
|
+
Taza::Settings.config(@site_name)[:browser].should eql(:fu)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should use the ENV variables if specfied instead of config files" do
|
53
|
+
ENV['browser'] = 'opera'
|
54
|
+
Taza::Settings.expects(:config_file).returns({:browser => :fu})
|
55
|
+
Taza::Settings.stubs(:path).returns("spec/sandbox")
|
56
|
+
Taza::Settings.config(@site_name)[:browser].should eql(:opera)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should use the correct config file to set defaults" do
|
60
|
+
Taza::Settings.stubs(:path).returns("spec/sandbox")
|
61
|
+
Taza::Settings.stubs(:config_file_path).returns('spec/sandbox/config.yml')
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should raise error for a config file that doesnot exist" do
|
65
|
+
Taza::Settings.stubs(:path).returns('spec/sandbox/file_not_exists.yml')
|
66
|
+
lambda {Taza::Settings.config}.should raise_error
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should path point at root directory" do
|
70
|
+
Taza::Settings.path.should eql('.')
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should use the config file's variable for driver settings if no environment variable is set" do
|
74
|
+
Taza::Settings.stubs(:path).returns("spec/sandbox")
|
75
|
+
Taza::Settings.stubs(:config_file).returns({:driver => :fun})
|
76
|
+
Taza::Settings.config(@site_name)[:driver].should eql(:fun)
|
77
|
+
end
|
78
|
+
|
79
|
+
class SiteName < Taza::Site
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
it "a site should be able to load its settings" do
|
84
|
+
Taza::Settings.stubs(:path).returns("spec/sandbox")
|
85
|
+
SiteName.settings[:url].should eql('http://google.com')
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'taza'
|
5
|
+
require 'vendor/gems/gems/rubigen-1.3.2/test/test_generator_helper'
|
6
|
+
|
7
|
+
describe "Site Generation" do
|
8
|
+
include RubiGen::GeneratorTestHelper
|
9
|
+
include Helpers::Generator
|
10
|
+
include Helpers::Taza
|
11
|
+
|
12
|
+
before :all do
|
13
|
+
@spec_helper = File.join(TMP_ROOT,PROJECT_NAME,'spec','spec_helper.rb')
|
14
|
+
@site_name = "WikipediaFoo"
|
15
|
+
@site_file = File.join(PROJECT_FOLDER,'lib','sites' , "wikipedia_foo.rb")
|
16
|
+
@site_folder = File.join(PROJECT_FOLDER,'lib','sites' , "wikipedia_foo")
|
17
|
+
end
|
18
|
+
|
19
|
+
before :each do
|
20
|
+
bare_setup
|
21
|
+
run_generator('taza', [APP_ROOT], generator_sources)
|
22
|
+
end
|
23
|
+
|
24
|
+
after :each do
|
25
|
+
bare_teardown
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should generate configuration file for a site" do
|
29
|
+
run_generator('site', [@site_name], generator_sources)
|
30
|
+
File.exists?(File.join(PROJECT_FOLDER,'config','wikipedia_foo.yml')).should be_true
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should generate a site path for pages" do
|
34
|
+
run_generator('site', [@site_name], generator_sources)
|
35
|
+
File.directory?(@site_folder).should be_true
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should generate a folder for a sites functional tests" do
|
39
|
+
run_generator('site', [@site_name], generator_sources)
|
40
|
+
File.directory?(File.join(PROJECT_FOLDER,'spec','functional','wikipedia_foo')).should be_true
|
41
|
+
end
|
42
|
+
|
43
|
+
it "generated site that uses the block given in new" do
|
44
|
+
@site_class = generate_site(@site_name)
|
45
|
+
stub_settings
|
46
|
+
stub_browser
|
47
|
+
foo = nil
|
48
|
+
@site_class.new {|site| foo = site}
|
49
|
+
foo.should_not be_nil
|
50
|
+
foo.should be_a_kind_of(Taza::Site)
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
data/spec/site_spec.rb
ADDED
@@ -0,0 +1,239 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'taza'
|
4
|
+
|
5
|
+
describe Taza::Site do
|
6
|
+
|
7
|
+
before :all do
|
8
|
+
@pages_path = File.join("spec","sandbox","pages","foo","*.rb")
|
9
|
+
Foo = Class.new(Taza::Site)
|
10
|
+
end
|
11
|
+
|
12
|
+
before :each do
|
13
|
+
Foo.any_instance.stubs(:pages_path).returns(@pages_path)
|
14
|
+
ENV['browser'] = nil
|
15
|
+
ENV['driver'] = nil
|
16
|
+
Taza::Settings.stubs(:config_file).returns({})
|
17
|
+
Taza::Settings.stubs(:site_file).returns({})
|
18
|
+
Taza::Site.before_browser_closes {}
|
19
|
+
end
|
20
|
+
|
21
|
+
it "pages_path should contain the site class name" do
|
22
|
+
browser = stub_browser
|
23
|
+
Taza::Browser.stubs(:create).returns(browser)
|
24
|
+
Bax = Class.new(Taza::Site)
|
25
|
+
Bax.new.pages_path.should eql("./lib/sites/bax/pages/*.rb")
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should execute a flow with given parameters" do
|
29
|
+
browser = stub_browser
|
30
|
+
Taza::Browser.stubs(:create).returns(browser)
|
31
|
+
params = {}
|
32
|
+
require 'spec/sandbox/flows/batman'
|
33
|
+
Batman.any_instance.expects(:run).with(params)
|
34
|
+
Barz = Class.new(Taza::Site)
|
35
|
+
Barz.any_instance.stubs(:path).returns('spec/sandbox')
|
36
|
+
Barz.new.flow(:batman,params)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should require a flow once it is called" do
|
40
|
+
browser = stub_browser
|
41
|
+
Taza::Browser.stubs(:create).returns(browser)
|
42
|
+
Class.constants.include?('Robin').should be_false
|
43
|
+
Bayz = Class.new(Taza::Site)
|
44
|
+
Bayz.any_instance.stubs(:path).returns('spec/sandbox')
|
45
|
+
Bayz.new.flow(:robin,{})
|
46
|
+
Robin
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should create a browser using environment variables" do
|
50
|
+
browser = stub_browser
|
51
|
+
browser.stubs(:goto)
|
52
|
+
Taza::Browser.expects(:create_watir_ie).returns browser
|
53
|
+
ENV['browser'] = 'ie'
|
54
|
+
ENV['driver'] = 'watir'
|
55
|
+
f = Foo.new
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should open watir browsers at the configuration URL" do
|
59
|
+
browser = stub_browser
|
60
|
+
browser.expects(:goto).with('a_url')
|
61
|
+
Taza::Browser.stubs(:create).returns(browser)
|
62
|
+
Taza::Settings.stubs(:config).returns(:url => 'a_url')
|
63
|
+
Foo.new
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should yield an instance of a page class" do
|
67
|
+
f = Foo.new(:browser => stub_browser)
|
68
|
+
barzor = nil
|
69
|
+
f.bar do |bar|
|
70
|
+
barzor = bar
|
71
|
+
end
|
72
|
+
barzor.should be_an_instance_of(Bar)
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should accept a browser instance" do
|
76
|
+
browser = stub_browser
|
77
|
+
foo = Foo.new(:browser => browser)
|
78
|
+
foo.browser.should eql(browser)
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should create a browser instance if one is not provided" do
|
83
|
+
browser = stub_browser
|
84
|
+
Taza::Browser.stubs(:create).returns(browser)
|
85
|
+
foo = Foo.new
|
86
|
+
foo.browser.should eql(browser)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should still close browser if an error is raised" do
|
90
|
+
browser = stub_browser
|
91
|
+
browser.expects(:close)
|
92
|
+
Taza::Browser.stubs(:create).returns(browser)
|
93
|
+
lambda { Foo.new { |site| raise StandardError}}.should raise_error
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should not close browser if block not given" do
|
97
|
+
browser = stub
|
98
|
+
browser.stubs(:goto)
|
99
|
+
browser.expects(:close).never
|
100
|
+
Taza::Browser.stubs(:create).returns(browser)
|
101
|
+
Foo.new
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should not close browser if an error is raised on browser goto" do
|
105
|
+
browser = Object.new
|
106
|
+
browser.stubs(:goto).raises(StandardError,"ErrorOnBrowserGoto")
|
107
|
+
browser.expects(:close).never
|
108
|
+
Taza::Browser.stubs(:create).returns(browser)
|
109
|
+
lambda { Foo.new }.should raise_error(StandardError,"ErrorOnBrowserGoto")
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should raise browser close error if no other errors" do
|
113
|
+
browser = stub_browser
|
114
|
+
browser.expects(:close).raises(StandardError,"BrowserCloseError")
|
115
|
+
Taza::Browser.stubs(:create).returns(browser)
|
116
|
+
lambda { Foo.new {}}.should raise_error(StandardError,"BrowserCloseError")
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should raise error inside block if both it and browser.close throws an error" do
|
120
|
+
browser = stub_browser
|
121
|
+
browser.expects(:close).raises(StandardError,"BrowserCloseError")
|
122
|
+
Taza::Browser.stubs(:create).returns(browser)
|
123
|
+
lambda { Foo.new { |site| raise StandardError, "innererror" }}.should raise_error(StandardError,"innererror")
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should close a browser if block given" do
|
127
|
+
browser = stub_browser
|
128
|
+
browser.expects(:close)
|
129
|
+
Taza::Browser.stubs(:create).returns(browser)
|
130
|
+
Foo.new do |site|
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should yield itself upon initialization" do
|
135
|
+
Taza::Browser.stubs(:create).returns(stub_browser)
|
136
|
+
foo = nil
|
137
|
+
f = Foo.new do |site|
|
138
|
+
foo = site
|
139
|
+
end
|
140
|
+
foo.should eql(f)
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should yield after page methods have been setup" do
|
144
|
+
Taza::Browser.stubs(:create).returns(stub_browser)
|
145
|
+
klass = Class::new(Taza::Site)
|
146
|
+
klass.any_instance.stubs(:pages_path).returns(@pages_path)
|
147
|
+
klass.new do |site|
|
148
|
+
site.should respond_to(:bar)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
it "should yield after browser has been setup" do
|
152
|
+
Taza::Browser.stubs(:create).returns(stub_browser)
|
153
|
+
klass = Class::new(Taza::Site)
|
154
|
+
klass.any_instance.stubs(:pages_path).returns(@pages_path)
|
155
|
+
klass.new do |site|
|
156
|
+
site.browser.should_not be_nil
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should pass its browser instance to its pages " do
|
161
|
+
browser = stub_browser
|
162
|
+
Taza::Browser.stubs(:create).returns(browser)
|
163
|
+
foo = Foo.new
|
164
|
+
foo.bar.browser.should eql(browser)
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should have a way to evaluate a block of code before site closes the browser" do
|
168
|
+
browser = stub()
|
169
|
+
browser.stubs(:goto)
|
170
|
+
Taza::Browser.stubs(:create).returns(browser)
|
171
|
+
browser_state = states('browser_open_state').starts_as('on')
|
172
|
+
browser.expects(:close).then(browser_state.is('off'))
|
173
|
+
browser.expects(:doit).when(browser_state.is('on'))
|
174
|
+
Taza::Site.before_browser_closes { |browser| browser.doit }
|
175
|
+
Foo.new {}
|
176
|
+
end
|
177
|
+
|
178
|
+
it "should have a way to evaluate a block of code before site closes the browser if an error occurs" do
|
179
|
+
browser = stub()
|
180
|
+
browser.stubs(:goto)
|
181
|
+
Taza::Browser.stubs(:create).returns(browser)
|
182
|
+
browser_state = states('browser_open_state').starts_as('on')
|
183
|
+
browser.expects(:close).then(browser_state.is('off'))
|
184
|
+
browser.expects(:doit).when(browser_state.is('on'))
|
185
|
+
Taza::Site.before_browser_closes { |browser| browser.doit }
|
186
|
+
lambda { Foo.new { |site| raise StandardError, "innererror" }}.should raise_error(StandardError,"innererror")
|
187
|
+
end
|
188
|
+
|
189
|
+
it "should still close its browser if #before_browser_closes raises an exception" do
|
190
|
+
browser = stub()
|
191
|
+
browser.stubs(:goto)
|
192
|
+
Taza::Browser.stubs(:create).returns(browser)
|
193
|
+
browser.expects(:close)
|
194
|
+
Taza::Site.before_browser_closes { |browser| raise StandardError, 'foo error' }
|
195
|
+
lambda { Foo.new {} }.should raise_error(StandardError,'foo error')
|
196
|
+
end
|
197
|
+
|
198
|
+
it "should not close a browser it did not make" do
|
199
|
+
browser = stub()
|
200
|
+
browser.stubs(:goto)
|
201
|
+
browser.expects(:close).never
|
202
|
+
Foo.new(:browser => browser) {}
|
203
|
+
end
|
204
|
+
|
205
|
+
it "should close a browser it did make" do
|
206
|
+
browser = stub()
|
207
|
+
Taza::Browser.stubs(:create).returns(browser)
|
208
|
+
browser.stubs(:goto)
|
209
|
+
browser.expects(:close)
|
210
|
+
Foo.new() {}
|
211
|
+
end
|
212
|
+
|
213
|
+
|
214
|
+
module Zoro
|
215
|
+
class Zoro < ::Taza::Site
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
it "should pass in the class name to settings config" do
|
220
|
+
browser = stub()
|
221
|
+
browser.stubs(:goto)
|
222
|
+
Taza::Browser.stubs(:create).returns(browser)
|
223
|
+
Taza::Settings.expects(:config).with('Zoro').returns({})
|
224
|
+
Zoro::Zoro.new
|
225
|
+
end
|
226
|
+
|
227
|
+
it "should load settings based on the sites class name" do
|
228
|
+
Taza::Settings.expects(:site_file).with('Zoro').returns({})
|
229
|
+
Zoro::Zoro.settings
|
230
|
+
end
|
231
|
+
|
232
|
+
def stub_browser
|
233
|
+
browser = stub()
|
234
|
+
browser.stubs(:close)
|
235
|
+
browser.stubs(:goto)
|
236
|
+
browser
|
237
|
+
end
|
238
|
+
|
239
|
+
end
|