site_prism 2.2 → 2.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -15,7 +15,7 @@ Here's an overview of how SitePrism is designed to be used:
15
15
  # define our site's pages
16
16
 
17
17
  class Home < SitePrism::Page
18
- set_url "http://www.google.com"
18
+ set_url "/index.htm"
19
19
  set_url_matcher /google.com\/?/
20
20
 
21
21
  element :search_field, "input[name='q']"
@@ -159,10 +159,39 @@ class Home < SitePrism::Page
159
159
  end
160
160
  ```
161
161
 
162
+ If you've set Capybara's `app_host` then you can set the URL as follows:
163
+
164
+ ```ruby
165
+ class Home < SitePrism::Page
166
+ set_url "/home.htm"
167
+ end
168
+ ```
169
+
162
170
  Note that setting a URL is optional - you only need to set a url if you want to be able to navigate
163
171
  directly to that page. It makes sense to set the URL for a page model of a home
164
172
  page or a login page, but probably not a search results page.
165
173
 
174
+ #### Parameterized URLs
175
+
176
+ SitePrism uses the Addressable gem and therefore allows for parameterized URLs. Here is
177
+ a simple example:
178
+
179
+ ```ruby
180
+ class UserProfile < SitePris::Page
181
+ set_url "/users{/username}"
182
+ end
183
+ ```
184
+
185
+ ...and a more complex example:
186
+
187
+ ```ruby
188
+ class Search < SitePris::Page
189
+ set_url "/search{?query*}"
190
+ end
191
+ ```
192
+
193
+ See https://github.com/sporkmonger/addressable for more details on parameterized URLs.
194
+
166
195
  ### Navigating to the Page
167
196
 
168
197
  Once the URL has been set (using `set_url`), you can navigate directly
@@ -173,9 +202,37 @@ to the page using `#load`:
173
202
  @home_page.load
174
203
  ```
175
204
 
205
+ #### Navigating to a page with a parameterized URL
206
+
207
+ The `#load` method takes parameters and will apply them to the URL. Using the examples above:
208
+
209
+ ```ruby
210
+ class UserProfile < SitePris::Page
211
+ set_url "/users{/username}"
212
+ end
213
+
214
+ @user_profile = UserProfile.new
215
+ @user_profile.load #=> /users
216
+ @user_profile.load(username: 'bob') #=> loads /users/bob
217
+ ```
218
+
219
+ ...and...
220
+
221
+ ```ruby
222
+ class Search < SitePris::Page
223
+ set_url "/search{?query*}"
224
+ end
225
+
226
+ @search = Search.new
227
+ @search.load(query: 'simple') #=> loads /search?query=simple
228
+ @search.load(query: {'color'=> 'red', 'text'=> 'blue'}) #=> loads /search?color=red&text=blue
229
+ ```
230
+
176
231
  This will tell whichever capybara driver you have configured to
177
232
  navigate to the URL set against that page's class.
178
233
 
234
+ See https://github.com/sporkmonger/addressable for more details on parameterized URLs.
235
+
179
236
  ### Verifying that a particular page is displayed
180
237
 
181
238
  Automated tests often need to verify that a particular page is
data/lib/site_prism.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'addressable/template'
1
2
  require 'site_prism/version'
2
3
  require 'site_prism/exceptions'
3
4
  require 'site_prism/element_container'
@@ -1,6 +1,6 @@
1
1
  module SitePrism::ElementContainer
2
2
 
3
- def element element_name, *find_args
3
+ def element(element_name, *find_args)
4
4
  build element_name, *find_args do
5
5
  define_method element_name.to_s do
6
6
  find_first *find_args
@@ -8,7 +8,7 @@ module SitePrism::ElementContainer
8
8
  end
9
9
  end
10
10
 
11
- def elements collection_name, *find_args
11
+ def elements(collection_name, *find_args)
12
12
  build collection_name, *find_args do
13
13
  define_method collection_name.to_s do
14
14
  find_all *find_args
@@ -17,7 +17,7 @@ module SitePrism::ElementContainer
17
17
  end
18
18
  alias :collection :elements
19
19
 
20
- def section section_name, section_class, *find_args
20
+ def section(section_name, section_class, *find_args)
21
21
  build section_name, *find_args do
22
22
  define_method section_name do
23
23
  section_class.new self, find_first(*find_args)
@@ -25,7 +25,7 @@ module SitePrism::ElementContainer
25
25
  end
26
26
  end
27
27
 
28
- def sections section_collection_name, section_class, *find_args
28
+ def sections(section_collection_name, section_class, *find_args)
29
29
  build section_collection_name, *find_args do
30
30
  define_method section_collection_name do
31
31
  find_all(*find_args).collect do |element|
@@ -35,7 +35,7 @@ module SitePrism::ElementContainer
35
35
  end
36
36
  end
37
37
 
38
- def iframe iframe_name, iframe_page_class, iframe_id
38
+ def iframe(iframe_name, iframe_page_class, iframe_id)
39
39
  add_to_mapped_items iframe_name
40
40
  create_existence_checker iframe_name, iframe_id
41
41
  create_waiter iframe_name, iframe_id
@@ -46,7 +46,7 @@ module SitePrism::ElementContainer
46
46
  end
47
47
  end
48
48
 
49
- def add_to_mapped_items item
49
+ def add_to_mapped_items(item)
50
50
  @mapped_items ||= []
51
51
  @mapped_items << item.to_s
52
52
  end
@@ -57,34 +57,34 @@ module SitePrism::ElementContainer
57
57
 
58
58
  private
59
59
 
60
- def build name, *find_args
60
+ def build(name, *find_args)
61
61
  if find_args.empty?
62
62
  create_no_selector name
63
63
  else
64
64
  add_to_mapped_items name
65
65
  yield
66
66
  end
67
- add_checkers_and_waiters name, *find_args
67
+ add_helper_methods name, *find_args
68
68
  end
69
69
 
70
- def add_checkers_and_waiters name, *find_args
70
+ def add_helper_methods(name, *find_args)
71
71
  create_existence_checker name, *find_args
72
72
  create_waiter name, *find_args
73
73
  create_visibility_waiter name, *find_args
74
74
  create_invisibility_waiter name, *find_args
75
75
  end
76
76
 
77
- def build_checker_or_waiter element_name, proposed_method_name, *find_args
77
+ def create_helper_method(proposed_method_name, *find_args)
78
78
  if find_args.empty?
79
- create_no_selector element_name, proposed_method_name
79
+ create_no_selector proposed_method_name
80
80
  else
81
81
  yield
82
82
  end
83
83
  end
84
84
 
85
- def create_existence_checker element_name, *find_args
85
+ def create_existence_checker(element_name, *find_args)
86
86
  method_name = "has_#{element_name.to_s}?"
87
- build_checker_or_waiter element_name, method_name, *find_args do
87
+ create_helper_method method_name, *find_args do
88
88
  define_method method_name do
89
89
  Capybara.using_wait_time 0 do
90
90
  element_exists? *find_args
@@ -93,9 +93,9 @@ module SitePrism::ElementContainer
93
93
  end
94
94
  end
95
95
 
96
- def create_waiter element_name, *find_args
96
+ def create_waiter(element_name, *find_args)
97
97
  method_name = "wait_for_#{element_name.to_s}"
98
- build_checker_or_waiter element_name, method_name, *find_args do
98
+ create_helper_method method_name, *find_args do
99
99
  define_method method_name do |timeout = Capybara.default_wait_time|
100
100
  Capybara.using_wait_time timeout do
101
101
  element_exists? *find_args
@@ -104,9 +104,9 @@ module SitePrism::ElementContainer
104
104
  end
105
105
  end
106
106
 
107
- def create_visibility_waiter element_name, *find_args
107
+ def create_visibility_waiter(element_name, *find_args)
108
108
  method_name = "wait_until_#{element_name.to_s}_visible"
109
- build_checker_or_waiter element_name, method_name, *find_args do
109
+ create_helper_method method_name, *find_args do
110
110
  define_method method_name do |timeout = Capybara.default_wait_time|
111
111
  Capybara.using_wait_time timeout do
112
112
  element_exists? *find_args
@@ -118,9 +118,9 @@ module SitePrism::ElementContainer
118
118
  end
119
119
  end
120
120
 
121
- def create_invisibility_waiter element_name, *find_args
121
+ def create_invisibility_waiter(element_name, *find_args)
122
122
  method_name = "wait_until_#{element_name.to_s}_invisible"
123
- build_checker_or_waiter element_name, method_name, *find_args do
123
+ create_helper_method method_name, *find_args do
124
124
  define_method method_name do |timeout = Capybara.default_wait_time|
125
125
  Timeout.timeout timeout, SitePrism::TimeOutWaitingForElementInvisibility do
126
126
  Capybara.using_wait_time 0 do
@@ -131,10 +131,9 @@ module SitePrism::ElementContainer
131
131
  end
132
132
  end
133
133
 
134
- def create_no_selector element_name, method_name = nil
135
- no_selector_method_name = method_name.nil? ? element_name : method_name
136
- define_method no_selector_method_name do
137
- raise SitePrism::NoSelectorForElement.new("#{self.class.name} => :#{element_name} needs a selector")
134
+ def create_no_selector(method_name)
135
+ define_method method_name do
136
+ raise SitePrism::NoSelectorForElement.new("#{self.class.name} => :#{method_name} needs a selector")
138
137
  end
139
138
  end
140
139
  end
@@ -4,9 +4,10 @@ module SitePrism
4
4
  include ElementChecker
5
5
  extend ElementContainer
6
6
 
7
- def load
8
- raise SitePrism::NoUrlForPage if url.nil?
9
- visit url
7
+ def load(expansion = {})
8
+ expanded_url = url(expansion)
9
+ raise SitePrism::NoUrlForPage if expanded_url.nil?
10
+ visit expanded_url
10
11
  end
11
12
 
12
13
  def displayed?
@@ -30,8 +31,9 @@ module SitePrism
30
31
  @url_matcher
31
32
  end
32
33
 
33
- def url
34
- self.class.url
34
+ def url(expansion = {})
35
+ return nil if self.class.url.nil?
36
+ Addressable::Template.new(self.class.url).expand(expansion).to_s
35
37
  end
36
38
 
37
39
  def url_matcher
@@ -1,4 +1,4 @@
1
1
  module SitePrism
2
- VERSION = "2.2"
2
+ VERSION = "2.3"
3
3
  end
4
4
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: site_prism
3
3
  version: !ruby/object:Gem::Version
4
- version: '2.2'
4
+ version: '2.3'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-12 00:00:00.000000000 Z
12
+ date: 2013-04-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capybara
@@ -49,6 +49,22 @@ dependencies:
49
49
  - - ~>
50
50
  - !ruby/object:Gem::Version
51
51
  version: '2.0'
52
+ - !ruby/object:Gem::Dependency
53
+ name: addressable
54
+ requirement: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ version: 2.3.3
60
+ type: :runtime
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: 2.3.3
52
68
  description: SitePrism gives you a simple, clean and semantic DSL for describing your
53
69
  site using the Page Object Model pattern, for use with Capybara
54
70
  email: nat@natontesting.com
@@ -85,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
101
  version: '0'
86
102
  requirements: []
87
103
  rubyforge_project:
88
- rubygems_version: 1.8.24
104
+ rubygems_version: 1.8.25
89
105
  signing_key:
90
106
  specification_version: 3
91
107
  summary: A Page Object Model DSL for Capybara