site_prism 0.9.6 → 0.9.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -21,13 +21,19 @@ module SitePrism::ElementContainer
21
21
  # #The has_search_link? method allows use of magic matchers in rspec/cucumber:
22
22
  # home.should have_search_link
23
23
  # home.should_not have_search_link
24
- def element element_name, element_locator
25
- add_element_name element_name
24
+ def element element_name, element_locator = nil
25
+ if element_locator.nil?
26
+ define_method element_name.to_s do
27
+ raise SitePrism::NoLocatorForElement.new("#{self.class.name} => :#{element_name} needs a locator")
28
+ end
29
+ else
30
+ add_element_name element_name.to_s
31
+ define_method element_name.to_s do
32
+ find_one element_locator
33
+ end
34
+ end
26
35
  create_existence_checker element_name, element_locator
27
36
  create_waiter element_name, element_locator
28
- define_method element_name.to_s do
29
- find_one element_locator
30
- end
31
37
  end
32
38
 
33
39
  # Works in the same way as {SitePrism::Page.element} in that it will generate two methods; one to check existence of
@@ -44,13 +50,19 @@ module SitePrism::ElementContainer
44
50
  # home.should have_app_links
45
51
  # home.app_links #=> [#<Capybara::Element tag="a">, #<Capybara::Element tag="a">, #<Capybara::Element tag="a">]
46
52
  # home.app_links.map {|link| link.text}.should == ['Finance', 'Maps', 'Blogs']
47
- def elements collection_name, collection_locator
48
- add_element_name collection_name
53
+ def elements collection_name, collection_locator = nil
54
+ if collection_locator.nil?
55
+ define_method collection_name.to_s do
56
+ raise SitePrism::NoLocatorForElement.new("#{self.class.name} => :#{element_name} needs a locator")
57
+ end
58
+ else
59
+ add_element_name collection_name
60
+ define_method collection_name.to_s do
61
+ find_all collection_locator
62
+ end
63
+ end
49
64
  create_existence_checker collection_name, collection_locator
50
65
  create_waiter collection_name, collection_locator
51
- define_method collection_name.to_s do
52
- find_all collection_locator
53
- end
54
66
  end
55
67
  alias :collection :elements
56
68
 
@@ -116,16 +128,30 @@ module SitePrism::ElementContainer
116
128
  # Creates a method used to check for the existence of the element whose details are passed to it
117
129
  # @param
118
130
  def create_existence_checker element_name, element_locator
119
- define_method "has_#{element_name.to_s}?" do
120
- element_exists? element_locator
131
+ method_name = "has_#{element_name.to_s}?"
132
+ if element_locator.nil?
133
+ define_method method_name do
134
+ raise SitePrism::NoLocatorForElement.new("#{self.class.name} => :#{element_name} needs a locator")
135
+ end
136
+ else
137
+ define_method method_name do
138
+ element_exists? element_locator
139
+ end
121
140
  end
122
141
  end
123
142
 
124
143
  # Creates a method used to wait for an element to appear - uses the default capybara wait time
125
144
  def create_waiter element_name, element_locator
126
- define_method "wait_for_#{element_name.to_s}" do |timeout = Capybara.default_wait_time|
127
- Capybara.using_wait_time timeout do
128
- element_waiter element_locator
145
+ method_name = "wait_for_#{element_name.to_s}"
146
+ if element_locator.nil?
147
+ define_method method_name do
148
+ raise SitePrism::NoLocatorForElement.new("#{self.class.name} => :#{element_name} needs a locator")
149
+ end
150
+ else
151
+ define_method method_name do |timeout = Capybara.default_wait_time|
152
+ Capybara.using_wait_time timeout do
153
+ element_waiter element_locator
154
+ end
129
155
  end
130
156
  end
131
157
  end
@@ -4,5 +4,7 @@ module SitePrism
4
4
  class NoUrlForPage < StandardError; end
5
5
  # Raised if you check to see if a page is displayed but it hasn't had its url matcher set
6
6
  class NoUrlMatcherForPage < StandardError; end
7
+ # Raised if you ask for an element that hasn't got a locator (i.e. a pending element)
8
+ class NoLocatorForElement < StandardError; end
7
9
  end
8
10
 
@@ -1,3 +1,3 @@
1
1
  module SitePrism
2
- VERSION = "0.9.6"
2
+ VERSION = "0.9.7"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: site_prism
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.9.6
5
+ version: 0.9.7
6
6
  platform: ruby
7
7
  authors:
8
8
  - Nat Ritmeyer
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-03-06 00:00:00 Z
13
+ date: 2012-03-11 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: capybara