watirsome 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d8dd7d5de4e6d3bd01e4b28482988d65963424d1
4
+ data.tar.gz: fb3b3abc789fdb5237609ae41b98d035a31ab6d2
5
+ SHA512:
6
+ metadata.gz: fc8eca156fa9928d4c1dd6644cda72e0749d3981e682e96ac3cf499e1853839935fa170f2750b7217c16498ec03252cc55fd6d91e9d627934dea6f0b3dbed492
7
+ data.tar.gz: 5ef5a76cc02b4c4d64230431871ae1c7c11cccf22787db111b862697417d7a7db176554e56343725ac2199db5738cf015895748b722e900f63629b27e8f2316a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ #### v0.1.4
2
+
3
+ * Support element subtype boolean locators (e.g. `select_list :list, selected: 'Default'`)
4
+
1
5
  #### v0.1.3
2
6
 
3
7
  * Remove `Watirsome.region_matcher` so now any module may implement `initialize_region`.
data/README.md CHANGED
@@ -79,22 +79,24 @@ page.svg_element # equals to @browser.element(tag_name: 'svg')
79
79
  page.login_button # equals to @browser.button(class: 'submit', index: 1)
80
80
  ```
81
81
 
82
- Watirsome also provides you with opportunity to locate elements by using any boolean method Watir element supports.
82
+ Watirsome also provides you with opportunity to locate elements by using any boolean method Watir element (and subelements) supports.
83
83
 
84
84
  ```ruby
85
85
  class Page
86
86
  include Watirsome
87
87
 
88
88
  div :layer, class: 'layer', visible: true
89
- span :wrapper, class: 'span', exists: false
89
+ span :wrapper, exists: false
90
+ select_list :country, selected: 'Please select country...'
90
91
  end
91
92
 
92
93
  page = Page.new(@browser)
93
- page.layer_div # equals to @browser.divs(class: 'layer').find { |e| e.visible? == true }
94
- page.wrapper_span # equals to @browser.divs(class: 'layer').find { |e| e.exists? == false }
94
+ page.layer_div # equals to @browser.divs(class: 'layer').find { |e| e.visible? == true }
95
+ page.wrapper_span # equals to @browser.spans.find { |e| e.exists? == false }
96
+ page.country_select_list # equals to @browser.select_lists.find { |e| e.selected?('Please select country...') }
95
97
  ```
96
98
 
97
- You can also use proc/lambda/block to locate element. Block is executed in the context of initalized page, so other accessors can be used.
99
+ You can also use proc/lambda/block to locate element. Block is executed in the context of initialized page, so other accessors can be used.
98
100
 
99
101
  ```ruby
100
102
  class Page
@@ -145,17 +147,17 @@ page.svg_element #=> #<Watir::HTMLElement:0x15288276ab771162 selector={
145
147
 
146
148
  #### Readable accessors
147
149
 
148
- For each redable element, accessor method is defined which returns text of that element.
150
+ For each readable element, accessor method is defined which returns text of that element.
149
151
 
150
152
  Read accessor method name is `element_name`.
151
153
 
152
- Default redable methods are: `[:div, :span, :p, :h1, :h2, :h3, :h4, :h5, :h6, :select_list, :text_field, :textarea]`.
154
+ Default readable methods are: `[:div, :span, :p, :h1, :h2, :h3, :h4, :h5, :h6, :select_list, :text_field, :textarea]`.
153
155
 
154
- You can make other elements redable by adding tag names to `Watirsome.redable`.
156
+ You can make other elements readable by adding tag names to `Watirsome.readable`.
155
157
 
156
158
  ```ruby
157
- # make section redable
158
- Watirsome.redable << :section
159
+ # make section readable
160
+ Watirsome.readable << :section
159
161
 
160
162
  class Page
161
163
  include Watirsome
@@ -52,7 +52,7 @@ module Watirsome
52
52
  # @api private
53
53
  #
54
54
  def define_element_accessor(name, method, *args, &block)
55
- watir_args, custom_args = extract_custom_args(args)
55
+ watir_args, custom_args = extract_custom_args(method, args)
56
56
  define_method :"#{name}_#{method}" do |*opts|
57
57
  if block_given?
58
58
  instance_exec(*opts, &block)
@@ -73,7 +73,7 @@ module Watirsome
73
73
  # @api private
74
74
  #
75
75
  def define_click_accessor(name, method, *args, &block)
76
- watir_args, custom_args = extract_custom_args(args)
76
+ watir_args, custom_args = extract_custom_args(method, args)
77
77
  define_method name do |*opts|
78
78
  if block_given?
79
79
  instance_exec(*opts, &block).click
@@ -98,7 +98,7 @@ module Watirsome
98
98
  # @api private
99
99
  #
100
100
  def define_read_accessor(name, method, *args, &block)
101
- watir_args, custom_args = extract_custom_args(args)
101
+ watir_args, custom_args = extract_custom_args(method, args)
102
102
  define_method name do |*opts|
103
103
  element = if block_given?
104
104
  instance_exec(*opts, &block)
@@ -129,7 +129,7 @@ module Watirsome
129
129
  # @api private
130
130
  #
131
131
  def define_set_accessor(name, method, *args, &block)
132
- watir_args, custom_args = extract_custom_args(args)
132
+ watir_args, custom_args = extract_custom_args(method, args)
133
133
  define_method :"#{name}=" do |*opts|
134
134
  element = if block_given?
135
135
  instance_exec(&block)
@@ -157,7 +157,7 @@ module Watirsome
157
157
  # @api private
158
158
  #
159
159
  def define_select_accessor(name, method, *args, &block)
160
- watir_args, custom_args = extract_custom_args(args)
160
+ watir_args, custom_args = extract_custom_args(method, args)
161
161
  define_method :"#{name}=" do |*opts|
162
162
  if block_given?
163
163
  instance_exec(&block).select *opts
@@ -171,18 +171,19 @@ module Watirsome
171
171
  # Extracts custom arguments which Watirsome gracefully handles from
172
172
  # mixed array with Watir locators.
173
173
  #
174
+ # @param [Symbol, String] method
174
175
  # @param [Array] args
175
176
  # @return Two arrays: Watir locators and custom locators
176
177
  # @api private
177
178
  #
178
- def extract_custom_args(*args)
179
+ def extract_custom_args(method, *args)
179
180
  identifier = args.shift
180
181
  watir_args, custom_args = [], []
181
182
  identifier.each_with_index do |hashes, index|
182
183
  watir_arg, custom_arg = {}, {}
183
184
  if hashes && !hashes.is_a?(Proc)
184
185
  hashes.each do |k, v|
185
- if Watir::Element.instance_methods.include? :"#{k}?"
186
+ if Watir.element_class_for(method).instance_methods.include? :"#{k}?"
186
187
  custom_arg[k] = identifier[index][k]
187
188
  else
188
189
  watir_arg[k] = v
@@ -218,7 +219,15 @@ module Watirsome
218
219
  plural = Watirsome.plural?(method)
219
220
  method = Watirsome.pluralize(method) unless plural
220
221
  elements = @browser.send(method, *watir_args)
221
- custom_args.first.each { |k, v| elements.to_a.select! { |e| e.send(:"#{k}?") == v } }
222
+ custom_args.first.each do |k, v|
223
+ elements.to_a.select! do |e|
224
+ if e.method(:"#{k}?").arity == 0
225
+ s.send(:"#{k}?") == v
226
+ else
227
+ e.send(:"#{k}?", v)
228
+ end
229
+ end
230
+ end
222
231
  plural ? elements : elements.first
223
232
  end
224
233
  end
@@ -1,3 +1,3 @@
1
1
  module Watirsome
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  end # Watirsome
@@ -3,10 +3,18 @@ require 'spec_helper'
3
3
  describe Watirsome::Accessors do
4
4
  include_context :page
5
5
  include_context :element
6
-
6
+
7
7
  it_defines :element_accessor, %w(div a text_field select_list)
8
8
  it_defines :read_accessor, %w(div text_field select_list)
9
9
  it_defines :click_accessor, %w(a)
10
10
  it_defines :set_accessor, %w(text_field checkbox)
11
11
  it_defines :select_accessor, %w(select_list)
12
+
13
+ it 'supports subtype custom locators' do
14
+ element2 = double('element')
15
+ expect(watir).to receive(:select_lists).with(id: 'select_list').and_return([element, element2])
16
+ expect(element).to receive(:selected?).with('Test').and_return(true)
17
+ expect(element2).to receive(:selected?).with('Test').and_return(false)
18
+ expect(page.select_list8_select_list).to eq(element)
19
+ end
12
20
  end
@@ -7,32 +7,32 @@ describe Watirsome::Initializers do
7
7
  it 'does not initalize page if there is no constructor defined' do
8
8
  page = Page.dup
9
9
  page.class_eval { remove_method :initialize_page }
10
- page.should_not_receive :initialize_page
10
+ expect(page).not_to receive(:initialize_page)
11
11
  page.new(watir)
12
12
  end
13
13
 
14
14
  it 'initializes page if there is constructor defined' do
15
- page.instance_variable_get(:@initialized).should == true
15
+ expect(page.instance_variable_get(:@initialized)).to eq(true)
16
16
  end
17
17
 
18
18
  it 'initalizes regions' do
19
- Page.any_instance.should_receive :initialize_regions
19
+ expect_any_instance_of(Page).to 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
- page.instance_variable_get(:@included_initialized).should == 1
26
+ expect(page.instance_variable_get(:@included_initialized)).to eq(1)
27
27
  end
28
28
 
29
29
  it 'initalizes extended regions' do
30
- page.instance_variable_get(:@extended_initialized).should == 1
30
+ expect(page.instance_variable_get(:@extended_initialized)).to eq(1)
31
31
  end
32
32
 
33
33
  it 'caches initalized regions' do
34
34
  page.initialize_regions
35
- page.instance_variable_get(:@included_initialized).should == 1
35
+ expect(page.instance_variable_get(:@included_initialized)).to eq(1)
36
36
  end
37
37
  end
38
38
  end
@@ -5,15 +5,15 @@ describe Watirsome do
5
5
  describe ".#{method}" do
6
6
  it 'returns array of accessors' do
7
7
  accessors = described_class.send(method)
8
- accessors.should be_an(Array)
8
+ expect(accessors).to be_an(Array)
9
9
  accessors.each do |accessor|
10
- accessor.should be_a(Symbol)
10
+ expect(accessor).to be_a(Symbol)
11
11
  end
12
12
  end
13
13
 
14
14
  it 'allows to add custom accessors' do
15
15
  described_class.send(method) << :custom
16
- described_class.send(method).should include(:custom)
16
+ expect(described_class.send(method)).to include(:custom)
17
17
  end
18
18
  end
19
19
 
@@ -28,11 +28,11 @@ describe Watirsome do
28
28
  end
29
29
 
30
30
  it "returns true if element is #{method}" do
31
- described_class.send(:"#{method}?", tag).should == true
31
+ expect(described_class.send(:"#{method}?", tag)).to eq(true)
32
32
  end
33
33
 
34
34
  it "returns false if element is not #{method}" do
35
- described_class.send(:"#{method}?", :foo).should == false
35
+ expect(described_class.send(:"#{method}?", :foo)).to eq(false)
36
36
  end
37
37
  end
38
38
  end
@@ -40,50 +40,50 @@ describe Watirsome do
40
40
  describe '.watir_methods' do
41
41
  it 'returns array of watir container methods' do
42
42
  described_class.watir_methods.each do |method|
43
- Watir::Container.instance_methods.should include(method)
43
+ expect(Watir::Container.instance_methods).to include(method)
44
44
  end
45
45
  end
46
46
  end
47
47
 
48
48
  describe '.watirsome?' do
49
49
  it 'returns true if method is watir-contained' do
50
- described_class.watirsome?(:div).should == true
50
+ expect(described_class.watirsome?(:div)).to eq(true)
51
51
  end
52
52
 
53
53
  it 'returns false if method is not watir-contained' do
54
- described_class.watirsome?(:foo).should == false
54
+ expect(described_class.watirsome?(:foo)).to eq(false)
55
55
  end
56
56
  end
57
57
 
58
58
  describe '.plural?' do
59
59
  it 'returns true if watir-contained method is plural with "s" ending' do
60
- described_class.plural?(:divs).should == true
60
+ expect(described_class.plural?(:divs)).to eq(true)
61
61
  end
62
62
 
63
63
  it 'returns true if watir-contained method is plural with "es" ending' do
64
- described_class.plural?(:checkboxes).should == true
64
+ expect(described_class.plural?(:checkboxes)).to eq(true)
65
65
  end
66
66
 
67
67
  it 'returns false if watir-contained method is singular' do
68
- described_class.plural?(:div).should == false
68
+ expect(described_class.plural?(:div)).to eq(false)
69
69
  end
70
70
 
71
71
  it 'returns false if method is not watir-contained' do
72
- described_class.plural?(:foo).should == false
72
+ expect(described_class.plural?(:foo)).to eq(false)
73
73
  end
74
74
  end
75
75
 
76
76
  describe '.pluralize' do
77
77
  it 'pluralizes method name with "s"' do
78
- described_class.pluralize(:div).should == :divs
78
+ expect(described_class.pluralize(:div)).to eq(:divs)
79
79
  end
80
80
 
81
81
  it 'pluralizes method name with "es"' do
82
- described_class.pluralize(:checkbox).should == :checkboxes
82
+ expect(described_class.pluralize(:checkbox)).to eq(:checkboxes)
83
83
  end
84
84
 
85
85
  it 'raises error when cannot pluralizes method' do
86
- -> { described_class.pluralize(:foo) }.should raise_error(Watirsome::Errors::CannotPluralizeError)
86
+ expect { described_class.pluralize(:foo) }.to raise_error(Watirsome::Errors::CannotPluralizeError)
87
87
  end
88
88
  end
89
89
 
@@ -91,19 +91,19 @@ describe Watirsome do
91
91
  include_context :page
92
92
 
93
93
  it 'adds accessor class methods' do
94
- page.class.should respond_to(:div)
94
+ expect(page.class).to respond_to(:div)
95
95
  end
96
96
 
97
97
  it 'does not add #extract_selector' do
98
- page.class.should_not respond_to(:extract_selector)
98
+ expect(page.class).not_to respond_to(:extract_selector)
99
99
  end
100
100
 
101
101
  it 'adds accessor instance methods' do
102
- page.private_methods.should include(:grab_elements)
102
+ expect(page.private_methods).to include(:grab_elements)
103
103
  end
104
104
 
105
105
  it 'adds regions initializer' do
106
- page.should respond_to(:initialize_regions)
106
+ expect(page).to respond_to(:initialize_regions)
107
107
  end
108
108
  end
109
109
  end
data/spec/spec_helper.rb CHANGED
@@ -6,8 +6,8 @@ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
6
6
  Coveralls::SimpleCov::Formatter
7
7
  ]
8
8
  SimpleCov.start do
9
- add_filter "/spec/"
10
- add_filter "/vendor/"
9
+ add_filter "/spec/"
10
+ add_filter "/vendor/"
11
11
  end
12
12
 
13
13
  require 'watir-webdriver'
@@ -19,13 +19,13 @@ end
19
19
 
20
20
  RSpec.configure do |spec|
21
21
  spec.alias_it_should_behave_like_to :it_defines, 'it defines'
22
-
22
+
23
23
  shared_context :page do
24
- let(:watir) { stub('watir') }
25
- let(:page) { Page.new(watir) }
24
+ let(:watir) { double('watir') }
25
+ let(:page) { Page.new(watir) }
26
26
  end
27
-
27
+
28
28
  shared_context :element do
29
- let(:element) { stub('element', visible?: true) }
29
+ let(:element) { double('element', visible?: true) }
30
30
  end
31
31
  end
data/spec/support/page.rb CHANGED
@@ -40,10 +40,13 @@ class Page
40
40
  # set/select accessor cannot have block arguments
41
41
  case tag
42
42
  when 'div', 'a'
43
- send(tag, :"#{tag}7") { |id| @browser.send(tag, id: id) }
43
+ send(tag, :"#{tag}7") { |id| @browser.send(tag, id: id) }
44
44
  when 'text_field', 'select_list'
45
- send(tag, :"#{tag}7") { @browser.send(tag, id: tag) }
45
+ send(tag, :"#{tag}7") { @browser.send(tag, id: tag) }
46
46
  end
47
47
  end
48
48
 
49
+ # custom subtype locators
50
+ select_list :select_list8, id: 'select_list', selected: 'Test'
51
+
49
52
  end # Page
@@ -1,51 +1,51 @@
1
1
  shared_examples_for :click_accessor do |tags|
2
2
  tags.each do |tag|
3
- context tag do
3
+ context tag do
4
4
  def accessor(tag, index, *args)
5
5
  page.send :"#{tag}#{index}", *args
6
6
  end
7
7
 
8
8
  it 'clicks element with no locators' do
9
- watir.should_receive(tag).with(no_args).and_return(element)
10
- element.should_receive(:click).with(any_args)
9
+ expect(watir).to receive(tag).with(no_args).and_return(element)
10
+ expect(element).to receive(:click).with(any_args)
11
11
  accessor(tag, 1)
12
12
  end
13
13
 
14
14
  it 'clicks element with single watir locator' do
15
- watir.should_receive(tag).with(id: tag).and_return(element)
16
- element.should_receive(:click).with(any_args)
15
+ expect(watir).to receive(tag).with(id: tag).and_return(element)
16
+ expect(element).to receive(:click).with(any_args)
17
17
  accessor(tag, 2)
18
18
  end
19
19
 
20
20
  it 'clicks element with multiple watir locator' do
21
- watir.should_receive(tag).with(id: tag, class: /#{tag}/).and_return(element)
22
- element.should_receive(:click).with(any_args)
21
+ expect(watir).to receive(tag).with(id: tag, class: /#{tag}/).and_return(element)
22
+ expect(element).to receive(:click).with(any_args)
23
23
  accessor(tag, 3)
24
24
  end
25
25
 
26
26
  it 'clicks element with custom locator' do
27
- element2 = stub('element', visible?: false)
27
+ element2 = double('element', visible?: false)
28
28
  plural = Watirsome.pluralize(tag)
29
- watir.should_receive(plural).with(id: tag, class: tag).and_return([element, element2])
30
- element.should_receive(:click).with(any_args)
29
+ expect(watir).to receive(plural).with(id: tag, class: tag).and_return([element, element2])
30
+ expect(element).to receive(:click).with(any_args)
31
31
  accessor(tag, 4)
32
32
  end
33
33
 
34
34
  it 'clicks element with proc' do
35
- watir.should_receive(tag).with(id: tag).and_return(element)
36
- element.should_receive(:click).with(any_args)
35
+ expect(watir).to receive(tag).with(id: tag).and_return(element)
36
+ expect(element).to receive(:click).with(any_args)
37
37
  accessor(tag, 5)
38
38
  end
39
39
 
40
40
  it 'clicks element with lambda' do
41
- watir.should_receive(tag).with(id: tag).and_return(element)
42
- element.should_receive(:click).with(any_args)
41
+ expect(watir).to receive(tag).with(id: tag).and_return(element)
42
+ expect(element).to receive(:click).with(any_args)
43
43
  accessor(tag, 6)
44
44
  end
45
45
 
46
46
  it 'clicks element with block and custom arguments' do
47
- watir.should_receive(tag).with(id: tag).and_return(element)
48
- element.should_receive(:click).with(any_args)
47
+ expect(watir).to receive(tag).with(id: tag).and_return(element)
48
+ expect(element).to receive(:click).with(any_args)
49
49
  accessor(tag, 7, tag)
50
50
  end
51
51
  end
@@ -1,47 +1,47 @@
1
1
  shared_examples_for :element_accessor do |tags|
2
2
  tags.each do |tag|
3
- context tag do
3
+ context tag do
4
4
  def accessor(tag, index, *args)
5
5
  page.send :"#{tag}#{index}_#{tag}", *args
6
6
  end
7
7
 
8
8
  it 'finds element with no locators' do
9
- watir.should_receive(tag).with(no_args).and_return(element)
10
- accessor(tag, 1).should == element
9
+ expect(watir).to receive(tag).with(no_args).and_return(element)
10
+ expect(accessor(tag, 1)).to eq(element)
11
11
  end
12
12
 
13
13
  it 'finds element with single watir locator' do
14
- watir.should_receive(tag).with(id: tag).and_return(element)
15
- accessor(tag, 2).should == element
14
+ expect(watir).to receive(tag).with(id: tag).and_return(element)
15
+ expect(accessor(tag, 2)).to eq(element)
16
16
  end
17
17
 
18
18
  it 'finds element with multiple watir locator' do
19
- watir.should_receive(tag).with(id: tag, class: /#{tag}/).and_return(element)
20
- accessor(tag, 3).should == element
19
+ expect(watir).to receive(tag).with(id: tag, class: /#{tag}/).and_return(element)
20
+ expect(accessor(tag, 3)).to eq(element)
21
21
  end
22
22
 
23
23
  it 'finds element with custom locator' do
24
- element2 = stub('element')
24
+ element2 = double('element')
25
25
  plural = Watirsome.pluralize(tag)
26
- watir.should_receive(plural).with(id: tag, class: tag).and_return([element, element2])
27
- element.should_receive(:visible?).with(no_args).and_return(true)
28
- element2.should_receive(:visible?).with(no_args).and_return(false)
29
- accessor(tag, 4).should == element
26
+ expect(watir).to receive(plural).with(id: tag, class: tag).and_return([element, element2])
27
+ expect(element).to receive(:visible?).and_return(true)
28
+ expect(element2).to receive(:visible?).and_return(false)
29
+ expect(accessor(tag, 4)).to eq(element)
30
30
  end
31
31
 
32
32
  it 'finds element with proc' do
33
- watir.should_receive(tag).with(id: tag).and_return(element)
34
- accessor(tag, 5).should == element
33
+ expect(watir).to receive(tag).with(id: tag).and_return(element)
34
+ expect(accessor(tag, 5)).to eq(element)
35
35
  end
36
36
 
37
37
  it 'finds element with lambda' do
38
- watir.should_receive(tag).with(id: tag).and_return(element)
39
- accessor(tag, 6).should == element
38
+ expect(watir).to receive(tag).with(id: tag).and_return(element)
39
+ expect(accessor(tag, 6)).to eq(element)
40
40
  end
41
41
 
42
42
  it 'finds element with block and custom arguments' do
43
- watir.should_receive(tag).with(id: tag).and_return(element)
44
- accessor(tag, 7, tag).should == element
43
+ expect(watir).to receive(tag).with(id: tag).and_return(element)
44
+ expect(accessor(tag, 7, tag)).to eq(element)
45
45
  end
46
46
  end
47
47
  end
@@ -1,67 +1,67 @@
1
1
  shared_examples_for :read_accessor do |tags|
2
2
  tags.each do |tag|
3
- context tag do
3
+ context tag do
4
4
  def accessor(tag, index, *args)
5
5
  page.send :"#{tag}#{index}", *args
6
6
  end
7
-
7
+
8
8
  def read_expectation(tag)
9
9
  case tag
10
10
  when 'text_field'
11
- element.should_receive(:value).and_return('text')
11
+ expect(element).to receive(:value).and_return('text')
12
12
  when 'select_list'
13
- option1 = stub('option1', selected?: true)
14
- option2 = stub('option2', selected?: false)
15
- element.should_receive(:options).and_return([option1, option2])
16
- option1.should_receive(:text).and_return('text')
17
- option2.should_not_receive(:text)
13
+ option1 = double('option1', selected?: true)
14
+ option2 = double('option2', selected?: false)
15
+ expect(element).to receive(:options).and_return([option1, option2])
16
+ expect(option1).to receive(:text).and_return('text')
17
+ expect(option2).not_to receive(:text)
18
18
  else
19
- element.should_receive(:text).and_return('text')
19
+ expect(element).to receive(:text).and_return('text')
20
20
  end
21
21
  end
22
22
 
23
23
  it 'gets text from element with no locators' do
24
- watir.should_receive(tag).with(no_args).and_return(element)
24
+ expect(watir).to receive(tag).with(no_args).and_return(element)
25
25
  read_expectation(tag)
26
- accessor(tag, 1).should == 'text'
26
+ expect(accessor(tag, 1)).to eq('text')
27
27
  end
28
28
 
29
29
  it 'gets text from element with single watir locator' do
30
- watir.should_receive(tag).with(id: tag).and_return(element)
30
+ expect(watir).to receive(tag).with(id: tag).and_return(element)
31
31
  read_expectation(tag)
32
- accessor(tag, 2).should == 'text'
32
+ expect(accessor(tag, 2)).to eq('text')
33
33
  end
34
34
 
35
35
  it 'gets text from element with multiple watir locator' do
36
- watir.should_receive(tag).with(id: tag, class: /#{tag}/).and_return(element)
36
+ expect(watir).to receive(tag).with(id: tag, class: /#{tag}/).and_return(element)
37
37
  read_expectation(tag)
38
- accessor(tag, 3).should == 'text'
38
+ expect(accessor(tag, 3)).to eq('text')
39
39
  end
40
40
 
41
41
  it 'gets text from element with custom locator' do
42
- element2 = stub('element', visible?: false)
42
+ element2 = double('element', visible?: false)
43
43
  plural = Watirsome.pluralize(tag)
44
- watir.should_receive(plural).with(id: tag, class: tag).and_return([element, element2])
44
+ expect(watir).to receive(plural).with(id: tag, class: tag).and_return([element, element2])
45
45
  read_expectation(tag)
46
- accessor(tag, 4).should == 'text'
46
+ expect(accessor(tag, 4)).to eq('text')
47
47
  end
48
48
 
49
49
  it 'gets text from element with proc' do
50
- watir.should_receive(tag).with(id: tag).and_return(element)
50
+ expect(watir).to receive(tag).with(id: tag).and_return(element)
51
51
  read_expectation(tag)
52
- accessor(tag, 5).should == 'text'
52
+ expect(accessor(tag, 5)).to eq('text')
53
53
  end
54
54
 
55
55
  it 'gets text from element with lambda' do
56
- watir.should_receive(tag).with(id: tag).and_return(element)
56
+ expect(watir).to receive(tag).with(id: tag).and_return(element)
57
57
  read_expectation(tag)
58
- accessor(tag, 6).should == 'text'
58
+ expect(accessor(tag, 6)).to eq('text')
59
59
  end
60
60
 
61
61
  it 'gets text from element with block and custom arguments' do
62
- watir.should_receive(tag).with(id: tag).and_return(element)
62
+ expect(watir).to receive(tag).with(id: tag).and_return(element)
63
63
  read_expectation(tag)
64
- accessor(tag, 7, tag).should == 'text'
64
+ expect(accessor(tag, 7, tag)).to eq('text')
65
65
  end
66
66
  end
67
67
  end
@@ -1,45 +1,45 @@
1
1
  shared_examples_for :select_accessor do |tags|
2
2
  tags.each do |tag|
3
- context tag do
3
+ context tag do
4
4
  def accessor(tag, index, *args)
5
5
  page.send :"#{tag}#{index}=", *args
6
6
  end
7
7
 
8
8
  it 'selects option for element with no locators' do
9
- watir.should_receive(tag).with(no_args).and_return(element)
10
- element.should_receive(:select).with('value')
9
+ expect(watir).to receive(tag).with(no_args).and_return(element)
10
+ expect(element).to receive(:select).with('value')
11
11
  accessor(tag, 1, 'value')
12
12
  end
13
13
 
14
14
  it 'selects option for element with single watir locator' do
15
- watir.should_receive(tag).with(id: tag).and_return(element)
16
- element.should_receive(:select).with('value')
15
+ expect(watir).to receive(tag).with(id: tag).and_return(element)
16
+ expect(element).to receive(:select).with('value')
17
17
  accessor(tag, 2, 'value')
18
18
  end
19
19
 
20
20
  it 'selects option for element with multiple watir locator' do
21
- watir.should_receive(tag).with(id: tag, class: /#{tag}/).and_return(element)
22
- element.should_receive(:select).with('value')
21
+ expect(watir).to receive(tag).with(id: tag, class: /#{tag}/).and_return(element)
22
+ expect(element).to receive(:select).with('value')
23
23
  accessor(tag, 3, 'value')
24
24
  end
25
25
 
26
26
  it 'selects option for element with custom locator' do
27
- element2 = stub('element', visible?: false)
27
+ element2 = double('element', visible?: false)
28
28
  plural = Watirsome.pluralize(tag)
29
- watir.should_receive(plural).with(id: tag, class: tag).and_return([element, element2])
30
- element.should_receive(:select).with('value')
29
+ expect(watir).to receive(plural).with(id: tag, class: tag).and_return([element, element2])
30
+ expect(element).to receive(:select).with('value')
31
31
  accessor(tag, 4, 'value')
32
32
  end
33
33
 
34
34
  it 'selects option for element with proc' do
35
- watir.should_receive(tag).with(id: tag).and_return(element)
36
- element.should_receive(:select).with('value')
35
+ expect(watir).to receive(tag).with(id: tag).and_return(element)
36
+ expect(element).to receive(:select).with('value')
37
37
  accessor(tag, 5, 'value')
38
38
  end
39
39
 
40
40
  it 'selects option for element with lambda' do
41
- watir.should_receive(tag).with(id: tag).and_return(element)
42
- element.should_receive(:select).with('value')
41
+ expect(watir).to receive(tag).with(id: tag).and_return(element)
42
+ expect(element).to receive(:select).with('value')
43
43
  accessor(tag, 6, 'value')
44
44
  end
45
45
  end
@@ -1,52 +1,52 @@
1
1
  shared_examples_for :set_accessor do |tags|
2
2
  tags.each do |tag|
3
- context tag do
3
+ context tag do
4
4
  def accessor(tag, index, *args)
5
5
  page.send :"#{tag}#{index}=", *args
6
6
  end
7
7
 
8
8
  it 'sets value on element with no locators' do
9
- watir.should_receive(tag).with(no_args).and_return(element)
10
- element.should_receive(:set).with('value')
9
+ expect(watir).to receive(tag).with(no_args).and_return(element)
10
+ expect(element).to receive(:set).with('value')
11
11
  accessor(tag, 1, 'value')
12
12
  end
13
13
 
14
14
  it 'sets value on element with single watir locator' do
15
- watir.should_receive(tag).with(id: tag).and_return(element)
16
- element.should_receive(:set).with('value')
15
+ expect(watir).to receive(tag).with(id: tag).and_return(element)
16
+ expect(element).to receive(:set).with('value')
17
17
  accessor(tag, 2, 'value')
18
18
  end
19
19
 
20
20
  it 'sets value on element with multiple watir locator' do
21
- watir.should_receive(tag).with(id: tag, class: /#{tag}/).and_return(element)
22
- element.should_receive(:set).with('value')
21
+ expect(watir).to receive(tag).with(id: tag, class: /#{tag}/).and_return(element)
22
+ expect(element).to receive(:set).with('value')
23
23
  accessor(tag, 3, 'value')
24
24
  end
25
25
 
26
26
  it 'sets value on element with custom locator' do
27
- element2 = stub('element', visible?: false)
27
+ element2 = double('element', visible?: false)
28
28
  plural = Watirsome.pluralize(tag)
29
- watir.should_receive(plural).with(id: tag, class: tag).and_return([element, element2])
30
- element.should_receive(:set).with('value')
29
+ expect(watir).to receive(plural).with(id: tag, class: tag).and_return([element, element2])
30
+ expect(element).to receive(:set).with('value')
31
31
  accessor(tag, 4, 'value')
32
32
  end
33
33
 
34
34
  it 'sets value on element with proc' do
35
- watir.should_receive(tag).with(id: tag).and_return(element)
36
- element.should_receive(:set).with('value')
35
+ expect(watir).to receive(tag).with(id: tag).and_return(element)
36
+ expect(element).to receive(:set).with('value')
37
37
  accessor(tag, 5, 'value')
38
38
  end
39
39
 
40
40
  it 'sets value on element with lambda' do
41
- watir.should_receive(tag).with(id: tag).and_return(element)
42
- element.should_receive(:set).with('value')
41
+ expect(watir).to receive(tag).with(id: tag).and_return(element)
42
+ expect(element).to receive(:set).with('value')
43
43
  accessor(tag, 6, 'value')
44
44
  end
45
-
45
+
46
46
  it 'sends keys if element cannot be set' do
47
- watir.should_receive(tag).with(no_args).and_return(element)
48
- element.stub(:respond_to?).with(:set).and_return(false)
49
- element.should_receive(:send_keys).with('value')
47
+ expect(watir).to receive(tag).with(no_args).and_return(element)
48
+ allow(element).to receive(:respond_to?).with(:set).and_return(false)
49
+ expect(element).to receive(:send_keys).with('value')
50
50
  accessor(tag, 1, 'value')
51
51
  end
52
52
  end
data/watirsome.gemspec CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
16
16
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
17
  s.require_paths = %w(lib)
18
18
 
19
- s.add_dependency 'watir-webdriver'
19
+ s.add_dependency 'watir-webdriver', '>= 0.6.9'
20
20
 
21
21
  s.add_development_dependency 'rspec'
22
22
  s.add_development_dependency 'rake'
metadata CHANGED
@@ -1,110 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: watirsome
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
5
- prerelease:
4
+ version: 0.1.4
6
5
  platform: ruby
7
6
  authors:
8
7
  - Alex Rodionov
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-06-22 00:00:00.000000000 Z
11
+ date: 2014-04-13 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: watir-webdriver
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
- version: '0'
19
+ version: 0.6.9
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
- version: '0'
26
+ version: 0.6.9
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rake
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ">="
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: fuubar
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - ">="
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - ">="
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: simplecov
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - ">="
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - ">="
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: coveralls
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ! '>='
87
+ - - ">="
100
88
  - !ruby/object:Gem::Version
101
89
  version: '0'
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ! '>='
94
+ - - ">="
108
95
  - !ruby/object:Gem::Version
109
96
  version: '0'
110
97
  description: Pure dynamic Watir-based page object DSL
@@ -113,8 +100,8 @@ executables: []
113
100
  extensions: []
114
101
  extra_rdoc_files: []
115
102
  files:
116
- - .coveralls.yml
117
- - .travis.yml
103
+ - ".coveralls.yml"
104
+ - ".travis.yml"
118
105
  - CHANGELOG.md
119
106
  - Gemfile
120
107
  - LICENSE.md
@@ -139,33 +126,26 @@ files:
139
126
  - watirsome.gemspec
140
127
  homepage: http://github.com/p0deje/watirsome
141
128
  licenses: []
129
+ metadata: {}
142
130
  post_install_message:
143
131
  rdoc_options: []
144
132
  require_paths:
145
133
  - lib
146
134
  required_ruby_version: !ruby/object:Gem::Requirement
147
- none: false
148
135
  requirements:
149
- - - ! '>='
136
+ - - ">="
150
137
  - !ruby/object:Gem::Version
151
138
  version: '0'
152
- segments:
153
- - 0
154
- hash: 2091343636029663572
155
139
  required_rubygems_version: !ruby/object:Gem::Requirement
156
- none: false
157
140
  requirements:
158
- - - ! '>='
141
+ - - ">="
159
142
  - !ruby/object:Gem::Version
160
143
  version: '0'
161
- segments:
162
- - 0
163
- hash: 2091343636029663572
164
144
  requirements: []
165
145
  rubyforge_project:
166
- rubygems_version: 1.8.23
146
+ rubygems_version: 2.2.0
167
147
  signing_key:
168
- specification_version: 3
148
+ specification_version: 4
169
149
  summary: Awesome page objects with Watir
170
150
  test_files:
171
151
  - spec/lib/watirsome/accessors_spec.rb