spec/watirspec/table_spec.rb in watir-webdriver-0.0.9 vs spec/watirspec/table_spec.rb in watir-webdriver-0.1.0

- old
+ new

@@ -39,149 +39,109 @@ it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do lambda { browser.table(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException) end end - describe "#length" do - it "returns the number of rows" do - browser.table(:id, 'outer').rows.length.should == 3 - browser.table(:id, 'inner').rows.length.should == 1 - end - end - # Other - describe "#to_a" do + describe "#strings" do it "returns a two-dimensional array representation of the table" do - browser.table(:id, 'inner').to_a.should == [["Table 2, Row 1, Cell 1", "Table 2, Row 1, Cell 2"]] - end - end + browser.table(:id, 'inner').strings.should == [ + ["Table 2, Row 1, Cell 1", + "Table 2, Row 1, Cell 2"] + ] - describe "#click" do - it "fires the table's onclick event" do - browser.table(:id, 'inner').click - messages.first.should == 'table' + browser.table(:id, 'outer').strings.should == [ + ["Table 1, Row 1, Cell 1", "Table 1, Row 1, Cell 2"], + ["Table 1, Row 2, Cell 1", "Table 1, Row 2, Cell 2 Table 2, Row 1, Cell 1 Table 2, Row 1, Cell 2"], + ["Table 1, Row 3, Cell 1", "Table 1, Row 3, Cell 2"] + ] end end - bug "http://github.com/jarib/watir-webdriver/issues/#issue/2", :webdriver do - describe "#row_count" do - it "counts the number of rows correctly" do - browser.table(:id, 'inner').row_count.should == 1 - browser.table(:id, 'outer').row_count.should == 3 - end - - it "raises an UnknownObjectException if the table doesn't exist" do - lambda { browser.table(:id, 'no_such_id').row_count }.should raise_error(UnknownObjectException) - lambda { browser.table(:index, 1337).row_count }.should raise_error(UnknownObjectException) - end + describe "#hashes" do + it "returns an Array of Hashes for the common table usage" do + browser.table(:id => "axis_example").hashes.should == [ + { "" => "March 2008", "Before income tax" => "", "Income tax" => "", "After income tax" => "" }, + { "" => "Gregory House", "Before income tax" => "5 934", "Income tax" => "1 347", "After income tax" => "4 587" }, + { "" => "Hugh Laurie", "Before income tax" => "6 300", "Income tax" => "1 479", "After income tax" => "4 821" }, + { "" => "April 2008", "Before income tax" => "", "Income tax" => "", "After income tax" => "" }, + { "" => "Gregory House", "Before income tax" => "5 863", "Income tax" => "1 331", "After income tax" => "4 532" }, + { "" => "Hugh Laurie", "Before income tax" => "6 252", "Income tax" => "1 420", "After income tax" => "4 832" }, + { "" => "Sum", "Before income tax" => "24 349", "Income tax" => "5 577", "After income tax" => "18 722"}, + ] end - end - bug "http://github.com/jarib/watir-webdriver/issues/#issue/2", :webdriver do - describe "#row_values" do - it "gets row values" do - browser.table(:id, 'outer').row_values(0).should == ["Table 1, Row 1, Cell 1", "Table 1, Row 1, Cell 2"] - browser.table(:id, 'inner').row_values(0).should == ["Table 2, Row 1, Cell 1", "Table 2, Row 1, Cell 2"] - browser.table(:id, 'outer').row_values(2).should == ["Table 1, Row 3, Cell 1", "Table 1, Row 3, Cell 2"] - end + it "raises an error if the table could not be parsed" do + pending end end - bug "http://github.com/jarib/watir-webdriver/issues/#issue/2", :webdriver do - describe "#column_count" do - it "counts the number of columns correctly" do - browser.table(:id, 'inner').column_count.should == 2 - browser.table(:id, 'outer').column_count.should == 2 - end - - it "raises an UnknownObjectException if the table doesn't exist" do - lambda { browser.table(:id, 'no_such_id').column_count }.should raise_error(UnknownObjectException) - lambda { browser.table(:index, 1337).column_count }.should raise_error(UnknownObjectException) - end + describe "#click" do + it "fires the table's onclick event" do + browser.table(:id, 'inner').click + messages.first.should == 'table' end end - bug "http://github.com/jarib/watir-webdriver/issues/#issue/2", :webdriver do - describe "#column_values" do - it "gets column values" do - browser.table(:id, 'inner').column_values(0).should == ["Table 2, Row 1, Cell 1"] - browser.table(:id, 'outer').column_values(0).should == ["Table 1, Row 1, Cell 1", "Table 1, Row 2, Cell 1", "Table 1, Row 3, Cell 1"] - end - - it "raises UnknownCellException when trying to locate non-existing cell" do - lambda { browser.table(:id, 'inner').column_values(1337) }.should raise_error(UnknownCellException) - end - end - end - describe "#[]" do it "returns the nth child row" do browser.table(:id, 'outer')[0].id.should == "outer_first" browser.table(:id, 'inner')[0].id.should == "inner_first" browser.table(:id, 'outer')[2].id.should == "outer_last" end - - bug "http://github.com/jarib/watir-webdriver/issues/issue/26", :webdriver do + not_compliant_on :webdriver do it "raises UnknownRowException if the index is out of bounds" do lambda { browser.table(:id, 'outer')[1337] }.should raise_error(UnknownRowException) end end end - bug "http://github.com/jarib/watir-webdriver/issues/#issue/2", :webdriver do - describe "#child_row" do - it "returns the nth child row" do - browser.table(:id, 'outer').child_row(0).id.should == "outer_first" - browser.table(:id, 'inner').child_row(0).id.should == "inner_first" - browser.table(:id, 'outer').child_row(2).id.should == "outer_last" - end - it "raises UnknownRowException if the index is out of bounds" do - lambda { browser.table(:id, 'outer').child_row(1337) }.should raise_error(UnknownRowException) - end + describe "#row" do + let(:table) { browser.table(:id, 'outer') } + + it "finds rows belonging to this table" do + table.row(:id => "outer_last").should exist + table.row(:text => /Table 1, Row 1, Cell 1/).should exist end - end - bug "http://github.com/jarib/watir-webdriver/issues/#issue/2", :webdriver do - describe "#child_cell" do - it "returns the nth child row" do - browser.table(:id, 'outer').child_cell(4).text.should == "Table 1, Row 3, Cell 1" - end - it "raises UnknownCellException if the index is out of bounds" do - lambda { browser.table(:id, 'outer').child_cell(1337) }.should raise_error(UnknownCellException) - end + it "does not find rows from a nested table" do + table.row(:id => "inner_first").should_not exist + table.row(:text => /^Table 2, Row 1, Cell 1 Table 2, Row 1, Cell 2$/).should_not exist end end - bug "http://github.com/jarib/watir-webdriver/issues/#issue/2", :webdriver do - describe "#each" do - it "iterates through the table's rows" do - ids = ["outer_first", "outer_second", "outer_last"] - browser.table(:id, 'outer').each_with_index do |r, idx| - r.id.should == ids[idx] - end - end + describe "#rows" do + it "finds the correct number of rows (excluding nested tables)" do + browser.table(:id, 'inner').rows.length.should == 1 + browser.table(:id, 'outer').rows.length.should == 3 end + + it "finds rows matching the selector" do + pending + end + + it "does not find rows from a nested table" do + pending + end end - bug "http://github.com/jarib/watir-webdriver/issues/#issue/2", :webdriver do - describe "#body" do - it "returns the correct instance of TableBody" do - body = browser.table(:index, 0).body(:id, 'first') - body.should be_instance_of(TableBody) - body[0][0].text.should == "March 2008" - end + describe "#tbody" do + it "returns the correct instance of TableSection" do + body = browser.table(:index, 0).tbody(:id, 'first') + body.should be_instance_of(TableSection) + body[0][0].text.should == "March 2008" end end - bug "http://github.com/jarib/watir-webdriver/issues/#issue/2", :webdriver do - describe "#bodies" do - it "returns the correct instance of TableBodies" do - bodies = browser.table(:index, 0).bodies - bodies.should be_instance_of(TableBodies) - bodies[0].id.should == "first" - bodies[1].id.should == "second" - end + describe "#tbodys" do + it "returns the correct instance of TableSection" do + bodies = browser.table(:index, 0).tbodys + + bodies.should be_instance_of(TableSectionCollection) + + bodies[0].id.should == "first" + bodies[1].id.should == "second" end end end