mohawk 0.1.4 → 0.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.
Files changed (73) hide show
  1. data/.gitmodules +3 -3
  2. data/Changelog +6 -1
  3. data/Rakefile +2 -3
  4. data/cucumber.yml +1 -1
  5. data/features/combo_box.feature +8 -0
  6. data/features/menu.feature +8 -0
  7. data/features/step_definitions/button_steps.rb +1 -1
  8. data/features/step_definitions/combo_box_steps.rb +13 -1
  9. data/features/step_definitions/control_steps.rb +1 -1
  10. data/features/step_definitions/menu_steps.rb +7 -2
  11. data/features/support/WindowsForms.exe +0 -0
  12. data/features/support/screens/main_screen.rb +3 -0
  13. data/features/table.feature +7 -7
  14. data/features/text.feature +4 -0
  15. data/lib/mohawk/accessors.rb +3 -0
  16. data/lib/mohawk/adapters/uia/button.rb +14 -0
  17. data/lib/mohawk/adapters/uia/checkbox.rb +22 -0
  18. data/lib/mohawk/adapters/uia/control.rb +83 -0
  19. data/lib/mohawk/adapters/uia/element_locator.rb +19 -0
  20. data/lib/mohawk/adapters/uia/menu_item.rb +48 -0
  21. data/lib/mohawk/adapters/uia/radio.rb +22 -0
  22. data/lib/mohawk/adapters/uia/select_list.rb +53 -0
  23. data/lib/mohawk/adapters/uia/spinner.rb +30 -0
  24. data/lib/mohawk/adapters/uia/tab_control.rb +26 -0
  25. data/lib/mohawk/adapters/uia/table.rb +62 -0
  26. data/lib/mohawk/adapters/uia/table_row.rb +73 -0
  27. data/lib/mohawk/adapters/uia/text_box.rb +47 -0
  28. data/lib/mohawk/adapters/uia/tree_view.rb +22 -0
  29. data/lib/mohawk/adapters/uia/value_control.rb +20 -0
  30. data/lib/mohawk/adapters/uia/window.rb +64 -0
  31. data/lib/mohawk/adapters/uia_adapter.rb +36 -50
  32. data/lib/mohawk/version.rb +1 -1
  33. data/lib/mohawk/waiter.rb +18 -0
  34. data/lib/mohawk/win_32.rb +12 -0
  35. data/lib/mohawk.rb +26 -14
  36. data/mohawk.gemspec +2 -2
  37. data/spec/lib/mohawk/adapters/uia/control_spec.rb +46 -0
  38. data/spec/lib/mohawk/adapters/uia/table_row_spec.rb +36 -0
  39. data/spec/lib/mohawk/waiter_spec.rb +39 -0
  40. data/spec/lib/mohawk_spec.rb +115 -92
  41. data/spec/lib/navigation_spec.rb +14 -20
  42. data/spec/spec_helper.rb +1 -1
  43. metadata +49 -67
  44. data/lib/mohawk/accessors/button.rb +0 -20
  45. data/lib/mohawk/accessors/checkbox.rb +0 -24
  46. data/lib/mohawk/accessors/combo.rb +0 -37
  47. data/lib/mohawk/accessors/control.rb +0 -24
  48. data/lib/mohawk/accessors/label.rb +0 -15
  49. data/lib/mohawk/accessors/link.rb +0 -9
  50. data/lib/mohawk/accessors/menu_item.rb +0 -21
  51. data/lib/mohawk/accessors/radio.rb +0 -19
  52. data/lib/mohawk/accessors/spinner.rb +0 -27
  53. data/lib/mohawk/accessors/table.rb +0 -69
  54. data/lib/mohawk/accessors/table_row.rb +0 -62
  55. data/lib/mohawk/accessors/tabs.rb +0 -30
  56. data/lib/mohawk/accessors/text.rb +0 -29
  57. data/lib/mohawk/accessors/tree_view.rb +0 -32
  58. data/spec/lib/mohawk/accessors/button_spec.rb +0 -45
  59. data/spec/lib/mohawk/accessors/checkbox_spec.rb +0 -46
  60. data/spec/lib/mohawk/accessors/combo_spec.rb +0 -119
  61. data/spec/lib/mohawk/accessors/control_spec.rb +0 -47
  62. data/spec/lib/mohawk/accessors/label_spec.rb +0 -29
  63. data/spec/lib/mohawk/accessors/link_spec.rb +0 -34
  64. data/spec/lib/mohawk/accessors/menu_spec.rb +0 -32
  65. data/spec/lib/mohawk/accessors/radio_spec.rb +0 -35
  66. data/spec/lib/mohawk/accessors/spinner_spec.rb +0 -43
  67. data/spec/lib/mohawk/accessors/table_row_spec.rb +0 -28
  68. data/spec/lib/mohawk/accessors/table_spec.rb +0 -262
  69. data/spec/lib/mohawk/accessors/tabs_spec.rb +0 -58
  70. data/spec/lib/mohawk/accessors/text_spec.rb +0 -51
  71. data/spec/lib/mohawk/accessors/tree_view_spec.rb +0 -98
  72. data/spec/lib/mohawk/adapters/uia_adapter_spec.rb +0 -55
  73. data/spec/table_stubber.rb +0 -55
@@ -1,43 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class SpinnerScreen
4
- include Mohawk
5
- window(:id => 123)
6
-
7
- spinner(:price_is_right, :id => 'barker')
8
- end
9
-
10
- describe Mohawk::Accessors::Spinner do
11
- let(:window) { double('RAutomation Window') }
12
- let(:spinner) { double('RAutomation Spinner') }
13
- subject { SpinnerScreen.new }
14
-
15
- before(:each) do
16
- RAutomation::Window.stub(:new).and_return(window)
17
- window.should_receive(:spinner).with(:id => 'barker').and_return(spinner)
18
- end
19
-
20
- it 'knows the value' do
21
- spinner.should_receive(:value).and_return(11.0)
22
- subject.price_is_right.should eq(11.0)
23
- end
24
-
25
- it 'can set the value' do
26
- spinner.should_receive(:set).with(11.0)
27
- subject.price_is_right = 11.0
28
- end
29
-
30
- it 'can be incremented' do
31
- spinner.should_receive(:increment).and_return(11.0)
32
- subject.increment_price_is_right.should eq(11.0)
33
- end
34
-
35
- it 'can be decremented' do
36
- spinner.should_receive(:decrement).and_return(11.0)
37
- subject.decrement_price_is_right.should eq(11.0)
38
- end
39
-
40
- it 'can get the view' do
41
- subject.price_is_right_view.should be(spinner)
42
- end
43
- end
@@ -1,28 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Mohawk::Accessors::TableRow do
4
- let(:table) { double('RAutomation Table') }
5
- let(:adapter) { double('mohawk adapter') }
6
- let(:mohawk_table) { Mohawk::Accessors::Table.new(adapter, value: 'whatever') }
7
- let(:stubber) do
8
- TableStubber.stub(table)
9
- .with_headers('Name', 'Age')
10
- .and_row('Levi', '33')
11
- end
12
-
13
- subject { Mohawk::Accessors::TableRow.new(mohawk_table, 0) }
14
-
15
- before(:each) do
16
- adapter.stub_chain(:window, :table).and_return(table)
17
- end
18
-
19
- it '#add_to_selection' do
20
- stubber.rows[0].should_receive(:select)
21
- subject.add_to_selection
22
- end
23
-
24
- it '#select' do
25
- stubber.should_singly_select_row(0)
26
- subject.select
27
- end
28
- end
@@ -1,262 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class TableScreen
4
- include Mohawk
5
- window(:id => nil)
6
-
7
- table(:top, :id => 'tableId')
8
-
9
- # aliases
10
- table(:my_default, :id => 'defaultAliasId')
11
- listview(:my_listview, :id => 'listviewAliasId')
12
- list_view(:my_list_view, :id => 'list_viewAliasId')
13
- end
14
-
15
- include RAutomation::Adapter::MsUia
16
-
17
- describe Mohawk::Accessors::Table do
18
- let(:screen) { TableScreen.new }
19
- let(:window) { double('RAutomation Window') }
20
- let(:table) { double('Table') }
21
-
22
- before(:each) do
23
- RAutomation::Window.stub(:new).and_return(window)
24
- end
25
-
26
- context 'working with table controls' do
27
- before(:each) do
28
- window.should_receive(:table).with(:id => 'tableId').and_return(table)
29
- end
30
-
31
- it 'can select a row by index' do
32
- stubber = TableStubber.stub(table)
33
- .with_headers('Name')
34
- .and_row('First Person')
35
- .and_row('Second Person')
36
-
37
- stubber.should_singly_select_row 1
38
- screen.top = 1
39
- end
40
-
41
- it 'can select a row by value' do
42
- stubber = TableStubber.stub(table)
43
- .with_headers('Name')
44
- .and_row('John Elway')
45
-
46
- stubber.should_singly_select_row 0
47
- screen.top = 'John Elway'
48
- end
49
-
50
- it 'can clear a row by index' do
51
- stubber = TableStubber.stub(table)
52
- .with_headers('Name').and_row('Whomever')
53
-
54
- stubber.rows[0].should_receive(:clear)
55
- screen.clear_top(0)
56
- end
57
-
58
- it 'can clear a row by value' do
59
- stubber = TableStubber.stub(table)
60
- .with_headers('Name').and_row('John Elway')
61
-
62
- stubber.rows[0].should_receive(:clear)
63
- screen.clear_top('John Elway')
64
- end
65
-
66
- context 'finding rows by Hash' do
67
- it 'can find a row by hash' do
68
- TableStubber.stub(table)
69
- .with_headers('Favorite Color', 'Favorite Number', 'Name')
70
- .and_row('Blue', '7', 'Levi')
71
- .and_row('Purple', '9', 'Larry')
72
-
73
- found_row = screen.find_top :favorite_number => 9
74
- found_row.favorite_color.should eq('Purple')
75
- found_row.favorite_number.should eq('9')
76
- found_row.name.should eq('Larry')
77
- end
78
-
79
- it 'matches all values' do
80
- stubber = TableStubber.stub(table)
81
- .with_headers('Column One', 'Column Two', 'Column Three')
82
- .and_row('first', 'something', 'foo')
83
- .and_row('second', 'another', 'bar')
84
-
85
- screen.find_top(:column_one => 'second', :column_three => 'bar').row.should eq(stubber.rows[1])
86
- end
87
-
88
- it 'can handle non-string values' do
89
- stubber = TableStubber.stub(table)
90
- .with_headers('name', 'age')
91
- .and_row('Levi', '33')
92
-
93
- screen.find_top(:age => 33).row.should eq(stubber.rows.first)
94
- end
95
-
96
- it 'raises if no row is found' do
97
- TableStubber.stub(table)
98
- .with_headers('Column One', 'Column Two', 'Column Three')
99
- .and_row('first', 'something', 'foo')
100
-
101
- expect { screen.find_top :column_one => 'not found' }.to raise_error "A row with {:column_one=>\"not found\"} was not found"
102
- end
103
- end
104
-
105
- context 'selecting a row by hash' do
106
- it 'singly selects the row' do
107
- stubber = TableStubber.stub(table)
108
- .with_headers('name', 'age')
109
- .and_row('Levi', '33')
110
- .and_row('John', '54')
111
-
112
- stubber.should_singly_select_row(1)
113
- screen.select_top(:age => 54)
114
- end
115
-
116
- it 'returns the row that it selected' do
117
- stubber = TableStubber.stub(table)
118
- .with_headers('name', 'age')
119
- .and_row('Levi', '33')
120
-
121
- stubber.should_singly_select_row(0)
122
- screen.select_top(:age => 33).name.should eq('Levi')
123
- end
124
-
125
- it 'uses the find_row semantics' do
126
- stubber = TableStubber.stub(table)
127
- .with_headers('name', 'age')
128
- .and_row('Levi', '33')
129
-
130
- Mohawk::Accessors::Table.any_instance.should_receive(:find_row_with).with(:age => 33).and_call_original
131
-
132
- stubber.should_singly_select_row(0)
133
- screen.select_top :age => 33
134
- end
135
- end
136
-
137
- context 'clearing a row by hash' do
138
- it 'returns the row that it cleared' do
139
- stubber = TableStubber.stub(table)
140
- .with_headers('name', 'age')
141
- .and_row('Levi', '33')
142
-
143
- stubber.rows[0].should_receive(:clear)
144
- screen.clear_top(:age => 33).name.should eq('Levi')
145
- end
146
-
147
- it 'uses the find_row semantics' do
148
- stubber = TableStubber.stub(table)
149
- .with_headers('name', 'age')
150
- .and_row('Levi', '33')
151
-
152
- Mohawk::Accessors::Table.any_instance.should_receive(:find_row_with).with(:age => 33).and_call_original
153
-
154
- stubber.rows[0].should_receive(:clear)
155
- screen.clear_top :age => 33
156
- end
157
- end
158
-
159
- context 'adding a row to the selection' do
160
- let(:stubber) do
161
- TableStubber.stub(table)
162
- .with_headers('name')
163
- .and_row('Levi')
164
- .and_row('John')
165
- end
166
-
167
- it 'returns the row that is added' do
168
- stubber.rows[1].should_receive(:select)
169
- screen.add_top(name: 'John').name.should eq('John')
170
- end
171
-
172
- it 'uses the find_row semantics' do
173
- Mohawk::Accessors::Table.any_instance.should_receive(:find_row_with).with(name: 'Levi').and_call_original
174
-
175
- stubber.rows[0].should_receive(:select)
176
- screen.add_top name: 'Levi'
177
- end
178
- end
179
-
180
- it 'has rows' do
181
- TableStubber.stub(table)
182
- .with_headers('Column')
183
- .and_row('First Row')
184
- .and_row('Second Row')
185
-
186
- screen.top.map(&:column).should eq(['First Row', 'Second Row'])
187
- end
188
-
189
- it 'has headers' do
190
- TableStubber.stub(table).with_headers('first header', 'second header')
191
- screen.top_headers.should eq(['first header', 'second header'])
192
- end
193
-
194
- it 'can return the raw view' do
195
- screen.top_view.should_not be_nil
196
- end
197
-
198
- describe Mohawk::Accessors::TableRow do
199
- let(:table_stubber) { TableStubber.stub(table) }
200
- before(:each) do
201
- table_stubber.with_headers('column').and_row('first row')
202
- end
203
-
204
- it 'can get an individual row' do
205
- screen.top[0].should_not be_nil
206
- end
207
-
208
- it 'knows if it is selected' do
209
- table_stubber.rows[0].should_receive(:selected?).and_return(true)
210
- screen.top[0].should be_selected
211
- end
212
-
213
- it 'can be selected' do
214
- table_stubber.should_singly_select_row(0)
215
- screen.top[0].select
216
- end
217
-
218
- it 'has cells' do
219
- TableStubber.stub(table)
220
- .with_headers('first', 'second')
221
- .and_row('Cell 1', 'Cell 2')
222
-
223
- screen.top[0].cells.should eq(['Cell 1', 'Cell 2'])
224
- end
225
-
226
- it 'can get cell values by header name' do
227
- TableStubber.stub(table)
228
- .with_headers('First Header', 'Second Header')
229
- .and_row('Item 1', 'Item 2')
230
-
231
- screen.top[0].second_header.should eq('Item 2')
232
- end
233
-
234
- it 'clearly lets you know if a header is not there' do
235
- TableStubber.stub(table)
236
- .with_headers('First Header', 'Second Header')
237
- .and_row('Item 1', 'Item 2')
238
-
239
- lambda { screen.top[0].does_not_exist }.should raise_error ArgumentError, 'does_not_exist column does not exist in [:first_header, :second_header]'
240
- end
241
- end
242
- end
243
-
244
- context 'aliases for table' do
245
- let(:null_table) { double('Null ComboBox Field').as_null_object }
246
- let(:table_aliases) { ['default', 'listview', 'list_view'] }
247
-
248
- def expected_alias(id)
249
- window.should_receive(:table).with(:id => "#{id}AliasId").ordered.and_return(null_table)
250
- end
251
-
252
- it 'has many aliases' do
253
- table_aliases.each do |which_alias|
254
- expected_alias which_alias
255
- end
256
-
257
- table_aliases.each do |which_alias|
258
- screen.send "my_#{which_alias}_view"
259
- end
260
- end
261
- end
262
- end
@@ -1,58 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class TabsScreen
4
- include Mohawk
5
- window(:id => 123)
6
-
7
- tabs(:tab, :id => 'tabsId')
8
- end
9
-
10
- class TabItem
11
- attr_reader :text, :index
12
- def initialize(text, index)
13
- @text, @index = text, index
14
- end
15
- end
16
-
17
- describe Mohawk::Accessors::Tabs do
18
- let(:window) { double('RAutomation Window') }
19
- let(:tab_control) { double('RAutomation TabControl') }
20
- subject { TabsScreen.new }
21
-
22
- before(:each) do
23
- RAutomation::Window.stub(:new).and_return(window)
24
- window.should_receive(:tab_control).with(:id => 'tabsId').and_return(tab_control)
25
- end
26
-
27
- def tabs_are(*tabs)
28
- expected = tabs.each_with_index.map {|t, i| TabItem.new(t, i) }
29
- tab_control.should_receive(:items).and_return(expected)
30
- end
31
-
32
- it 'knows the currently selected tab' do
33
- tab_control.should_receive(:value).and_return('Current Tab')
34
-
35
- subject.tab.should eq('Current Tab')
36
- end
37
-
38
- it 'knows the available tabs' do
39
- tabs_are('first', 'second')
40
- subject.tab_items.should eq(['first', 'second'])
41
- end
42
-
43
- it 'can select tabs by index' do
44
- tab_control.should_receive(:select).with(1)
45
- subject.tab = 1
46
- end
47
-
48
- it 'can select tabs by value' do
49
- tab_control.should_receive(:set).with('The Tab')
50
- subject.tab = 'The Tab'
51
- end
52
-
53
- it 'can select tabs by regex' do
54
- tabs_are('Something', 'With the Number 7')
55
- tab_control.should_receive(:set).with('With the Number 7')
56
- subject.tab = /\d+/
57
- end
58
- end
@@ -1,51 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class TextScreen
4
- include Mohawk
5
- window(:id => nil)
6
-
7
- text(:text_id, :id => "textId")
8
- end
9
-
10
- describe Mohawk::Accessors::Text do
11
- let(:screen) { TextScreen.new }
12
- let(:window) { double("RAutomation Window") }
13
- let(:text_field) { double("Text Field") }
14
- let(:text_field_window) { double("Text Field Window") }
15
-
16
- before(:each) do
17
- RAutomation::Window.stub(:new).and_return(window)
18
- window.should_receive(:text_field).with(:id => "textId").and_return(text_field)
19
- end
20
-
21
- context "accessing text controls" do
22
-
23
- it "sets the text" do
24
- text_field.should_receive(:set).with("the text value")
25
- screen.text_id = "the text value"
26
- end
27
-
28
- it "retrieves the text" do
29
- text_field.should_receive(:value).and_return("the text")
30
- screen.text_id.should eq("the text")
31
- end
32
-
33
- it "clears the text" do
34
- text_field.should_receive(:clear)
35
- screen.clear_text_id
36
- end
37
-
38
- it "enters the text" do
39
- text_field.should_receive(:hwnd).and_return 123
40
- window.should_receive(:child).with(:hwnd => 123).and_return(text_field_window)
41
- text_field_window.should_receive(:send_keys).with("entered text".split(//))
42
-
43
- screen.enter_text_id "entered text"
44
- end
45
-
46
- it "can dish out the text view" do
47
- screen.text_id_view.should be(text_field)
48
- end
49
-
50
- end
51
- end
@@ -1,98 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class TreeViewScreen
4
- include Mohawk
5
- window(:id => nil)
6
-
7
- tree_view(:oak, :id => "treeViewId")
8
-
9
- # aliases
10
- tree_view(:my_default, :id => "defaultAliasId")
11
- treeview(:my_treeview, :id => "treeviewAliasId")
12
- tree(:my_tree, :id => "treeAliasId")
13
- end
14
-
15
- class FakeTreeItem
16
- attr_reader :text
17
-
18
- def initialize(item_text)
19
- @text = item_text
20
- end
21
- end
22
-
23
- describe Mohawk::Accessors::TreeView do
24
- let(:screen) { TreeViewScreen.new }
25
- let(:window) { double("RAutomation Window") }
26
- let(:tree_field) { double("TreeView Field") }
27
- let(:options) { double("TreeView Options") }
28
- let(:option) { double("TreeView Option") }
29
-
30
- before(:each) do
31
- RAutomation::Window.stub(:new).and_return(window)
32
- tree_field.stub(:options).and_return(options)
33
- end
34
-
35
- context "working with TreeView controls" do
36
- before(:each) do
37
- window.should_receive(:select_list).with(:id => "treeViewId").and_return(tree_field)
38
- end
39
-
40
- it "has a value" do
41
- tree_field.should_receive(:value).and_return("tree value")
42
- screen.oak.should eq "tree value"
43
- end
44
-
45
- it "can select items by index" do
46
- options.should_receive(:[]).with(7).and_return(option)
47
- option.should_receive(:select)
48
-
49
- screen.oak = 7
50
- end
51
-
52
- it "can select items by their value" do
53
- tree_field.should_receive(:option).with(text: 'item value').and_return(option)
54
- option.should_receive(:select)
55
-
56
- screen.oak = "item value"
57
- end
58
-
59
- it "can return the tree items" do
60
- tree_field.should_receive(:options).and_return([FakeTreeItem.new("Item One"), FakeTreeItem.new("Item Two")])
61
- screen.oak_items.should eq ["Item One", "Item Two"]
62
- end
63
-
64
- it "can expand items" do
65
- tree_field.should_receive(:expand).with(7)
66
- screen.expand_oak_item 7
67
- end
68
-
69
- it "can collapse items" do
70
- tree_field.should_receive(:collapse).with("some item")
71
- screen.collapse_oak_item "some item"
72
- end
73
-
74
- it "can work with the raw view" do
75
- tree_field.should_receive(:visible?).and_return(true)
76
- screen.oak_view.should be_visible
77
- end
78
- end
79
-
80
- context "aliases for tree_view" do
81
- let(:null_tree_view) { double("Null TreeView Field").as_null_object }
82
- let(:tree_view_aliases) { ["default", "treeview", "tree"] }
83
-
84
- def expected_alias(id)
85
- window.should_receive(:select_list).with(:id => "#{id}AliasId").ordered.and_return(null_tree_view)
86
- end
87
-
88
- it "has many aliases" do
89
- tree_view_aliases.each do |which_alias|
90
- expected_alias which_alias
91
- end
92
-
93
- tree_view_aliases.each do |which_alias|
94
- screen.send "my_#{which_alias}"
95
- end
96
- end
97
- end
98
- end
@@ -1,55 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class AnyScreen
4
- include Mohawk
5
- window(:title => /Some Title/, :children_only => true)
6
- end
7
-
8
- RSpec::Matchers.define(:use_the_cached) do |control_type, the_alias=nil|
9
- match do |screen|
10
- screen.adapter.window.stub(the_alias || control_type).and_return(double('first control'), double('second control'))
11
- first, second = 2.times.map { screen.adapter.send(control_type, :id => 'id') }
12
- first.eql?(second)
13
- end
14
- end
15
-
16
- RSpec::Matchers.define(:only_search_children_for_a) do |control_type, the_alias=nil|
17
- match do |screen|
18
- screen.adapter.window.should_receive(the_alias || control_type).with(:id => 'id', :children_only => true).and_return(double('child control'))
19
- screen.adapter.send(control_type, :id => 'id')
20
- true
21
- end
22
- end
23
-
24
- describe Mohawk::Adapters::UiaAdapter do
25
- subject(:screen) { AnyScreen.new }
26
-
27
- let(:window) { double('RAutomation Window') }
28
- before(:each) { RAutomation::Window.stub(:new).and_return(window) }
29
-
30
- context 'limiting searches to children only' do
31
- it { should only_search_children_for_a(:combo, :select_list) }
32
- it { should only_search_children_for_a(:checkbox) }
33
- it { should only_search_children_for_a(:text, :text_field) }
34
- it { should only_search_children_for_a(:button) }
35
- it { should only_search_children_for_a(:radio) }
36
- it { should only_search_children_for_a(:label) }
37
- it { should only_search_children_for_a(:link, :label) }
38
- it { should only_search_children_for_a(:table) }
39
- it { should only_search_children_for_a(:tree_view, :select_list) }
40
- it { should only_search_children_for_a(:value_control) }
41
- end
42
-
43
- context 'caching controls' do
44
- it { should use_the_cached(:combo, :select_list) }
45
- it { should use_the_cached(:checkbox) }
46
- it { should use_the_cached(:text, :text_field) }
47
- it { should use_the_cached(:button) }
48
- it { should use_the_cached(:radio) }
49
- it { should use_the_cached(:label) }
50
- it { should use_the_cached(:link, :label) }
51
- it { should use_the_cached(:table) }
52
- it { should use_the_cached(:tree_view, :select_list) }
53
- it { should use_the_cached(:value_control) }
54
- end
55
- end
@@ -1,55 +0,0 @@
1
- require 'securerandom'
2
-
3
- class TableStubber
4
- include RSpec::Mocks::ExampleMethods, RAutomation::Adapter::MsUia
5
-
6
- attr_reader :table, :rows
7
-
8
- def initialize(table)
9
- @table = table
10
- @id = SecureRandom.base64
11
- @table.stub(:search_information).and_return(@id)
12
- @table.stub(:selected_rows).and_return []
13
- @rows = []
14
- end
15
-
16
- def self.stub(table)
17
- TableStubber.new(table)
18
- end
19
-
20
- def with_headers(*headers)
21
- UiaDll.stub(:table_headers).with(@id).and_return(headers.map(&:to_s))
22
- self
23
- end
24
-
25
- def and_row(*values)
26
- stub_cells_for(add_row, values)
27
- self
28
- end
29
-
30
- def should_singly_select_row(which)
31
- UiaDll.should_receive(:table_single_select).with(@id, which)
32
- end
33
-
34
- private
35
- def add_row
36
- row = double("table #{@id}, row #{rows.count}")
37
- row.stub(:row).and_return(rows.count)
38
- Row.stub(:new).with(table, :index => rows.count).and_return(row)
39
- rows << row
40
- table.stub(:row_count).and_return(rows.count)
41
- row
42
- end
43
-
44
- def stub_cells_for(row, values)
45
- cells = []
46
- values.each_with_index do |value, index|
47
- cell = double("Cell at #{row.row}, #{index}")
48
- Cell.stub(:new).with(row, :index => index).and_return(cell)
49
- cell.stub(:text).and_return(value)
50
- cells << cell
51
- end
52
- row.stub(:value).and_return(values.first)
53
- row.stub(:cells).and_return(cells)
54
- end
55
- end