watir-webdriver 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +53 -31
- data/VERSION +1 -1
- data/lib/watir-webdriver.rb +6 -8
- data/lib/watir-webdriver/attribute_helper.rb +121 -0
- data/lib/watir-webdriver/browser.rb +13 -6
- data/lib/watir-webdriver/collections/element_collection.rb +21 -15
- data/lib/watir-webdriver/collections/table_row_collection.rb +11 -0
- data/lib/watir-webdriver/container.rb +17 -11
- data/lib/watir-webdriver/element.rb +201 -0
- data/lib/watir-webdriver/elements/button.rb +19 -2
- data/lib/watir-webdriver/elements/checkbox.rb +24 -4
- data/lib/watir-webdriver/elements/file_field.rb +24 -4
- data/lib/watir-webdriver/elements/font.rb +10 -11
- data/lib/watir-webdriver/elements/frame.rb +11 -3
- data/lib/watir-webdriver/elements/generated.rb +2491 -1313
- data/lib/watir-webdriver/elements/hidden.rb +16 -5
- data/lib/watir-webdriver/elements/input.rb +44 -5
- data/lib/watir-webdriver/elements/link.rb +6 -8
- data/lib/watir-webdriver/elements/radio.rb +25 -6
- data/lib/watir-webdriver/elements/{select_list.rb → select.rb} +8 -9
- data/lib/watir-webdriver/elements/text_field.rb +32 -3
- data/lib/watir-webdriver/html.rb +18 -0
- data/lib/watir-webdriver/html/generator.rb +112 -0
- data/lib/watir-webdriver/html/idl_sorter.rb +49 -0
- data/lib/watir-webdriver/html/spec_extractor.rb +111 -0
- data/lib/watir-webdriver/html/util.rb +31 -0
- data/lib/watir-webdriver/html/visitor.rb +186 -0
- data/lib/watir-webdriver/locators/element_locator.rb +4 -0
- data/lib/watir-webdriver/locators/text_field_locator.rb +2 -2
- data/lib/watir-webdriver/xpath_support.rb +3 -5
- data/lib/yard/handlers/watir.rb +57 -0
- data/spec/{base_element_spec.rb → element_spec.rb} +3 -2
- data/spec/input_spec.rb +65 -0
- data/spec/spec_helper.rb +9 -2
- data/spec/watirspec/area_spec.rb +9 -13
- data/spec/watirspec/areas_spec.rb +7 -1
- data/spec/watirspec/browser_spec.rb +68 -72
- data/spec/watirspec/button_spec.rb +16 -9
- data/spec/watirspec/buttons_spec.rb +11 -9
- data/spec/watirspec/checkbox_spec.rb +1 -1
- data/spec/watirspec/checkboxes_spec.rb +7 -1
- data/spec/watirspec/collections_spec.rb +18 -0
- data/spec/watirspec/dd_spec.rb +1 -1
- data/spec/watirspec/dds_spec.rb +7 -1
- data/spec/watirspec/del_spec.rb +141 -0
- data/spec/watirspec/dels_spec.rb +37 -0
- data/spec/watirspec/div_spec.rb +6 -22
- data/spec/watirspec/divs_spec.rb +8 -2
- data/spec/watirspec/dl_spec.rb +1 -1
- data/spec/watirspec/dls_spec.rb +7 -1
- data/spec/watirspec/dt_spec.rb +1 -1
- data/spec/watirspec/dts_spec.rb +7 -1
- data/spec/watirspec/element_spec.rb +11 -20
- data/spec/watirspec/em_spec.rb +1 -1
- data/spec/watirspec/ems_spec.rb +7 -1
- data/spec/watirspec/filefield_spec.rb +8 -11
- data/spec/watirspec/filefields_spec.rb +7 -1
- data/spec/watirspec/font_spec.rb +2 -2
- data/spec/watirspec/form_spec.rb +10 -18
- data/spec/watirspec/forms_spec.rb +7 -1
- data/spec/watirspec/frame_spec.rb +69 -73
- data/spec/watirspec/frames_spec.rb +15 -2
- data/spec/watirspec/hidden_spec.rb +1 -1
- data/spec/watirspec/hiddens_spec.rb +7 -1
- data/spec/watirspec/hn_spec.rb +1 -1
- data/spec/watirspec/hns_spec.rb +23 -27
- data/spec/watirspec/image_spec.rb +9 -15
- data/spec/watirspec/images_spec.rb +7 -1
- data/spec/watirspec/ins_spec.rb +142 -0
- data/spec/watirspec/inses_spec.rb +37 -0
- data/spec/watirspec/label_spec.rb +1 -1
- data/spec/watirspec/labels_spec.rb +7 -1
- data/spec/watirspec/li_spec.rb +1 -1
- data/spec/watirspec/lib/guards.rb +12 -12
- data/spec/watirspec/lib/implementation.rb +48 -0
- data/spec/watirspec/lib/watirspec.rb +17 -12
- data/spec/watirspec/link_spec.rb +6 -11
- data/spec/watirspec/links_spec.rb +1 -1
- data/spec/watirspec/lis_spec.rb +7 -1
- data/spec/watirspec/map_spec.rb +1 -1
- data/spec/watirspec/maps_spec.rb +7 -1
- data/spec/watirspec/meta_spec.rb +13 -15
- data/spec/watirspec/metas_spec.rb +6 -1
- data/spec/watirspec/ol_spec.rb +57 -59
- data/spec/watirspec/ols_spec.rb +10 -4
- data/spec/watirspec/option_spec.rb +50 -83
- data/spec/watirspec/p_spec.rb +1 -1
- data/spec/watirspec/pre_spec.rb +1 -1
- data/spec/watirspec/pres_spec.rb +7 -1
- data/spec/watirspec/ps_spec.rb +7 -1
- data/spec/watirspec/radio_spec.rb +9 -11
- data/spec/watirspec/radios_spec.rb +1 -1
- data/spec/watirspec/select_list_spec.rb +27 -40
- data/spec/watirspec/select_lists_spec.rb +1 -1
- data/spec/watirspec/span_spec.rb +1 -1
- data/spec/watirspec/spans_spec.rb +7 -1
- data/spec/watirspec/spec_helper.rb +1 -0
- data/spec/watirspec/strong_spec.rb +1 -1
- data/spec/watirspec/strongs_spec.rb +7 -1
- data/spec/watirspec/table_bodies_spec.rb +22 -10
- data/spec/watirspec/table_body_spec.rb +33 -40
- data/spec/watirspec/table_cell_spec.rb +1 -1
- data/spec/watirspec/table_cells_spec.rb +36 -15
- data/spec/watirspec/table_footer_spec.rb +43 -40
- data/spec/watirspec/table_footers_spec.rb +35 -19
- data/spec/watirspec/table_header_spec.rb +44 -39
- data/spec/watirspec/table_headers_spec.rb +37 -19
- data/spec/watirspec/table_row_spec.rb +13 -9
- data/spec/watirspec/table_rows_spec.rb +16 -6
- data/spec/watirspec/table_spec.rb +83 -62
- data/spec/watirspec/tables_spec.rb +7 -1
- data/spec/watirspec/text_field_spec.rb +4 -6
- data/spec/watirspec/text_fields_spec.rb +1 -1
- data/spec/watirspec/ul_spec.rb +1 -1
- data/spec/watirspec/uls_spec.rb +25 -22
- data/support/html5.html +89235 -0
- data/watir-webdriver.gemspec +31 -21
- metadata +52 -23
- data/TODO +0 -15
- data/lib/watir-webdriver/base_element.rb +0 -361
- data/lib/watir-webdriver/collections/buttons_collection.rb +0 -15
- data/lib/watir-webdriver/collections/table_rows_collection.rb +0 -16
- data/lib/watir-webdriver/collections/text_fields_collection.rb +0 -15
- data/lib/watir-webdriver/elements/headings.rb +0 -48
- data/support/html5/html5.idl +0 -1274
- data/support/html5/old/html5.idl +0 -962
- data/support/html5/old/html5_extras.idl +0 -145
- data/support/html5/watir_visitor.rb +0 -173
- data/support/yard_handlers.rb +0 -87
data/spec/watirspec/hns_spec.rb
CHANGED
@@ -1,38 +1,34 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require File.dirname(__FILE__)
|
2
|
+
require File.expand_path('spec_helper', File.dirname(__FILE__))
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
browser.goto(WatirSpec.files + "/non_control_elements.html")
|
9
|
-
end
|
4
|
+
describe "H1s", "H2s", "H3s", "H4s", "H5s", "H6s" do
|
5
|
+
before :each do
|
6
|
+
browser.goto(WatirSpec.files + "/non_control_elements.html")
|
7
|
+
end
|
10
8
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
9
|
+
describe "#length" do
|
10
|
+
it "returns the number of h1s" do
|
11
|
+
browser.h2s.length.should == 9
|
15
12
|
end
|
13
|
+
end
|
16
14
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
15
|
+
describe "#[]" do
|
16
|
+
it "returns the h1 at the given index" do
|
17
|
+
browser.h1s[0].id.should == "first_header"
|
21
18
|
end
|
19
|
+
end
|
22
20
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
31
|
-
collection.length
|
21
|
+
describe "#each" do
|
22
|
+
it "iterates through header collections correctly" do
|
23
|
+
lengths = (1..6).collect do |i|
|
24
|
+
collection = browser.send(:"h#{i}s")
|
25
|
+
collection.each_with_index do |h, index|
|
26
|
+
h.id.should == browser.send(:"h#{i}", :index, index).id
|
27
|
+
h.value.should == browser.send(:"h#{i}", :index, index).value
|
32
28
|
end
|
33
|
-
|
29
|
+
collection.length
|
34
30
|
end
|
31
|
+
lengths.should == [2, 9, 2, 1, 1, 2]
|
35
32
|
end
|
36
33
|
end
|
37
|
-
|
38
|
-
end
|
34
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require File.dirname(__FILE__)
|
2
|
+
require File.expand_path('spec_helper', File.dirname(__FILE__))
|
3
3
|
|
4
4
|
describe "Image" do
|
5
5
|
|
@@ -13,9 +13,7 @@ describe "Image" do
|
|
13
13
|
browser.image(:id, 'square').should exist
|
14
14
|
browser.image(:id, /square/).should exist
|
15
15
|
|
16
|
-
|
17
|
-
browser.image(:src, 'images/circle.jpg').should exist
|
18
|
-
end
|
16
|
+
browser.image(:src, 'images/circle.jpg').should exist
|
19
17
|
|
20
18
|
browser.image(:src, /circle/).should exist
|
21
19
|
browser.image(:alt, 'circle').should exist
|
@@ -122,7 +120,7 @@ describe "Image" do
|
|
122
120
|
end
|
123
121
|
|
124
122
|
# File methods
|
125
|
-
not_compliant_on :
|
123
|
+
not_compliant_on :webdriver do
|
126
124
|
describe "#file_created_date" do
|
127
125
|
it "returns the date the image was created as reported by the file system" do
|
128
126
|
browser.goto(WatirSpec.host + "/images.html")
|
@@ -134,7 +132,7 @@ describe "Image" do
|
|
134
132
|
end
|
135
133
|
|
136
134
|
|
137
|
-
not_compliant_on :
|
135
|
+
not_compliant_on :webdriver do # WTR-346
|
138
136
|
describe "#file_size" do
|
139
137
|
it "returns the file size of the image if the image exists" do
|
140
138
|
browser.image(:id, 'square').file_size.should == File.size("#{WatirSpec.files}/images/square.jpg".sub("file://", ''))
|
@@ -147,10 +145,8 @@ describe "Image" do
|
|
147
145
|
end
|
148
146
|
|
149
147
|
describe "#height" do
|
150
|
-
|
151
|
-
|
152
|
-
browser.image(:id, 'square').height.should == 88
|
153
|
-
end
|
148
|
+
it "returns the height of the image if the image exists" do
|
149
|
+
browser.image(:id, 'square').height.should == 88
|
154
150
|
end
|
155
151
|
|
156
152
|
it "raises UnknownObjectException if the image doesn't exist" do
|
@@ -159,10 +155,8 @@ describe "Image" do
|
|
159
155
|
end
|
160
156
|
|
161
157
|
describe "#width" do
|
162
|
-
|
163
|
-
|
164
|
-
browser.image(:id, 'square').width.should == 88
|
165
|
-
end
|
158
|
+
it "returns the width of the image if the image exists" do
|
159
|
+
browser.image(:id, 'square').width.should == 88
|
166
160
|
end
|
167
161
|
|
168
162
|
it "raises UnknownObjectException if the image doesn't exist" do
|
@@ -193,7 +187,7 @@ describe "Image" do
|
|
193
187
|
end
|
194
188
|
end
|
195
189
|
|
196
|
-
not_compliant_on :
|
190
|
+
not_compliant_on :webdriver do
|
197
191
|
describe "#save" do
|
198
192
|
it "saves the image to a file" do
|
199
193
|
file = "#{File.expand_path Dir.pwd}/sample.img.dat"
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require File.dirname(__FILE__)
|
2
|
+
require File.expand_path('spec_helper', File.dirname(__FILE__))
|
3
3
|
|
4
4
|
describe "Images" do
|
5
5
|
|
@@ -21,10 +21,16 @@ describe "Images" do
|
|
21
21
|
|
22
22
|
describe "#each" do
|
23
23
|
it "iterates through images correctly" do
|
24
|
+
count = 0
|
25
|
+
|
24
26
|
browser.images.each_with_index do |c, index|
|
25
27
|
c.id.should == browser.image(:index, index).id
|
26
28
|
c.value.should == browser.image(:index, index).value
|
29
|
+
|
30
|
+
count += 1
|
27
31
|
end
|
32
|
+
|
33
|
+
count.should > 0
|
28
34
|
end
|
29
35
|
end
|
30
36
|
|
@@ -0,0 +1,142 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.expand_path('spec_helper', File.dirname(__FILE__))
|
3
|
+
|
4
|
+
describe "Ins" do
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
browser.goto(WatirSpec.files + "/non_control_elements.html")
|
8
|
+
end
|
9
|
+
|
10
|
+
# Exists method
|
11
|
+
describe "#exist?" do
|
12
|
+
it "returns true if the 'ins' exists" do
|
13
|
+
browser.ins(:id, "lead").should exist
|
14
|
+
browser.ins(:id, /lead/).should exist
|
15
|
+
browser.ins(:text, "This is an inserted text tag 1").should exist
|
16
|
+
browser.ins(:text, /This is an inserted text tag 1/).should exist
|
17
|
+
browser.ins(:class, "lead").should exist
|
18
|
+
browser.ins(:class, /lead/).should exist
|
19
|
+
browser.ins(:index, 0).should exist
|
20
|
+
browser.ins(:xpath, "//ins[@id='lead']").should exist
|
21
|
+
end
|
22
|
+
|
23
|
+
it "returns false if the element doesn't exist" do
|
24
|
+
browser.ins(:id, "no_such_id").should_not exist
|
25
|
+
browser.ins(:id, /no_such_id/).should_not exist
|
26
|
+
browser.ins(:text, "no_such_text").should_not exist
|
27
|
+
browser.ins(:text, /no_such_text/).should_not exist
|
28
|
+
browser.ins(:class, "no_such_class").should_not exist
|
29
|
+
browser.ins(:class, /no_such_class/).should_not exist
|
30
|
+
browser.ins(:index, 1337).should_not exist
|
31
|
+
browser.ins(:xpath, "//ins[@id='no_such_id']").should_not exist
|
32
|
+
end
|
33
|
+
|
34
|
+
it "raises TypeError when 'what' argument is invalid" do
|
35
|
+
lambda { browser.ins(:id, 3.14).exists? }.should raise_error(TypeError)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do
|
39
|
+
lambda { browser.ins(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Attribute methods
|
44
|
+
describe "#class_name" do
|
45
|
+
it "returns the class attribute" do
|
46
|
+
browser.ins(:index, 0).class_name.should == 'lead'
|
47
|
+
end
|
48
|
+
|
49
|
+
it "returns an empty string if the element exists and the attribute doesn't" do
|
50
|
+
browser.ins(:index, 2).class_name.should == ''
|
51
|
+
end
|
52
|
+
|
53
|
+
it "raises UnknownObjectException if the ins doesn't exist" do
|
54
|
+
lambda { browser.ins(:id, 'no_such_id').class_name }.should raise_error(UnknownObjectException)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "#id" do
|
59
|
+
it "returns the id attribute" do
|
60
|
+
browser.ins(:index, 0).id.should == "lead"
|
61
|
+
end
|
62
|
+
|
63
|
+
it "returns an empty string if the element exists and the attribute doesn't" do
|
64
|
+
browser.ins(:index, 2).id.should == ''
|
65
|
+
end
|
66
|
+
|
67
|
+
it "raises UnknownObjectException if the ins doesn't exist" do
|
68
|
+
lambda { browser.ins(:id, "no_such_id").id }.should raise_error(UnknownObjectException)
|
69
|
+
lambda { browser.ins(:index, 1337).id }.should raise_error(UnknownObjectException)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "#title" do
|
74
|
+
it "returns the title attribute" do
|
75
|
+
browser.ins(:index, 0).title.should == 'Lorem ipsum'
|
76
|
+
end
|
77
|
+
|
78
|
+
it "returns an empty string if the element exists and the attribute doesn't" do
|
79
|
+
browser.ins(:index, 2).title.should == ''
|
80
|
+
end
|
81
|
+
|
82
|
+
it "raises UnknownObjectException if the ins doesn't exist" do
|
83
|
+
lambda { browser.ins(:id, 'no_such_id').title }.should raise_error( UnknownObjectException)
|
84
|
+
lambda { browser.ins(:xpath, "//ins[@id='no_such_id']").title }.should raise_error( UnknownObjectException)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "#text" do
|
89
|
+
it "returns the text of the ins" do
|
90
|
+
browser.ins(:index, 1).text.should == 'This is an inserted text tag 2'
|
91
|
+
end
|
92
|
+
|
93
|
+
it "returns an empty string if the element doesn't contain any text" do
|
94
|
+
browser.ins(:index, 3).text.should == ''
|
95
|
+
end
|
96
|
+
|
97
|
+
it "raises UnknownObjectException if the ins doesn't exist" do
|
98
|
+
lambda { browser.ins(:id, 'no_such_id').text }.should raise_error( UnknownObjectException)
|
99
|
+
lambda { browser.ins(:xpath , "//ins[@id='no_such_id']").text }.should raise_error( UnknownObjectException)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe "#value" do
|
104
|
+
it "returns the value attribute" do
|
105
|
+
browser.ins(:index, 1).value.should == "invalid_attribute"
|
106
|
+
end
|
107
|
+
|
108
|
+
it "returns an empty string if the element exists and the attribute doesn't" do
|
109
|
+
browser.ins(:index, 3).value.should == ''
|
110
|
+
end
|
111
|
+
|
112
|
+
it "raises UnknownObjectException if the ins doesn't exist" do
|
113
|
+
lambda { browser.ins(:id , "no_such_id").value }.should raise_error(UnknownObjectException)
|
114
|
+
lambda { browser.ins(:index , 1337).value }.should raise_error(UnknownObjectException)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe "#respond_to?" do
|
119
|
+
it "returns true for all attribute methods" do
|
120
|
+
browser.ins(:index, 0).should respond_to(:class_name)
|
121
|
+
browser.ins(:index, 0).should respond_to(:id)
|
122
|
+
browser.ins(:index, 0).should respond_to(:title)
|
123
|
+
browser.ins(:index, 0).should respond_to(:text)
|
124
|
+
browser.ins(:index, 0).should respond_to(:value)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
# Other
|
129
|
+
describe "#click" do
|
130
|
+
it "fires events" do
|
131
|
+
browser.ins(:class, 'footer').text.should_not include('Javascript')
|
132
|
+
browser.ins(:class, 'footer').click
|
133
|
+
browser.ins(:class, 'footer').text.should include('Javascript')
|
134
|
+
end
|
135
|
+
|
136
|
+
it "raises UnknownObjectException if the ins doesn't exist" do
|
137
|
+
lambda { browser.ins(:id, "no_such_id").click }.should raise_error(UnknownObjectException)
|
138
|
+
lambda { browser.ins(:title, "no_such_title").click }.should raise_error(UnknownObjectException)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.expand_path('spec_helper', File.dirname(__FILE__))
|
3
|
+
|
4
|
+
describe "Inses" do
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
browser.goto(WatirSpec.files + "/non_control_elements.html")
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#length" do
|
11
|
+
it "returns the number of inses" do
|
12
|
+
browser.inses.length.should == 5
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#[]" do
|
17
|
+
it "returns the ins at the given index" do
|
18
|
+
browser.inses[0].id.should == "lead"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#each" do
|
23
|
+
it "iterates through inses correctly" do
|
24
|
+
count = 0
|
25
|
+
|
26
|
+
browser.inses.each_with_index do |s, index|
|
27
|
+
s.id.should == browser.ins(:index, index).id
|
28
|
+
s.value.should == browser.ins(:index, index).value
|
29
|
+
|
30
|
+
count += 1
|
31
|
+
end
|
32
|
+
|
33
|
+
count.should > 0
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require File.dirname(__FILE__)
|
2
|
+
require File.expand_path('spec_helper', File.dirname(__FILE__))
|
3
3
|
|
4
4
|
describe "Labels" do
|
5
5
|
|
@@ -21,10 +21,16 @@ describe "Labels" do
|
|
21
21
|
|
22
22
|
describe "#each" do
|
23
23
|
it "iterates through labels correctly" do
|
24
|
+
count = 0
|
25
|
+
|
24
26
|
browser.labels.each_with_index do |l, index|
|
25
27
|
l.id.should == browser.label(:index, index).id
|
26
28
|
l.value.should == browser.label(:index, index).value
|
29
|
+
|
30
|
+
count += 1
|
27
31
|
end
|
32
|
+
|
33
|
+
count.should > 0
|
28
34
|
end
|
29
35
|
end
|
30
36
|
|
data/spec/watirspec/li_spec.rb
CHANGED
@@ -8,48 +8,48 @@ module WatirSpec
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def record(guard_name, impls, data)
|
11
|
-
impls
|
12
|
-
guards[impl] << [guard_name, data]
|
13
|
-
end
|
11
|
+
guards[impls] << {:name => guard_name, :data => data}
|
14
12
|
end
|
15
13
|
|
16
14
|
def report
|
17
|
-
gs =
|
15
|
+
gs = WatirSpec.implementation.matching_guards_in(guards)
|
18
16
|
print "\n\nWatirSpec guards for this implementation: "
|
19
|
-
|
17
|
+
|
20
18
|
if gs.empty?
|
21
19
|
puts "none."
|
22
20
|
else
|
23
21
|
puts
|
24
|
-
gs.each do |
|
25
|
-
puts "\t#{
|
22
|
+
gs.each do |guard|
|
23
|
+
puts "\t#{guard[:name].to_s.ljust(20)}: #{guard[:data].inspect}"
|
26
24
|
end
|
27
25
|
end
|
28
26
|
end
|
29
|
-
end
|
27
|
+
end # class << self
|
28
|
+
|
29
|
+
private
|
30
30
|
|
31
31
|
def deviates_on(*impls)
|
32
32
|
Guards.record :deviates, impls, :file => caller.first
|
33
33
|
return yield if WatirSpec.unguarded?
|
34
|
-
yield if
|
34
|
+
yield if WatirSpec.implementation.matches_guard?(impls)
|
35
35
|
end
|
36
36
|
|
37
37
|
def not_compliant_on(*impls)
|
38
38
|
Guards.record :not_compliant, impls, :file => caller.first
|
39
39
|
return yield if WatirSpec.unguarded?
|
40
|
-
yield unless
|
40
|
+
yield unless WatirSpec.implementation.matches_guard?(impls)
|
41
41
|
end
|
42
42
|
|
43
43
|
def compliant_on(*impls)
|
44
44
|
Guards.record :compliant, impls, :file => caller.first
|
45
45
|
return yield if WatirSpec.unguarded?
|
46
|
-
yield if
|
46
|
+
yield if WatirSpec.implementation.matches_guard?(impls)
|
47
47
|
end
|
48
48
|
|
49
49
|
def bug(key, *impls)
|
50
50
|
Guards.record :bug, impls, :file => caller.first, :key => key
|
51
51
|
return yield if WatirSpec.unguarded?
|
52
|
-
yield unless
|
52
|
+
yield unless WatirSpec.implementation.matches_guard?(impls)
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module WatirSpec
|
2
|
+
class Implementation
|
3
|
+
|
4
|
+
attr_writer :name, :guard_proc, :browser_class
|
5
|
+
attr_accessor :browser_args
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@guard_proc = nil
|
9
|
+
end
|
10
|
+
|
11
|
+
def browser_class
|
12
|
+
@browser_class || raise("browser_class not set")
|
13
|
+
end
|
14
|
+
|
15
|
+
def name
|
16
|
+
@name || raise("implementation name not set")
|
17
|
+
end
|
18
|
+
|
19
|
+
def matches_guard?(args)
|
20
|
+
return @guard_proc.call(args) if @guard_proc
|
21
|
+
|
22
|
+
args.include? name
|
23
|
+
end
|
24
|
+
|
25
|
+
def matching_guards_in(guards)
|
26
|
+
result = []
|
27
|
+
guards.each { |args, data| data.each {|d| result << d } if matches_guard?(args) }
|
28
|
+
|
29
|
+
result
|
30
|
+
end
|
31
|
+
|
32
|
+
end # Implementation
|
33
|
+
end # WatirSpec
|
34
|
+
|
35
|
+
if __FILE__ == $0
|
36
|
+
require "rubygems"
|
37
|
+
require 'spec/autorun'
|
38
|
+
|
39
|
+
describe WatirSpec::Implementation do
|
40
|
+
before { @impl = WatirSpec::Implementation.new }
|
41
|
+
|
42
|
+
it "finds matching guards" do
|
43
|
+
guards = {[:watir]=>[{:name=>:not_compliant, :data=>{:file=>"./spec/watirspec/div_spec.rb:108"}}, {:name=>:deviates, :data=>{:file=>"./spec/watirspec/div_spec.rb:114"}}, {:name=>:not_compliant, :data=>{:file=>"./spec/watirspec/div_spec.rb:200"}}, {:name=>:bug, :data=>{:file=>"./spec/watirspec/div_spec.rb:228", :key=>"WTR-350"}}], [:celerity]=>[{:name=>:deviates, :data=>{:file=>"./spec/watirspec/div_spec.rb:143"}}]}
|
44
|
+
@impl.name = :celerity
|
45
|
+
@impl.matching_guards_in(guards).should == [{:name => :deviates, :data => {:file=>"./spec/watirspec/div_spec.rb:143"}}]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|