watirsome 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,11 +1,15 @@
1
+ #### v0.1.3
2
+
3
+ * Remove `Watirsome.region_matcher` so now any module may implement `initialize_region`.
4
+
1
5
  #### v0.1.2
2
6
 
3
- * Fix for checkboxes in previous version hasn't actually resolved issue. Now fixes
7
+ * Fix for checkboxes in previous version hasn't actually resolved issue. Now fixed.
4
8
 
5
9
  #### v0.1.1
6
10
 
7
- * Fixed problem when plural form of `checkbox` was `checkboxs` instead of `checkboxes`
11
+ * Fixed problem when plural form of `checkbox` was `checkboxs` instead of `checkboxes`.
8
12
 
9
13
  #### v0.1.0
10
14
 
11
- * Initial release
15
+ * Initial release.
data/README.md CHANGED
@@ -22,31 +22,35 @@ gem 'watirsome'
22
22
  ### Examples
23
23
 
24
24
  ```ruby
25
- class Page
25
+ class LoginPage
26
26
  include Watirsome
27
-
27
+
28
28
  text_field :username, label: 'Username'
29
29
  text_field :password, label: 'Password'
30
- button :login, text: 'Login'
31
-
30
+ button :submit_login, text: 'Login'
31
+
32
32
  def login(username, password)
33
33
  self.username = username
34
34
  self.password = password
35
- login
35
+ submit_login
36
36
  end
37
37
  end
38
+
39
+ browser = Watir::Browser.new
40
+ page = LoginPage.new(browser)
41
+ page.login('demo', 'demo')
38
42
  ```
39
43
 
40
44
  ### Accessors
41
45
 
42
- Watirsome provides you with accessors DSL to isolate elements from your methods.
46
+ Watirsome provides you with accessors DSL to isolate elements from your methods.
43
47
 
44
48
  All accessors are just proxied to Watir, thus you free to use all its power in your page objects.
45
49
 
46
50
  ```ruby
47
51
  class Page
48
52
  include Watirsome
49
-
53
+
50
54
  # any method defined in Watir::Container are accessible
51
55
  body :body
52
56
  section :section, id: 'section_one'
@@ -61,16 +65,16 @@ You can use any kind of locators you use with Watir.
61
65
  ```ruby
62
66
  class Page
63
67
  include Watirsome
64
-
68
+
65
69
  body :body
66
70
  section :one, id: 'section_one'
67
71
  element :svg, tag_name: 'svg'
68
- button :login, class: 'submit', index: 1
72
+ button :login, class: 'submit', index: 1
69
73
  end
70
74
 
71
75
  page = Page.new(@browser)
72
76
  page.body_element # equals to @browser.body
73
- page.section_one # equals to @browser.section(id: 'section')
77
+ page.one_section # equals to @browser.section(id: 'section_one')
74
78
  page.svg_element # equals to @browser.element(tag_name: 'svg')
75
79
  page.login_button # equals to @browser.button(class: 'submit', index: 1)
76
80
  ```
@@ -80,9 +84,9 @@ Watirsome also provides you with opportunity to locate elements by using any boo
80
84
  ```ruby
81
85
  class Page
82
86
  include Watirsome
83
-
84
- div :layer, class: 'layer', visible: true
85
- span :wrapper, class: 'span', exists: false
87
+
88
+ div :layer, class: 'layer', visible: true
89
+ span :wrapper, class: 'span', exists: false
86
90
  end
87
91
 
88
92
  page = Page.new(@browser)
@@ -95,7 +99,7 @@ You can also use proc/lambda/block to locate element. Block is executed in the c
95
99
  ```ruby
96
100
  class Page
97
101
  include Watirsome
98
-
102
+
99
103
  div :layer, class: 'layer'
100
104
  span :wrapper, -> { layer_div.span(class: 'span') }
101
105
  end
@@ -109,9 +113,9 @@ Moreover, you can pass arguments to blocks!
109
113
  ```ruby
110
114
  class Page
111
115
  include Watirsome
112
-
116
+
113
117
  div :layer, class: 'layer'
114
- a :link do |text|
118
+ a :link do |text|
115
119
  layer_div.a(text: text)
116
120
  end
117
121
  end
@@ -248,7 +252,7 @@ page.country = 'Russia' #=> selects option with "Russia" text
248
252
 
249
253
  ### Initializers
250
254
 
251
- Watirsome provides you with initializers DSL to dynamically modify your pages/regions behavior.
255
+ Watirsome provides you with initializers DSL to dynamically modify your pages/regions behavior.
252
256
 
253
257
  #### Page initializer
254
258
 
@@ -288,7 +292,7 @@ end
288
292
  class Page
289
293
  include Watirsome
290
294
  include HeaderRegion
291
-
295
+
292
296
  def initialize_page
293
297
  extend FooterRegion
294
298
  end
@@ -299,13 +303,7 @@ Page.new(@browser)
299
303
  #=> 'Initialized footer!'
300
304
  ```
301
305
 
302
- Regions are being cached, so, once initialzed, they won't be executed if you call `Page#initialize_regions` again.
303
-
304
- Each module is first checked if its name matches the regular expression of region (to make sure we don't touch unrelated included modules). By default, regexp is `/^.+(Region)$/`, but you can change it by altering `Watirsome.region_matcher`.
305
-
306
- ```ruby
307
- Watirsome.region_matcher = /^.+(Region|Helper)$/
308
- ```
306
+ Regions are being cached, so, once initialized, they won't be executed if you call `Page#initialize_regions` again.
309
307
 
310
308
  ### Limitations
311
309
 
@@ -1,6 +1,6 @@
1
1
  module Watirsome
2
2
  module Initializers
3
-
3
+
4
4
  #
5
5
  # Initializes page class.
6
6
  # Allows to define "#initialize_page" which will be called as page constructor.
@@ -25,12 +25,10 @@ module Watirsome
25
25
  # get included and extended modules
26
26
  modules = self.class.included_modules + (class << self; self end).included_modules
27
27
  modules.uniq!
28
- # make sure only necessary modules are being called
29
- regexp = Watirsome.region_matcher
30
- modules.select! { |m| regexp === m.to_s }
28
+ # initialize each module
31
29
  modules.each do |m|
32
30
  # check that constructor is defined and we haven't called it before
33
- if m.instance_methods.include?(:initialize_region) && !@initialized_regions.include?(m)
31
+ if !@initialized_regions.include?(m) && m.instance_methods.include?(:initialize_region)
34
32
  m.instance_method(:initialize_region).bind(self).call
35
33
  # cache region
36
34
  @initialized_regions << m
@@ -1,3 +1,3 @@
1
1
  module Watirsome
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end # Watirsome
data/lib/watirsome.rb CHANGED
@@ -1,9 +1,6 @@
1
1
  module Watirsome
2
2
  class << self
3
3
 
4
- # @attr [Regexp] region_matcher
5
- attr_accessor :region_matcher
6
-
7
4
  # @attr [Array<Symbol>] readable
8
5
  attr_accessor :readable
9
6
 
@@ -16,14 +13,6 @@ module Watirsome
16
13
  # @attr [Array<Symbol>] selectable
17
14
  attr_accessor :selectable
18
15
 
19
- #
20
- # Returns regular expression for region module names.
21
- # @return [Regexp]
22
- #
23
- def region_matcher
24
- @region_matcher ||= /^.+(Region)$/
25
- end
26
-
27
16
  #
28
17
  # Returns array of readable elements.
29
18
  # @return [Array<Symbol>]
@@ -165,7 +154,7 @@ module Watirsome
165
154
 
166
155
  end # self
167
156
 
168
-
157
+
169
158
  def self.included(kls)
170
159
  kls.extend Watirsome::Accessors::ClassMethods
171
160
  kls.send :include, Watirsome::Accessors::InstanceMethods
@@ -14,31 +14,22 @@ describe Watirsome::Initializers do
14
14
  it 'initializes page if there is constructor defined' do
15
15
  page.instance_variable_get(:@initialized).should == true
16
16
  end
17
-
17
+
18
18
  it 'initalizes regions' do
19
19
  Page.any_instance.should_receive :initialize_regions
20
20
  Page.new(watir)
21
21
  end
22
22
  end
23
-
23
+
24
24
  describe '#initialize_regions' do
25
25
  it 'initalizes included regions' do
26
26
  page.instance_variable_get(:@included_initialized).should == 1
27
27
  end
28
-
28
+
29
29
  it 'initalizes extended regions' do
30
30
  page.instance_variable_get(:@extended_initialized).should == 1
31
31
  end
32
-
33
- it 'does not initalize modules with incorrect name' do
34
- page.instance_variable_get(:@helper_initialized).should == nil
35
- end
36
-
37
- it 'uses Watirsome.region_matcher to match module name' do
38
- Watirsome.should_receive(:region_matcher).and_return ''
39
- page
40
- end
41
-
32
+
42
33
  it 'caches initalized regions' do
43
34
  page.initialize_regions
44
35
  page.instance_variable_get(:@included_initialized).should == 1
@@ -1,12 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Watirsome do
4
- describe '.region_matcher' do
5
- it 'returns region matcher regexp' do
6
- described_class.region_matcher.should be_a(Regexp)
7
- end
8
- end
9
-
10
4
  %w(readable clickable settable selectable).each do |method|
11
5
  describe ".#{method}" do
12
6
  it 'returns array of accessors' do
@@ -92,7 +86,7 @@ describe Watirsome do
92
86
  -> { described_class.pluralize(:foo) }.should raise_error(Watirsome::Errors::CannotPluralizeError)
93
87
  end
94
88
  end
95
-
89
+
96
90
  context 'when included' do
97
91
  include_context :page
98
92
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: watirsome
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.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-05-13 00:00:00.000000000 Z
12
+ date: 2013-06-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: watir-webdriver
@@ -151,7 +151,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
151
151
  version: '0'
152
152
  segments:
153
153
  - 0
154
- hash: 3290082201192832262
154
+ hash: 2091343636029663572
155
155
  required_rubygems_version: !ruby/object:Gem::Requirement
156
156
  none: false
157
157
  requirements:
@@ -160,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
160
  version: '0'
161
161
  segments:
162
162
  - 0
163
- hash: 3290082201192832262
163
+ hash: 2091343636029663572
164
164
  requirements: []
165
165
  rubyforge_project:
166
166
  rubygems_version: 1.8.23