pagemodels 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,11 @@
1
1
  module PageModels
2
2
  class Base
3
3
  def open!
4
- visit(url)
4
+ if config.driver.class.to_s == "Capybara::Session"
5
+ visit(full_url)
6
+ else
7
+ goto(full_url)
8
+ end
5
9
  verify!
6
10
  end
7
11
 
@@ -24,5 +28,9 @@ module PageModels
24
28
  def config
25
29
  PageModels::Configuration.instance
26
30
  end
31
+
32
+ def full_url
33
+ url =~ /^https?:\/\// ? url : config.base_url + url
34
+ end
27
35
  end
28
36
  end
@@ -4,10 +4,17 @@ module PageModels
4
4
  class Configuration
5
5
  include Singleton
6
6
  attr_writer :driver
7
+ attr_accessor :base_url
7
8
 
8
9
  def initialize
10
+ reset!
11
+ end
12
+
13
+ def reset!
9
14
  @driver = :capybara
15
+ @base_url = "http://localhost:3000"
10
16
  @frameworks = []
17
+ @driver_instance = nil
11
18
  end
12
19
 
13
20
  def integrate(framework)
@@ -19,11 +26,15 @@ module PageModels
19
26
  end
20
27
 
21
28
  def driver
22
- case @driver
23
- when :capybara
24
- Capybara.current_session
25
- else
26
- raise ConfigurationError.new("No driver configured.")
29
+ @driver_instance ||= begin
30
+ case @driver
31
+ when :capybara
32
+ Capybara.current_session
33
+ when :celerity
34
+ Celerity::Browser.new
35
+ else
36
+ Watir::Browser.new(@driver)
37
+ end
27
38
  end
28
39
  end
29
40
  end
@@ -1,13 +1,18 @@
1
- Given /^I open the (.+ page)(.*)$/ do |page, args|
1
+ Given /^I (?:open|visit|go to) the (.+\s?page)(.*)$/ do |page, args|
2
2
  self.page_model = PageModels.create(page, args)
3
3
  page_model.open!
4
4
  end
5
5
 
6
- Then /^I should see the (.+ page)(.*)$/ do |page, args|
6
+ Then /^I should (?:see|be on) the (.+\s?page)(.*)$/ do |page, args|
7
7
  self.page_model = PageModels.create(page, args)
8
8
  page_model.verify!
9
9
  end
10
10
 
11
+ at_exit do
12
+ driver = PageModels::Configuration.instance.driver
13
+ driver.close if driver.class.to_s == "Watir::Browser"
14
+ end
15
+
11
16
  module PageModels
12
17
  module CucumberIntegration
13
18
  attr_accessor :page_model
@@ -1,3 +1,3 @@
1
1
  module PageModels
2
- VERSION = "0.1.1"
3
- end
2
+ VERSION = "0.1.2"
3
+ end
@@ -5,8 +5,12 @@ describe PageModels::Base do
5
5
  end
6
6
 
7
7
  class TestPageModel < PageModels::Base
8
+ def initialize(url="http://test-page")
9
+ @url = url
10
+ end
11
+
8
12
  def url
9
- "/test-page"
13
+ @url
10
14
  end
11
15
 
12
16
  def verify!
@@ -41,18 +45,65 @@ describe PageModels::Base do
41
45
  end
42
46
  end
43
47
 
44
- describe "opening a page" do
48
+ describe "constructing page URLs" do
49
+ before(:each) do
50
+ PageModels::Configuration.instance.stub(:driver).and_return(Capybara::Session.new)
51
+ PageModels::Configuration.instance.base_url = "https://1.2.3.4:4321"
52
+ @page_model = TestPageModel.new
53
+ end
54
+
55
+ it "uses the base URL from config" do
56
+ pm = TestPageModel.new("/foo")
57
+ pm.should_receive(:visit).with("https://1.2.3.4:4321/foo")
58
+ pm.should_receive(:verify!)
59
+ pm.open!
60
+ end
61
+
62
+ it "ignores base URL if http:// is specified" do
63
+ pm = TestPageModel.new("http://foo")
64
+ pm.should_receive(:visit).with("http://foo")
65
+ pm.should_receive(:verify!)
66
+ pm.open!
67
+ end
68
+
69
+ it "ignores base URL if https:// is specified" do
70
+ pm = TestPageModel.new("https://foo")
71
+ pm.should_receive(:visit).with("https://foo")
72
+ pm.should_receive(:verify!)
73
+ pm.open!
74
+ end
75
+ end
76
+
77
+ describe "opening a page with driver" do
45
78
  before(:each) do
46
- @driver = Object.new
47
- PageModels::Configuration.instance.stub(:driver).and_return(@driver)
48
79
  @page_model = TestPageModel.new
49
80
  end
50
81
 
51
- it "should visit the page, then call verify" do
52
- @page_model.should_receive(:visit).with("/test-page")
53
- @page_model.should_receive(:verify!)
54
- @page_model.open!
82
+ describe "for capybara" do
83
+ it "should visit the page, then call verify" do
84
+ PageModels::Configuration.instance.stub(:driver).and_return(Capybara::Session.new)
85
+ @page_model.should_receive(:visit).with("http://test-page")
86
+ @page_model.should_receive(:verify!)
87
+ @page_model.open!
88
+ end
55
89
  end
56
90
 
91
+ describe "for celerity" do
92
+ it "should goto the page, then call verify" do
93
+ PageModels::Configuration.instance.stub(:driver).and_return(Celerity::Browser.new)
94
+ @page_model.should_receive(:goto).with("http://test-page")
95
+ @page_model.should_receive(:verify!)
96
+ @page_model.open!
97
+ end
98
+ end
99
+
100
+ describe "for watir-webdriver" do
101
+ it "should goto the page, then call verify" do
102
+ PageModels::Configuration.instance.stub(:driver).and_return(Watir::Browser.new(:chrome))
103
+ @page_model.should_receive(:goto).with("http://test-page")
104
+ @page_model.should_receive(:verify!)
105
+ @page_model.open!
106
+ end
107
+ end
57
108
  end
58
109
  end
@@ -1,26 +1,52 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "../../spec_helper")
2
2
 
3
- module Capybara
4
- def self.current_session
5
- @session ||= Object.new
6
- end
7
- end
8
-
9
3
  describe PageModels::Configuration do
10
4
  before(:each) do
11
5
  @config = PageModels::Configuration.instance
6
+ @config.reset!
12
7
  end
13
8
 
14
- describe "providing a driver" do
15
- it "should raise an error if no driver is configured" do
16
- @config.driver = nil
17
- lambda { @config.driver }.should raise_error(PageModels::ConfigurationError)
18
- end
19
-
9
+ describe "providing a driver" do
20
10
  it "should provide a Capybara session" do
21
11
  @config.driver = :capybara
22
12
  @config.driver.should == Capybara.current_session
23
13
  end
14
+
15
+ it "should provide a Celerity browser" do
16
+ @config.driver = :celerity
17
+ @config.driver.should be_a Celerity::Browser
18
+ end
19
+
20
+ describe "for watir-webdriver" do
21
+ it "should support Chrome" do
22
+ @config.driver = :chrome
23
+ @config.driver.should be_a Watir::Browser
24
+ @config.driver.browser.should == :chrome
25
+ end
26
+
27
+ it "should support Chrome" do
28
+ @config.driver = :firefox
29
+ @config.driver.should be_a Watir::Browser
30
+ @config.driver.browser.should == :firefox
31
+ end
32
+
33
+ it "should support IE" do
34
+ @config.driver = :ie
35
+ @config.driver.should be_a Watir::Browser
36
+ @config.driver.browser.should == :ie
37
+ end
38
+ end
39
+
40
+ it "should return the same instance every time" do
41
+ @config.base_url.should == "http://localhost:3000"
42
+ @config.driver = :celerity
43
+ @config.driver.should === @config.driver
44
+ end
45
+ end
46
+
47
+ it "provides a base URL" do
48
+ @config.base_url = "https://1.2.3.4:4321"
49
+ @config.base_url.should == "https://1.2.3.4:4321"
24
50
  end
25
51
 
26
52
  describe "integrating with frameworks" do
data/spec/spec_helper.rb CHANGED
@@ -1 +1,24 @@
1
- require File.join(File.dirname(__FILE__), "..", "lib", "pagemodels")
1
+ require File.join(File.dirname(__FILE__), "..", "lib", "pagemodels")
2
+
3
+ module Capybara
4
+ class Session
5
+ end
6
+
7
+ def self.current_session
8
+ @session ||= Session.new
9
+ end
10
+ end
11
+
12
+ module Watir
13
+ class Browser
14
+ attr_reader :browser
15
+ def initialize(browser)
16
+ @browser = browser
17
+ end
18
+ end
19
+ end
20
+
21
+ module Celerity
22
+ class Browser
23
+ end
24
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: pagemodels
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.1
5
+ version: 0.1.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Rick Grundy
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-06-18 00:00:00 +01:00
13
+ date: 2012-02-14 00:00:00 +08:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency