spec/lib/mohawk/accessors/table_spec.rb in mohawk-0.0.2 vs spec/lib/mohawk/accessors/table_spec.rb in mohawk-0.0.3

- old
+ new

@@ -1,6 +1,7 @@ require 'spec_helper' +require 'ffi' class TableScreen include Mohawk window(:id => nil) @@ -18,10 +19,23 @@ @text = text @row = row end end +module FFI + module Library + def ffi_lib(*names) + end + + def ffi_libraries + end + + def attach_function(name, func, args, returns = nil, options = nil) + end + end +end + describe Mohawk::Accessors::Table do let(:screen) { TableScreen.new } let(:window) { double("RAutomation Window") } let(:table) { double("Table") } @@ -32,46 +46,77 @@ context "working with table controls" do before(:each) do window.should_receive(:table).with(:id => "tableId").and_return(table) end - it "can set a value by index" do + it "can select a row by index" do table.should_receive(:select).with(1) screen.top = 1 end + it "can select a row by value" do + table.should_receive(:select).with "John Elway" + screen.top = "John Elway" + end + it "has rows" do fake_rows = [FakeTableRow.new("First Row", 0), FakeTableRow.new("Second Row", 1)] expected_rows = fake_rows.map {|r| {:text => r.text, :row => r.row} } table.should_receive(:rows).and_return(fake_rows) - expected_rows.should eq(screen.top_rows) + screen.top.map(&:to_hash).should eq(expected_rows) end + it "has headers" do + expected_headers = ["first header", "second header"] + table.should_receive(:search_information).and_return(1234) + RAutomation::Adapter::MsUia::UiaDll.should_receive(:table_headers).with(1234).and_return(expected_headers) + screen.top_headers.should eq(expected_headers) + end + it "can return the raw view" do screen.top_view.should_not be_nil end - describe Mohawk::Accessors::Table::Row do - let(:table_row) { double("RAutomation Table::Row") } + describe Mohawk::Accessors::TableRow do + let(:table_row) { double("RAutomation TableRow") } before(:each) do table.should_receive(:row).with(:index => 0).and_return(table_row) table_row.stub(:row).and_return 0 end it "can get an individual row" do - screen.top_row(0).should_not be_nil + screen.top[0].should_not be_nil end it "knows if it is selected" do table.should_receive(:selected?).with(0).and_return(true) - screen.top_row(0).should be_selected + screen.top[0].should be_selected end + it "can be selected" do + table.should_receive(:select).with(0) + screen.top[0].select + end + it "has cells" do expected_cells = [FakeTableRow.new("Item 1", 0), FakeTableRow.new("Item 2", 1)] table_row.should_receive(:cells).and_return(expected_cells) - screen.top_row(0).cells.should eq expected_cells.map &:text + screen.top[0].cells.should eq expected_cells.map &:text + end + + it "can get cell values by header name" do + RAutomation::Adapter::MsUia::UiaDll.should_receive(:table_headers).and_return(["First Header", "Second Header"]) + table.should_receive(:search_information) + expected_cells = [FakeTableRow.new("Item 1", 0), FakeTableRow.new("Item 2", 1)] + table_row.should_receive(:cells).and_return(expected_cells) + screen.top[0].second_header.should eq("Item 2") + end + + it "clearly lets you know if a header is not there" do + RAutomation::Adapter::MsUia::UiaDll.should_receive(:table_headers).and_return(["First Header", "Second Header"]) + table.should_receive(:search_information) + lambda { screen.top[0].does_not_exist }.should raise_error ArgumentError, "does_not_exist column does not exist in [:first_header, :second_header]" end end end context "aliases for table" do