require 'spec_helper' describe Symbiont::WebObjects::SelectList do describe "implementation" do let(:select_list_object) { double('select_list_object') } let(:select_list) { Symbiont::WebObjects::SelectList } let(:select_list_actual) { Symbiont::WebObjects::SelectList.new(select_list_object) } let(:list_opts) { [select_list_object, select_list_object] } before(:each) do select_list_object.stub(:find_elements).and_return(select_list_object) select_list_object.stub(:wd).and_return(select_list_object) select_list_object.stub(:include?) end it "should reference standard usable selectors" do [:class, :id, :name, :index, :xpath].each do |s| locator = select_list.provide_locator_for s => 'value' locator.keys.first.should == s end end it "should register with a select list tag" do ::Symbiont::WebObjects.get_class_for(:select).should == ::Symbiont::WebObjects::SelectList end it "should return an option when indexed" do select_list_object.should_receive(:find_elements).with(:xpath, ".//child::option").and_return(list_opts) select_list_actual[0].should be_instance_of Symbiont::WebObjects::Option end it "should return an array of options" do select_list_object.should_receive(:find_elements).with(:xpath, ".//child::option").and_return(list_opts) select_list_actual.options.size.should == 2 end it "should return an array of selected options" do select_list_object.stub(:selected_options).and_return(list_opts) select_list_object.stub(:text).and_return(select_list_object) select_list_actual.selected_options.should == list_opts end it "should determine if an option is selected" do select_list_object.stub(:selected?).with('testing').and_return(true) select_list_actual.selected?('testing') end it "should determine if an option is available" do select_list_object.stub(:include?).with('testing').and_return(true) select_list_actual.include?('testing') end it "should get the values for any selected options" do select_list_object.stub(:selected_options).and_return(list_opts) select_list_object.stub(:value).and_return(select_list_object) select_list_actual.selected_values.should == list_opts end it "should be able to select an item by value" do select_list_object.should_receive(:select_value).and_return(true) select_list_actual.select_value('testing') end it "should be able to select an item by option" do select_list_object.should_receive(:select).and_return(true) select_list_actual.select('testing') end end end