watirspec 0.1.0 → 0.1.1

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.
data/History.rdoc CHANGED
@@ -1,3 +1,13 @@
1
+ === Version 0.1.1 / 2010-04-04
2
+
3
+ * Watir::Table#to_a and Watir::TableRow#to_a work now well with tr, th, td elements, colspan and nested tables.
4
+ This means that you can test easily tables now:
5
+ expected_table = [["one", "two"], ["three", "four"]]
6
+ table(:id => "table_id").to_a.should =~ expected_table
7
+
8
+ * removed strict version requirements for dependencies
9
+
10
+
1
11
  === Version 0.1.0 / 2010-04-03
2
12
 
3
13
  First release of WatiRspec, a small library for combining Watir and RSpec for browser-based functional testing in Ruby.
@@ -1,3 +1,3 @@
1
1
  module WatiRspec
2
- VERSION = "0.1.0" #:nodoc:
2
+ VERSION = "0.1.1"
3
3
  end
@@ -6,8 +6,8 @@ module Watir
6
6
  end
7
7
 
8
8
  # patches for Watir
9
- module Watir #:nodoc:all
10
- class IE
9
+ module Watir
10
+ class IE #:nodoc:all
11
11
  # This is Watir's overriden wait method, which is used in many places for deciding
12
12
  # if browser is ready or not. We have to patch one line in it to work properly
13
13
  # when file save as dialog has been displayed. For some reason READYSTATE (4)
@@ -65,7 +65,7 @@ module Watir #:nodoc:all
65
65
  end
66
66
  end
67
67
 
68
- module PageContainer
68
+ module PageContainer #:nodoc:all
69
69
  # patch for .click_no_wait
70
70
  def eval_in_spawned_process(command)
71
71
  command.strip!
@@ -77,4 +77,45 @@ module Watir #:nodoc:all
77
77
  system(exec_string)
78
78
  end
79
79
  end
80
+
81
+ class Table < Element
82
+
83
+ # This method returns multi-dimensional array of the text's in table.
84
+ #
85
+ # It works with tr, th, td elements, colspan, rowspan and nested tables.
86
+ def to_a
87
+ assert_exists
88
+ y = []
89
+ @o.getElementsByTagName("TR").each do |row|
90
+ # make sure that this row is directly child element of the table
91
+ # and not from some inner table
92
+ next unless row.parentElement.parentElement.uniqueID == @o.uniqueID
93
+
94
+ y << TableRow.new(@container, :ole_object, row).to_a
95
+ end
96
+ y
97
+ end
98
+ end
99
+
100
+ class TableRow < Element
101
+
102
+ # This method returns (multi)-dimensional array of the text's in table row.
103
+ #
104
+ # It works with th, td elements, colspan, rowspan and nested tables.
105
+ def to_a
106
+ assert_exists
107
+ y = []
108
+ @o.cells.each do |cell|
109
+ inner_tables = cell.getElementsByTagName("TABLE")
110
+ inner_tables.each do |inner_table|
111
+ y << Watir::Table.new(@container, :ole_object, inner_table).to_a
112
+ end
113
+
114
+ if inner_tables.length == 0
115
+ y << cell.innerText.strip
116
+ end
117
+ end
118
+ y
119
+ end
120
+ end
80
121
  end
@@ -0,0 +1,40 @@
1
+ require "watirspec"
2
+ require "spec/autorun"
3
+
4
+ describe Watir::TableRow do
5
+ include WatiRspec::SpecHelper
6
+
7
+ before :all do
8
+ goto "http://dl.dropbox.com/u/2731643/misc/tables.html"
9
+ end
10
+
11
+ it "#to_a works with regular row" do
12
+ first_row = table(:id => "normal")[1]
13
+ first_row.to_a.should =~ %w[1 2 3]
14
+ end
15
+
16
+ it "#to_a works with headers in row" do
17
+ first_row = table(:id => "headers")[1]
18
+ first_row.to_a.should =~ %w[1 2 3 4]
19
+ end
20
+
21
+ it "#to_a works with nested tables" do
22
+ second_row = table(:id => "nested")[2]
23
+ second_row.to_a.should =~ [[%w[11 12], %w[13 14]], "3"]
24
+ end
25
+
26
+ it "#to_a works with colspan" do
27
+ second_row = table(:id => "colspan")[2]
28
+ second_row.to_a.should == ["3"]
29
+ end
30
+
31
+ it "#to_a works with rowspan" do
32
+ t = table(:id => "rowspan")
33
+ second_row = t[2]
34
+ second_row.to_a.should == ["3", "4"]
35
+
36
+ third_row = t[3]
37
+ third_row.to_a.should == ["5"]
38
+ end
39
+
40
+ end
@@ -0,0 +1,53 @@
1
+ require "watirspec"
2
+ require "spec/autorun"
3
+
4
+ describe Watir::Table do
5
+ include WatiRspec::SpecHelper
6
+
7
+ before :all do
8
+ goto "http://dl.dropbox.com/u/2731643/misc/tables.html"
9
+ end
10
+
11
+ it "#to_a works with regular table" do
12
+ expected_table = [
13
+ %w[1 2 3],
14
+ %w[4 5 6],
15
+ %w[7 8 9]
16
+ ]
17
+ table(:id => "normal").to_a.should =~ expected_table
18
+ end
19
+
20
+ it "#to_a works with table with headers" do
21
+ expected_table = [
22
+ %w[1 2 3 4],
23
+ %w[5 6 7 8],
24
+ %w[9 10 11 12],
25
+ ]
26
+ table(:id => "headers").to_a.should =~ expected_table
27
+ end
28
+
29
+ it "#to_a works with nested tables" do
30
+ expected_table = [
31
+ %w[1 2],
32
+ [[%w[11 12], %w[13 14]], "3"]
33
+ ]
34
+ table(:id => "nested").to_a.should =~ expected_table
35
+ end
36
+
37
+ it "#to_a works with colspan" do
38
+ expected_table = [
39
+ %w[1 2],
40
+ ["3"]
41
+ ]
42
+ table(:id => "colspan").to_a.should =~ expected_table
43
+ end
44
+
45
+ it "#to_a works with rowspan" do
46
+ expected_table = [
47
+ %w[1 2],
48
+ %w[3 4],
49
+ %w[5]
50
+ ]
51
+ table(:id => "rowspan").to_a.should =~ expected_table
52
+ end
53
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jarmo Pertman
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-03 00:00:00 +03:00
17
+ date: 2010-04-05 00:00:00 +03:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -22,7 +22,7 @@ dependencies:
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - "="
25
+ - - ">="
26
26
  - !ruby/object:Gem::Version
27
27
  segments:
28
28
  - 1
@@ -36,7 +36,7 @@ dependencies:
36
36
  prerelease: false
37
37
  requirement: &id002 !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - "="
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  segments:
42
42
  - 1
@@ -74,13 +74,11 @@ dependencies:
74
74
  prerelease: false
75
75
  requirement: &id005 !ruby/object:Gem::Requirement
76
76
  requirements:
77
- - - "="
77
+ - - ">="
78
78
  - !ruby/object:Gem::Version
79
79
  segments:
80
- - 2
81
- - 12
82
80
  - 0
83
- version: 2.12.0
81
+ version: "0"
84
82
  type: :runtime
85
83
  version_requirements: *id005
86
84
  - !ruby/object:Gem::Dependency
@@ -137,6 +135,8 @@ files:
137
135
  - README.rdoc
138
136
  - spec/spec_helper_spec.rb
139
137
  - spec/util_spec.rb
138
+ - spec/watir_table_row_spec.rb
139
+ - spec/watir_table_spec.rb
140
140
  - templates/common/config.rb
141
141
  - templates/common/environment.rb
142
142
  - templates/common/lib/common_application_helper.rb
@@ -145,7 +145,7 @@ files:
145
145
  - templates/project/environment.rb
146
146
  - templates/project/ide_runner.rb
147
147
  - templates/project/spec/dummy_spec.rb
148
- - watirspec-0.1.0.gem
148
+ - watirspec-0.1.1.gem
149
149
  has_rdoc: true
150
150
  homepage: http://github.com/jarmo/WatiRspec
151
151
  licenses: []
@@ -187,6 +187,6 @@ rubyforge_project:
187
187
  rubygems_version: 1.3.6
188
188
  signing_key:
189
189
  specification_version: 3
190
- summary: watirspec 0.1.0
190
+ summary: watirspec 0.1.1
191
191
  test_files: []
192
192