diff --git a/rb/selenium-webdriver.gemspec b/rb/selenium-webdriver.gemspec index 4a3e0072a7a61..239bc056b0ceb 100644 --- a/rb/selenium-webdriver.gemspec +++ b/rb/selenium-webdriver.gemspec @@ -27,7 +27,7 @@ Gem::Specification.new do |s| s.add_runtime_dependency "childprocess", ["~> 0.5"] s.add_runtime_dependency "websocket", ["~> 1.0"] - s.add_development_dependency "rspec", ["~> 2.99.0"] + s.add_development_dependency "rspec", ["~> 3.0"] s.add_development_dependency "rack", ["~> 1.0"] s.add_development_dependency "ci_reporter", ["~> 1.6", ">= 1.6.2"] s.add_development_dependency "webmock", ["~> 1.7", ">= 1.7.5"] diff --git a/rb/spec/integration/selenium/client/api/backward_compatible_api_spec.rb b/rb/spec/integration/selenium/client/api/backward_compatible_api_spec.rb index 54489f7d633fe..d18315d9fae6f 100644 --- a/rb/spec/integration/selenium/client/api/backward_compatible_api_spec.rb +++ b/rb/spec/integration/selenium/client/api/backward_compatible_api_spec.rb @@ -23,19 +23,19 @@ it "provides legacy driver methods" do page.open "http://localhost:4444/selenium-server/org/openqa/selenium/tests/html/test_click_page1.html" - page.get_title.should eql("Click Page 1") - page.get_text("link").index("Click here for next page").should_not be_nil + expect(page.get_title).to eql("Click Page 1") + expect(page.get_text("link").index("Click here for next page")).not_to be_nil links = page.get_all_links - links.length.should > 3 - links[3].should eql("linkToAnchorOnThisPage") + expect(links.length).to be > 3 + expect(links[3]).to eql("linkToAnchorOnThisPage") page.click "link" page.wait_for_page_to_load 5000 - page.get_location.should =~ %r"/selenium-server/org/openqa/selenium/tests/html/test_click_page2.html" + expect(page.get_location).to match(%r"/selenium-server/org/openqa/selenium/tests/html/test_click_page2.html") page.click "previousPage" page.wait_for_page_to_load 5000 - page.get_location.should =~ %r"/selenium-server/org/openqa/selenium/tests/html/test_click_page1.html" + expect(page.get_location).to match(%r"/selenium-server/org/openqa/selenium/tests/html/test_click_page1.html") end end diff --git a/rb/spec/integration/selenium/client/api/click_spec.rb b/rb/spec/integration/selenium/client/api/click_spec.rb index 61f2ec13ccb86..cee9e3851729f 100644 --- a/rb/spec/integration/selenium/client/api/click_spec.rb +++ b/rb/spec/integration/selenium/client/api/click_spec.rb @@ -22,37 +22,37 @@ describe "Click Instrumentation" do it "clicks" do page.open "http://localhost:4444/selenium-server/org/openqa/selenium/tests/html/test_click_page1.html" - page.text_content("link").should eql("Click here for next page") + expect(page.text_content("link")).to eql("Click here for next page") page.click "link", :wait_for => :page - page.title.should eql("Click Page Target") + expect(page.title).to eql("Click Page Target") page.click "previousPage", :wait_for => :page - page.title.should eql("Click Page 1") + expect(page.title).to eql("Click Page 1") page.click "linkWithEnclosedImage", :wait_for => :page - page.title.should eql("Click Page Target") + expect(page.title).to eql("Click Page Target") page.click "previousPage", :wait_for => :page page.click "enclosedImage", :wait_for => :page - page.title.should eql("Click Page Target") + expect(page.title).to eql("Click Page Target") page.click "previousPage", :wait_for => :page page.click "extraEnclosedImage", :wait_for => :page - page.title.should eql("Click Page Target") + expect(page.title).to eql("Click Page Target") page.click "previousPage", :wait_for => :page page.click "linkToAnchorOnThisPage" - page.title.should eql("Click Page 1") + expect(page.title).to eql("Click Page 1") page.click "linkWithOnclickReturnsFalse" - page.title.should eql("Click Page 1") + expect(page.title).to eql("Click Page 1") end it "double clicks" do page.open "http://localhost:4444/selenium-server/org/openqa/selenium/tests/html/test_click_page1.html" page.double_click "doubleClickable" - page.get_alert.should eql("double clicked!") + expect(page.get_alert).to eql("double clicked!") end end diff --git a/rb/spec/integration/selenium/client/api/cookie_spec.rb b/rb/spec/integration/selenium/client/api/cookie_spec.rb index c336d94b507ca..227b098864515 100644 --- a/rb/spec/integration/selenium/client/api/cookie_spec.rb +++ b/rb/spec/integration/selenium/client/api/cookie_spec.rb @@ -24,12 +24,12 @@ page.open "http://localhost:4444/selenium-server/org/openqa/selenium/tests/html/path1/cookie1.html" page.delete_all_visible_cookies - page.cookies.should be_empty + expect(page.cookies).to be_empty page.open "http://localhost:4444/selenium-server/org/openqa/selenium/tests/html/path2/cookie2.html" page.delete_all_visible_cookies - page.cookies.should be_empty + expect(page.cookies).to be_empty end it "can set cookies" do @@ -37,22 +37,22 @@ page.create_cookie "addedCookieForPath1=new value1" page.create_cookie "addedCookieForPath2=new value2", :path => "/selenium-server/org/openqa/selenium/tests/html/path2/", :max_age => 60 page.open "http://localhost:4444/selenium-server/org/openqa/selenium/tests/html/path1/cookie1.html" - page.cookies.should =~ /addedCookieForPath1=new value1/ + expect(page.cookies).to match(/addedCookieForPath1=new value1/) - page.cookie?("addedCookieForPath1").should be true - page.cookie("addedCookieForPath1").should eql("new value1") - page.cookie?("testCookie").should be false - page.cookie?("addedCookieForPath2").should be false + expect(page.cookie?("addedCookieForPath1")).to be true + expect(page.cookie("addedCookieForPath1")).to eql("new value1") + expect(page.cookie?("testCookie")).to be false + expect(page.cookie?("addedCookieForPath2")).to be false page.delete_cookie "addedCookieForPath1", "/selenium-server/org/openqa/selenium/tests/html/path1/" - page.cookies.should be_empty + expect(page.cookies).to be_empty page.open "http://localhost:4444/selenium-server/org/openqa/selenium/tests/html/path2/cookie2.html" - page.cookie("addedCookieForPath2").should eql("new value2") - page.cookie?("addedCookieForPath1").should be false + expect(page.cookie("addedCookieForPath2")).to eql("new value2") + expect(page.cookie?("addedCookieForPath1")).to be false page.delete_cookie "addedCookieForPath2", "/selenium-server/org/openqa/selenium/tests/html/path2/" page.delete_cookie "addedCookieForPath2" - page.cookies.should be_empty + expect(page.cookies).to be_empty end end diff --git a/rb/spec/integration/selenium/client/api/element_spec.rb b/rb/spec/integration/selenium/client/api/element_spec.rb index acedd7620e29f..a6396b7f91ba3 100644 --- a/rb/spec/integration/selenium/client/api/element_spec.rb +++ b/rb/spec/integration/selenium/client/api/element_spec.rb @@ -22,12 +22,12 @@ describe "Element API" do it "can detect element presence" do page.open "http://localhost:4444/selenium-server/org/openqa/selenium/tests/html/test_element_present.html" - page.element?('aLink').should be true + expect(page.element?('aLink')).to be true page.click 'removeLinkAfterAWhile', :wait_for => :no_element, :element => "aLink" - page.element?('aLink').should be false + expect(page.element?('aLink')).to be false page.click 'addLinkAfterAWhile', :wait_for => :element, :element => "aLink" - page.element?('aLink').should be true + expect(page.element?('aLink')).to be true end end diff --git a/rb/spec/integration/selenium/client/api/highlight_located_element_spec.rb b/rb/spec/integration/selenium/client/api/highlight_located_element_spec.rb index b58235c4ca1c3..2660d565734de 100644 --- a/rb/spec/integration/selenium/client/api/highlight_located_element_spec.rb +++ b/rb/spec/integration/selenium/client/api/highlight_located_element_spec.rb @@ -25,12 +25,12 @@ page.execution_delay = 1000 page.highlight_located_element = true begin - page.text("calculator-result").should be_empty + expect(page.text("calculator-result")).to be_empty page.type "calculator-expression", "2 + 2" page.click "calculator-button" , :wait_for => :ajax, :javascript_framework => :jquery - page.value("calculator-result").should eql("4") + expect(page.value("calculator-result")).to eql("4") ensure page.highlight_located_element = false end diff --git a/rb/spec/integration/selenium/client/api/screenshot_spec.rb b/rb/spec/integration/selenium/client/api/screenshot_spec.rb index 16bf5dc2f78ba..b3d9d0d036b62 100644 --- a/rb/spec/integration/selenium/client/api/screenshot_spec.rb +++ b/rb/spec/integration/selenium/client/api/screenshot_spec.rb @@ -22,7 +22,7 @@ describe "Screenshot" do it "can capture html for current page" do page.open "http://localhost:4444/selenium-server/org/openqa/selenium/tests/html/test_click_page1.html" - page.get_html_source.should =~ // + expect(page.get_html_source).to match(//) end # Raising Java Error on Windows @@ -32,10 +32,10 @@ page.open "http://localhost:4444/selenium-server/org/openqa/selenium/tests/html/test_click_page1.html" page.capture_screenshot tempfile - File.exists?(tempfile).should be true + expect(File.exists?(tempfile)).to be true File.open(tempfile, "rb") do |io| magic = io.read(4) - magic.should == "\211PNG" + expect(magic).to eq("\211PNG") end end @@ -45,6 +45,6 @@ encodedImage = page.capture_screenshot_to_string pngImage = Base64.decode64(encodedImage) - pngImage.should =~ /^\211PNG/n + expect(pngImage).to match(/^\211PNG/n) end end diff --git a/rb/spec/integration/selenium/client/api/select_window_spec.rb b/rb/spec/integration/selenium/client/api/select_window_spec.rb index a07c24c64c17f..1875482c8a04b 100644 --- a/rb/spec/integration/selenium/client/api/select_window_spec.rb +++ b/rb/spec/integration/selenium/client/api/select_window_spec.rb @@ -24,20 +24,20 @@ page.open "http://localhost:4444/selenium-server/org/openqa/selenium/tests/html/test_select_window.html" page.click "popupPage", :wait_for => :popup, :window => "myPopupWindow", :select => true - page.location.should =~ %r{/tests/html/test_select_window_popup.html} - page.title.should =~ /Select Window Popup/ - page.all_window_names.size.should eql(2) - page.all_window_names.include?("myPopupWindow").should be true + expect(page.location).to match(%r{/tests/html/test_select_window_popup.html}) + expect(page.title).to match(/Select Window Popup/) + expect(page.all_window_names.size).to eql(2) + expect(page.all_window_names.include?("myPopupWindow")).to be true page.close page.select_window "null" - page.location.should =~ %r{/tests/html/test_select_window.html} + expect(page.location).to match(%r{/tests/html/test_select_window.html}) page.click "popupPage", :wait_for => :popup, :window => "myPopupWindow" page.select_window "title=Select Window Popup" - page.location.should =~ %r{/tests/html/test_select_window_popup.html} + expect(page.location).to match(%r{/tests/html/test_select_window_popup.html}) page.close page.select_window "null" @@ -47,7 +47,7 @@ page.open "http://localhost:4444/selenium-server/org/openqa/selenium/tests/html/test_select_window.html" page.click "popupAnonymous", :wait_for => :popup, :window => "anonymouspopup", :select => true - page.location.should =~ %r{/tests/html/test_select_window_popup.html} + expect(page.location).to match(%r{/tests/html/test_select_window_popup.html}) page.click "closePage" page.select_window "null" @@ -57,7 +57,7 @@ page.open "http://localhost:4444/selenium-server/org/openqa/selenium/tests/html/test_select_window.html" page.click "popupAnonymous", :wait_for => :popup, :window => "anonymouspopup", :select => true - page.location.should =~ %r{/tests/html/test_select_window_popup.html} + expect(page.location).to match(%r{/tests/html/test_select_window_popup.html}) page.click "closePage2" page.select_window "null" diff --git a/rb/spec/integration/selenium/client/api/wait_for_ajax_spec.rb b/rb/spec/integration/selenium/client/api/wait_for_ajax_spec.rb index 057e6daf27180..6ef3088444940 100644 --- a/rb/spec/integration/selenium/client/api/wait_for_ajax_spec.rb +++ b/rb/spec/integration/selenium/client/api/wait_for_ajax_spec.rb @@ -23,11 +23,11 @@ describe "Prototype" do it "blocks until AJAX request is complete" do page.open "http://localhost:4567/prototype.html" - page.text("calculator-result").should be_empty + expect(page.text("calculator-result")).to be_empty page.type "calculator-expression", "2 + 2" page.click "calculator-button", :wait_for => :ajax - page.value("calculator-result").should eql("4") + expect(page.value("calculator-result")).to eql("4") end end @@ -35,12 +35,12 @@ it "blocks until AJAX request is complete" do page.open "http://localhost:4567/jquery.html" - page.text("calculator-result").should be_empty + expect(page.text("calculator-result")).to be_empty page.type "calculator-expression", "2 + 2" page.click "calculator-button" , :wait_for => :ajax, :javascript_framework => :jquery - page.value("calculator-result").should eql("4") + expect(page.value("calculator-result")).to eql("4") end end end diff --git a/rb/spec/integration/selenium/client/api/wait_for_field_value_spec.rb b/rb/spec/integration/selenium/client/api/wait_for_field_value_spec.rb index 484b17d650d13..cb0140e09bc14 100644 --- a/rb/spec/integration/selenium/client/api/wait_for_field_value_spec.rb +++ b/rb/spec/integration/selenium/client/api/wait_for_field_value_spec.rb @@ -23,21 +23,21 @@ it "blocks until field is updated" do page.open "http://localhost:4567/jquery.html" - page.text("calculator-result").should be_empty + expect(page.text("calculator-result")).to be_empty page.type "calculator-expression", "2 + 2" page.click "calculator-button", :wait_for => :value, :element => "calculator-result", :value => "4" - page.value("calculator-result").should eql("4") + expect(page.value("calculator-result")).to eql("4") end it "times out when field is never properly updated" do page.open "http://localhost:4567/jquery.html" - page.text("calculator-result").should be_empty + expect(page.text("calculator-result")).to be_empty page.type "calculator-expression", "2 + 2" should_timeout do @@ -53,13 +53,13 @@ it "blocks until field is updated" do page.open "http://localhost:4567/jquery.html" - page.text("calculator-result").should be_empty + expect(page.text("calculator-result")).to be_empty page.type "calculator-expression", "2 + 2" page.click "calculator-button", :wait_for => :no_value, :element => "calculator-result", :value => "" - page.value("calculator-result").should eql("4") + expect(page.value("calculator-result")).to eql("4") end it "times out when field is never properly updated" do diff --git a/rb/spec/integration/selenium/client/api/webdriver_backed_spec.rb b/rb/spec/integration/selenium/client/api/webdriver_backed_spec.rb index 2a9be0ef1cbf3..88ec81f18d4ce 100644 --- a/rb/spec/integration/selenium/client/api/webdriver_backed_spec.rb +++ b/rb/spec/integration/selenium/client/api/webdriver_backed_spec.rb @@ -35,6 +35,6 @@ selenium.start :driver => webdriver selenium.open '/' - selenium.title.should == webdriver.title + expect(selenium.title).to eq(webdriver.title) end end diff --git a/rb/spec/integration/selenium/webdriver/app_cache_spec.rb b/rb/spec/integration/selenium/webdriver/app_cache_spec.rb index f2129f8965ee5..e0c04dd20ae7c 100644 --- a/rb/spec/integration/selenium/webdriver/app_cache_spec.rb +++ b/rb/spec/integration/selenium/webdriver/app_cache_spec.rb @@ -25,12 +25,12 @@ module Selenium::WebDriver::DriverExtensions compliant_on :browser => nil do it "gets the app cache status" do - driver.application_cache.status.should == :uncached + expect(driver.application_cache.status).to eq(:uncached) driver.online = false driver.navigate.to url_for("html5Page.html") - browser.application_cache.status.should == :idle + expect(browser.application_cache.status).to eq(:idle) end it "loads from cache when offline" do @@ -40,7 +40,7 @@ module Selenium::WebDriver::DriverExtensions driver.online = false driver.get url_for("html5Page.html") - driver.title.should == "HTML5" + expect(driver.title).to eq("HTML5") end it "gets the app cache entries" do @@ -49,14 +49,14 @@ module Selenium::WebDriver::DriverExtensions driver.get url_for("html5Page") entries = driver.application_cache.to_a - entries.size.should > 2 + expect(entries.size).to be > 2 entries.each do |e| case e.url when /red\.jpg/ - e.type.value.should == :master + expect(e.type.value).to eq(:master) when /yellow\.jpg/ - e.type.value.should == :explicit + expect(e.type.value).to eq(:explicit) end end end diff --git a/rb/spec/integration/selenium/webdriver/chrome/driver_spec.rb b/rb/spec/integration/selenium/webdriver/chrome/driver_spec.rb index f90b1486be023..49e872b853aec 100644 --- a/rb/spec/integration/selenium/webdriver/chrome/driver_spec.rb +++ b/rb/spec/integration/selenium/webdriver/chrome/driver_spec.rb @@ -28,16 +28,16 @@ module Chrome driver.navigate.to url_for("click_jacker.html") ua = driver.execute_script "return window.navigator.userAgent" - ua.should == "foo;bar" + expect(ua).to eq("foo;bar") ensure driver.quit if driver end end it "should raise ArgumentError if :args is not an Array" do - lambda { + expect { Selenium::WebDriver.for(:chrome, :args => "--foo") - }.should raise_error(ArgumentError) + }.to raise_error(ArgumentError) end end diff --git a/rb/spec/integration/selenium/webdriver/chrome/profile_spec.rb b/rb/spec/integration/selenium/webdriver/chrome/profile_spec.rb index dafecc7f72c4d..35fe6c3733c4f 100755 --- a/rb/spec/integration/selenium/webdriver/chrome/profile_spec.rb +++ b/rb/spec/integration/selenium/webdriver/chrome/profile_spec.rb @@ -40,39 +40,39 @@ module Chrome profile['foo.boolean'] = true new_profile = Profile.from_json(profile.to_json) - new_profile['foo.boolean'].should be true + expect(new_profile['foo.boolean']).to be true end it "adds an extension" do ext_path = "/some/path.crx" - File.should_receive(:file?).with(ext_path).and_return true - profile.add_extension(ext_path).should == [ext_path] + expect(File).to receive(:file?).with(ext_path).and_return true + expect(profile.add_extension(ext_path)).to eq([ext_path]) end it "reads an extension as binary data" do ext_path = "/some/path.crx" - File.should_receive(:file?).with(ext_path).and_return true + expect(File).to receive(:file?).with(ext_path).and_return true profile.add_extension(ext_path) ext_file = double('file') - File.should_receive(:open).with(ext_path, "rb").and_yield ext_file - ext_file.should_receive(:read).and_return "test" + expect(File).to receive(:open).with(ext_path, "rb").and_yield ext_file + expect(ext_file).to receive(:read).and_return "test" - profile.should_receive(:layout_on_disk).and_return "ignored" - Zipper.should_receive(:zip).and_return "ignored" + expect(profile).to receive(:layout_on_disk).and_return "ignored" + expect(Zipper).to receive(:zip).and_return "ignored" - profile.as_json().should == { + expect(profile.as_json()).to eq({ 'zip' => "ignored", 'extensions' => [Base64.strict_encode64("test")] - } + }) end it "raises an error if the extension doesn't exist" do - lambda { + expect { profile.add_extension("/not/likely/to/exist.crx") - }.should raise_error + }.to raise_error end end diff --git a/rb/spec/integration/selenium/webdriver/driver_spec.rb b/rb/spec/integration/selenium/webdriver/driver_spec.rb index 0fae2e4f8efa7..351e14fe8c033 100644 --- a/rb/spec/integration/selenium/webdriver/driver_spec.rb +++ b/rb/spec/integration/selenium/webdriver/driver_spec.rb @@ -22,14 +22,14 @@ describe "Driver" do it "should get the page title" do driver.navigate.to url_for("xhtmlTest.html") - driver.title.should == "XHTML Test Page" + expect(driver.title).to eq("XHTML Test Page") end # Edge does not yet support session/:sessionId/source http://dev.modern.ie/platform/status/webdriver/details/ not_compliant_on :browser => :edge do it "should get the page source" do driver.navigate.to url_for("xhtmlTest.html") - driver.page_source.should match(%r[XHTML Test Page]i) + expect(driver.page_source).to match(%r[XHTML Test Page]i) end end @@ -37,9 +37,9 @@ it "should refresh the page" do driver.navigate.to url_for("javascriptPage.html") driver.find_element(:id, 'updatediv').click - driver.find_element(:id, 'dynamo').text.should == "Fish and chips!" + expect(driver.find_element(:id, 'dynamo').text).to eq("Fish and chips!") driver.navigate.refresh - driver.find_element(:id, 'dynamo').text.should == "What's for dinner?" + expect(driver.find_element(:id, 'dynamo').text).to eq("What's for dinner?") end end @@ -50,8 +50,8 @@ begin driver.save_screenshot path - File.exist?(path).should be true # sic - File.size(path).should > 0 + expect(File.exist?(path)).to be true # sic + expect(File.size(path)).to be > 0 ensure File.delete(path) if File.exist?(path) end @@ -61,12 +61,12 @@ driver.navigate.to url_for("xhtmlTest.html") ss = driver.screenshot_as(:png) - ss.should be_kind_of(String) - ss.size.should > 0 + expect(ss).to be_kind_of(String) + expect(ss.size).to be > 0 end it "raises an error when given an unknown format" do - lambda { driver.screenshot_as(:jpeg) }.should raise_error(WebDriver::Error::UnsupportedOperationError) + expect { driver.screenshot_as(:jpeg) }.to raise_error(WebDriver::Error::UnsupportedOperationError) end end @@ -74,41 +74,41 @@ it "should find by id" do driver.navigate.to url_for("xhtmlTest.html") element = driver.find_element(:id, "id1") - element.should be_kind_of(WebDriver::Element) - element.text.should == "Foo" + expect(element).to be_kind_of(WebDriver::Element) + expect(element.text).to eq("Foo") end it "should find by field name" do driver.navigate.to url_for("formPage.html") - driver.find_element(:name, "x").attribute('value').should == "name" + expect(driver.find_element(:name, "x").attribute('value')).to eq("name") end it "should find by class name" do driver.navigate.to url_for("xhtmlTest.html") - driver.find_element(:class, "header").text.should == "XHTML Might Be The Future" + expect(driver.find_element(:class, "header").text).to eq("XHTML Might Be The Future") end it "should find by link text" do driver.navigate.to url_for("xhtmlTest.html") - driver.find_element(:link, "Foo").text.should == "Foo" + expect(driver.find_element(:link, "Foo").text).to eq("Foo") end # Edge does not yet support xpath not_compliant_on :browser => :edge do it "should find by xpath" do driver.navigate.to url_for("xhtmlTest.html") - driver.find_element(:xpath, "//h1").text.should == "XHTML Might Be The Future" + expect(driver.find_element(:xpath, "//h1").text).to eq("XHTML Might Be The Future") end end it "should find by css selector" do driver.navigate.to url_for("xhtmlTest.html") - driver.find_element(:css, "div.content").attribute("class").should == "content" + expect(driver.find_element(:css, "div.content").attribute("class")).to eq("content") end it "should find by tag name" do driver.navigate.to url_for("xhtmlTest.html") - driver.find_element(:tag_name, 'div').attribute("class").should == "navigation" + expect(driver.find_element(:tag_name, 'div').attribute("class")).to eq("navigation") end # Edge does not yet support session/:sessionId/element/:id/element @@ -120,7 +120,7 @@ element = driver.find_element(:name, "form2") child = element.find_element(:name, "selectomatic") - child.attribute("id").should == "2" + expect(child.attribute("id")).to eq("2") end end @@ -133,18 +133,18 @@ element = driver.find_element(:name, "form2") child = element.find_element(:tag_name, "select") - child.attribute("id").should == "2" + expect(child.attribute("id")).to eq("2") end end it "should raise on nonexistant element" do driver.navigate.to url_for("xhtmlTest.html") - lambda { driver.find_element("nonexistant") }.should raise_error + expect { driver.find_element("nonexistant") }.to raise_error end it "should find elements with a hash selector" do driver.navigate.to url_for("xhtmlTest.html") - driver.find_element(:class => "header").text.should == "XHTML Might Be The Future" + expect(driver.find_element(:class => "header").text).to eq("XHTML Might Be The Future") end # Edge does not yet support xpath @@ -152,8 +152,8 @@ it "should find elements with the shortcut syntax" do driver.navigate.to url_for("xhtmlTest.html") - driver[:id1].should be_kind_of(WebDriver::Element) - driver[:xpath => "//h1"].should be_kind_of(WebDriver::Element) + expect(driver[:id1]).to be_kind_of(WebDriver::Element) + expect(driver[:xpath => "//h1"]).to be_kind_of(WebDriver::Element) end end end @@ -186,19 +186,19 @@ describe "execute script" do it "should return strings" do driver.navigate.to url_for("xhtmlTest.html") - driver.execute_script("return document.title;").should == "XHTML Test Page" + expect(driver.execute_script("return document.title;")).to eq("XHTML Test Page") end it "should return numbers" do driver.navigate.to url_for("xhtmlTest.html") - driver.execute_script("return document.title.length;").should == "XHTML Test Page".length + expect(driver.execute_script("return document.title.length;")).to eq("XHTML Test Page".length) end it "should return elements" do driver.navigate.to url_for("xhtmlTest.html") element = driver.execute_script("return document.getElementById('id1');") - element.should be_kind_of(WebDriver::Element) - element.text.should == "Foo" + expect(element).to be_kind_of(WebDriver::Element) + expect(element.text).to eq("Foo") end not_compliant_on :browser => [:android] do @@ -213,67 +213,67 @@ }; SCRIPT - result.should be_kind_of(Hash) - result['elements']['body'].should be_kind_of(WebDriver::Element) - result['elements']['other'].first.should be_kind_of(WebDriver::Element) + expect(result).to be_kind_of(Hash) + expect(result['elements']['body']).to be_kind_of(WebDriver::Element) + expect(result['elements']['other'].first).to be_kind_of(WebDriver::Element) end end it "should return booleans" do driver.navigate.to url_for("xhtmlTest.html") - driver.execute_script("return true;").should == true + expect(driver.execute_script("return true;")).to eq(true) end it "should raise if the script is bad" do driver.navigate.to url_for("xhtmlTest.html") - lambda { driver.execute_script("return squiggle();") }.should raise_error + expect { driver.execute_script("return squiggle();") }.to raise_error end it "should return arrays" do driver.navigate.to url_for("xhtmlTest.html") - driver.execute_script('return ["zero", "one", "two"];').should == %w[zero one two] + expect(driver.execute_script('return ["zero", "one", "two"];')).to eq(%w[zero one two]) end it "should be able to call functions on the page" do driver.navigate.to url_for("javascriptPage.html") driver.execute_script("displayMessage('I like cheese');") - driver.find_element(:id, "result").text.strip.should == "I like cheese" + expect(driver.find_element(:id, "result").text.strip).to eq("I like cheese") end it "should be able to pass string arguments" do driver.navigate.to url_for("javascriptPage.html") - driver.execute_script("return arguments[0] == 'fish' ? 'fish' : 'not fish';", "fish").should == "fish" + expect(driver.execute_script("return arguments[0] == 'fish' ? 'fish' : 'not fish';", "fish")).to eq("fish") end it "should be able to pass boolean arguments" do driver.navigate.to url_for("javascriptPage.html") - driver.execute_script("return arguments[0] == true;", true).should == true + expect(driver.execute_script("return arguments[0] == true;", true)).to eq(true) end it "should be able to pass numeric arguments" do driver.navigate.to url_for("javascriptPage.html") - driver.execute_script("return arguments[0] == 1 ? 1 : 0;", 1).should == 1 + expect(driver.execute_script("return arguments[0] == 1 ? 1 : 0;", 1)).to eq(1) end it "should be able to pass null arguments" do driver.navigate.to url_for("javascriptPage.html") - driver.execute_script("return arguments[0];", nil).should == nil + expect(driver.execute_script("return arguments[0];", nil)).to eq(nil) end it "should be able to pass array arguments" do driver.navigate.to url_for("javascriptPage.html") - driver.execute_script("return arguments[0];", [1, '2', 3]).should == [1, '2', 3] + expect(driver.execute_script("return arguments[0];", [1, '2', 3])).to eq([1, '2', 3]) end it "should be able to pass element arguments" do driver.navigate.to url_for("javascriptPage.html") button = driver.find_element(:id, "plainButton") - driver.execute_script("arguments[0]['flibble'] = arguments[0].getAttribute('id'); return arguments[0]['flibble'];", button).should == "plainButton" + expect(driver.execute_script("arguments[0]['flibble'] = arguments[0].getAttribute('id'); return arguments[0]['flibble'];", button)).to eq("plainButton") end it "should be able to pass in multiple arguments" do driver.navigate.to url_for("javascriptPage.html") - driver.execute_script("return arguments[0] + arguments[1];", "one", "two").should == "onetwo" + expect(driver.execute_script("return arguments[0] + arguments[1];", "one", "two")).to eq("onetwo") end end end @@ -288,19 +288,19 @@ it "should be able to return arrays of primitives from async scripts" do result = driver.execute_async_script "arguments[arguments.length - 1]([null, 123, 'abc', true, false]);" - result.should == [nil, 123, 'abc', true, false] + expect(result).to eq([nil, 123, 'abc', true, false]) end it "should be able to pass multiple arguments to async scripts" do result = driver.execute_async_script "arguments[arguments.length - 1](arguments[0] + arguments[1]);", 1, 2 - result.should == 3 + expect(result).to eq(3) end it "times out if the callback is not invoked" do - lambda { + expect { # Script is expected to be async and explicitly callback, so this should timeout. driver.execute_async_script "return 1 + 2;" - }.should raise_error(Selenium::WebDriver::Error::ScriptTimeOutError) + }.to raise_error(Selenium::WebDriver::Error::ScriptTimeOutError) end end end diff --git a/rb/spec/integration/selenium/webdriver/element_spec.rb b/rb/spec/integration/selenium/webdriver/element_spec.rb index ae74f6b1d9c3e..47834923aba19 100644 --- a/rb/spec/integration/selenium/webdriver/element_spec.rb +++ b/rb/spec/integration/selenium/webdriver/element_spec.rb @@ -46,7 +46,7 @@ key_reporter = driver.find_element(:id, 'keyReporter') key_reporter.send_keys("Tet", :arrow_left, "s") - key_reporter.attribute('value').should == "Test" + expect(key_reporter.attribute('value')).to eq("Test") end end @@ -56,7 +56,7 @@ driver.navigate.to url_for("formPage.html") element = driver.find_element(:id, 'upload') - element.attribute('value').should be_empty + expect(element.attribute('value')).to be_empty file = Tempfile.new('file-upload') path = file.path @@ -64,19 +64,19 @@ element.send_keys path - element.attribute('value').should include(File.basename(path)) + expect(element.attribute('value')).to include(File.basename(path)) end end it "should get attribute value" do driver.navigate.to url_for("formPage.html") - driver.find_element(:id, "withText").attribute("rows").should == "5" + expect(driver.find_element(:id, "withText").attribute("rows")).to eq("5") end not_compliant_on :browser => :edge do it "should return nil for non-existent attributes" do driver.navigate.to url_for("formPage.html") - driver.find_element(:id, "withText").attribute("nonexistent").should be_nil + expect(driver.find_element(:id, "withText").attribute("nonexistent")).to be_nil end end @@ -94,29 +94,29 @@ cheese.click - cheese.should be_selected - peas.should_not be_selected + expect(cheese).to be_selected + expect(peas).not_to be_selected peas.click - peas.should be_selected - cheese.should_not be_selected + expect(peas).to be_selected + expect(cheese).not_to be_selected end end it "should get enabled" do driver.navigate.to url_for("formPage.html") - driver.find_element(:id, "notWorking").should_not be_enabled + expect(driver.find_element(:id, "notWorking")).not_to be_enabled end it "should get text" do driver.navigate.to url_for("xhtmlTest.html") - driver.find_element(:class, "header").text.should == "XHTML Might Be The Future" + expect(driver.find_element(:class, "header").text).to eq("XHTML Might Be The Future") end it "should get displayed" do driver.navigate.to url_for("xhtmlTest.html") - driver.find_element(:class, "header").should be_displayed + expect(driver.find_element(:class, "header")).to be_displayed end # Edge does not yet support /session/:sessionId/element/:id/location @@ -126,8 +126,8 @@ driver.navigate.to url_for("xhtmlTest.html") loc = driver.find_element(:class, "header").location - loc.x.should >= 1 - loc.y.should >= 1 + expect(loc.x).to be >= 1 + expect(loc.y).to be >= 1 end end @@ -138,8 +138,8 @@ driver.navigate.to url_for("javascriptPage.html") loc = driver.find_element(:id, 'keyUp').location_once_scrolled_into_view - loc.x.should >= 1 - loc.y.should >= 0 # can be 0 if scrolled to the top + expect(loc.x).to be >= 1 + expect(loc.y).to be >= 0 # can be 0 if scrolled to the top end end @@ -150,8 +150,8 @@ driver.navigate.to url_for("xhtmlTest.html") size = driver.find_element(:class, "header").size - size.width.should > 0 - size.height.should > 0 + expect(size.width).to be > 0 + expect(size.height).to be > 0 end end @@ -166,7 +166,7 @@ drag_and_drop(img2, img1). perform - img1.location.should == img2.location + expect(img1.location).to eq(img2.location) end end @@ -179,7 +179,7 @@ style2 = element.style("background-color") # backwards compatibility acceptable = ["rgb(0, 128, 0)", "#008000", 'rgba(0,128,0,1)', 'rgba(0, 128, 0, 1)'] - acceptable.should include(style1, style2) + expect(acceptable).to include(style1, style2) end end @@ -191,8 +191,8 @@ body = driver.find_element(:tag_name, 'body') xbody = driver.find_element(:xpath, "//body") - body.should == xbody - body.should eql(xbody) + expect(body).to eq(xbody) + expect(body).to eql(xbody) end end @@ -204,8 +204,8 @@ p1 = elements.fetch(0) p2 = elements.fetch(1) - p1.should_not == p2 - p1.should_not eql(p2) + expect(p1).not_to eq(p2) + expect(p1).not_to eql(p2) end end @@ -217,7 +217,7 @@ body = driver.find_element(:tag_name, 'body') xbody = driver.find_element(:xpath, "//body") - body.hash.should == xbody.hash + expect(body.hash).to eq(xbody.hash) end end @@ -229,7 +229,7 @@ body = driver.find_elements(:tag_name, 'body').fetch(0) xbody = driver.find_elements(:xpath, "//body").fetch(0) - body.hash.should == xbody.hash + expect(body.hash).to eq(xbody.hash) end end diff --git a/rb/spec/integration/selenium/webdriver/error_spec.rb b/rb/spec/integration/selenium/webdriver/error_spec.rb index e2428999a406d..a050f65caa076 100644 --- a/rb/spec/integration/selenium/webdriver/error_spec.rb +++ b/rb/spec/integration/selenium/webdriver/error_spec.rb @@ -24,9 +24,9 @@ it "should raise an appropriate error" do driver.navigate.to url_for("xhtmlTest.html") - lambda { + expect { driver.find_element(:id, "nonexistant") - }.should raise_error(WebDriver::Error::NoSuchElementError) + }.to raise_error(WebDriver::Error::NoSuchElementError) end compliant_on :driver => [:remote, :firefox] do @@ -42,8 +42,8 @@ rescued = true end - rescued.should be true - ex.backtrace.first.should include("[remote server]") + expect(rescued).to be true + expect(ex.backtrace.first).to include("[remote server]") end end end diff --git a/rb/spec/integration/selenium/webdriver/firefox/profile_spec.rb b/rb/spec/integration/selenium/webdriver/firefox/profile_spec.rb index 309146a163757..75b342c60cc50 100644 --- a/rb/spec/integration/selenium/webdriver/firefox/profile_spec.rb +++ b/rb/spec/integration/selenium/webdriver/firefox/profile_spec.rb @@ -39,9 +39,9 @@ def read_generated_prefs(from = nil) profile['foo.string'] = "bar" string = read_generated_prefs - string.should include('user_pref("foo.number", 123)') - string.should include('user_pref("foo.boolean", true)') - string.should include(%{user_pref("foo.string", "bar")}) + expect(string).to include('user_pref("foo.number", 123)') + expect(string).to include('user_pref("foo.boolean", true)') + expect(string).to include(%{user_pref("foo.string", "bar")}) end it "should be serializable to JSON" do @@ -49,57 +49,57 @@ def read_generated_prefs(from = nil) new_profile = Profile.from_json(profile.to_json) string = read_generated_prefs(new_profile) - string.should include('user_pref("foo.boolean", true)') + expect(string).to include('user_pref("foo.boolean", true)') end it "should not let user override defaults" do profile['app.update.enabled'] = true string = read_generated_prefs - string.should include('user_pref("app.update.enabled", false)') + expect(string).to include('user_pref("app.update.enabled", false)') end it "should properly handle escaped characters" do profile['foo'] = 'C:\\r\\n' string = read_generated_prefs - string.should include('user_pref("foo", "C:\\\\r\\\\n");') + expect(string).to include('user_pref("foo", "C:\\\\r\\\\n");') end it "should let the user override some specific prefs" do profile["browser.startup.page"] = "http://example.com" string = read_generated_prefs - string.should include(%Q{user_pref("browser.startup.page", "http://example.com")}) + expect(string).to include(%Q{user_pref("browser.startup.page", "http://example.com")}) end it "should raise an error if the value given is not a string, number or boolean" do - lambda { profile['foo.bar'] = [] }.should raise_error(TypeError) + expect { profile['foo.bar'] = [] }.to raise_error(TypeError) end it "should raise an error if the value is already stringified" do - lambda { profile['foo.bar'] = '"stringified"' }.should raise_error(ArgumentError) + expect { profile['foo.bar'] = '"stringified"' }.to raise_error(ArgumentError) end it "should enable secure SSL" do profile.secure_ssl = true string = read_generated_prefs - string.should include('user_pref("webdriver_accept_untrusted_certs", false)') + expect(string).to include('user_pref("webdriver_accept_untrusted_certs", false)') end it "should disable secure SSL" do profile.secure_ssl = false string = read_generated_prefs - string.should include('user_pref("webdriver_accept_untrusted_certs", true)') + expect(string).to include('user_pref("webdriver_accept_untrusted_certs", true)') end it "should change the setting for untrusted certificate issuer" do profile.assume_untrusted_certificate_issuer = false string = read_generated_prefs - string.should include('user_pref("webdriver_assume_untrusted_issuer", false)') + expect(string).to include('user_pref("webdriver_assume_untrusted_issuer", false)') end it "can configure a manual proxy" do @@ -113,32 +113,32 @@ def read_generated_prefs(from = nil) profile.proxy = proxy string = read_generated_prefs - string.should include('user_pref("network.proxy.http", "foo")') - string.should include('user_pref("network.proxy.http_port", 123)') + expect(string).to include('user_pref("network.proxy.http", "foo")') + expect(string).to include('user_pref("network.proxy.http_port", 123)') - string.should include('user_pref("network.proxy.ftp", "bar")') - string.should include('user_pref("network.proxy.ftp_port", 234)') + expect(string).to include('user_pref("network.proxy.ftp", "bar")') + expect(string).to include('user_pref("network.proxy.ftp_port", 234)') - string.should include('user_pref("network.proxy.ssl", "baz")') - string.should include('user_pref("network.proxy.ssl_port", 345)') + expect(string).to include('user_pref("network.proxy.ssl", "baz")') + expect(string).to include('user_pref("network.proxy.ssl_port", 345)') - string.should include('user_pref("network.proxy.no_proxies_on", "localhost")') - string.should include('user_pref("network.proxy.type", 1)') + expect(string).to include('user_pref("network.proxy.no_proxies_on", "localhost")') + expect(string).to include('user_pref("network.proxy.type", 1)') end it "can configure a PAC proxy" do profile.proxy = Proxy.new(:pac => "http://foo/bar.pac") string = read_generated_prefs - string.should include('user_pref("network.proxy.autoconfig_url", "http://foo/bar.pac")') - string.should include('user_pref("network.proxy.type", 2)') + expect(string).to include('user_pref("network.proxy.autoconfig_url", "http://foo/bar.pac")') + expect(string).to include('user_pref("network.proxy.type", 2)') end it "can configure an auto-detected proxy" do profile.proxy = Proxy.new(:auto_detect => true) string = read_generated_prefs - string.should include('user_pref("network.proxy.type", 4)') + expect(string).to include('user_pref("network.proxy.type", 4)') end it "should be able to use the same profile more than once" do diff --git a/rb/spec/integration/selenium/webdriver/keyboard_spec.rb b/rb/spec/integration/selenium/webdriver/keyboard_spec.rb index 54b77cf4a4985..7da2d2734e0f2 100644 --- a/rb/spec/integration/selenium/webdriver/keyboard_spec.rb +++ b/rb/spec/integration/selenium/webdriver/keyboard_spec.rb @@ -31,9 +31,9 @@ module WebDriver driver.keyboard.send_keys "ab" text = driver.find_element(:id => "body_result").text.strip - text.should == "keypress keypress" + expect(text).to eq("keypress keypress") - driver.find_element(:id => "result").text.strip.should be_empty + expect(driver.find_element(:id => "result").text.strip).to be_empty end @@ -51,13 +51,13 @@ module WebDriver driver.keyboard.send_keys "ab" driver.keyboard.release :shift - event_input.attribute(:value).should == "AB" - keylogger.text.strip.should =~ /^(focus )?keydown keydown keypress keyup keydown keypress keyup keyup$/ + expect(event_input.attribute(:value)).to eq("AB") + expect(keylogger.text.strip).to match(/^(focus )?keydown keydown keypress keyup keydown keypress keyup keyup$/) end end it "raises an ArgumentError if the pressed key is not a modifier key" do - lambda { driver.keyboard.press :return }.should raise_error(ArgumentError) + expect { driver.keyboard.press :return }.to raise_error(ArgumentError) end # Edge does not yet support /session/:sessionId/click @@ -71,10 +71,10 @@ module WebDriver driver.mouse.click event_input driver.keyboard.press :shift - keylogger.text.should =~ /keydown$/ + expect(keylogger.text).to match(/keydown$/) driver.keyboard.release :shift - keylogger.text.should =~ /keyup$/ + expect(keylogger.text).to match(/keyup$/) end end end diff --git a/rb/spec/integration/selenium/webdriver/location_spec.rb b/rb/spec/integration/selenium/webdriver/location_spec.rb index 5468a81af9302..a36df5841c81f 100644 --- a/rb/spec/integration/selenium/webdriver/location_spec.rb +++ b/rb/spec/integration/selenium/webdriver/location_spec.rb @@ -38,9 +38,9 @@ module Selenium::WebDriver::DriverExtensions driver.location = location loc = driver.location - loc.latitude.should be_within(0.000001).of(lat) - loc.longitude.should be_within(0.000001).of(lon) - loc.altitude.should be_within(0.000001).of(alt) + expect(loc.latitude).to be_within(0.000001).of(lat) + expect(loc.longitude).to be_within(0.000001).of(lon) + expect(loc.altitude).to be_within(0.000001).of(alt) end end diff --git a/rb/spec/integration/selenium/webdriver/mouse_spec.rb b/rb/spec/integration/selenium/webdriver/mouse_spec.rb index dc44a23704346..3ac4b5ec0380e 100644 --- a/rb/spec/integration/selenium/webdriver/mouse_spec.rb +++ b/rb/spec/integration/selenium/webdriver/mouse_spec.rb @@ -45,7 +45,7 @@ module WebDriver driver.mouse.up droppable text = droppable.find_element(:tag_name => "p").text - text.should == "Dropped!" + expect(text).to eq("Dropped!") end it "double clicks an element" do diff --git a/rb/spec/integration/selenium/webdriver/navigation_spec.rb b/rb/spec/integration/selenium/webdriver/navigation_spec.rb index 9e810d459f9a5..eacb0fd5bd499 100644 --- a/rb/spec/integration/selenium/webdriver/navigation_spec.rb +++ b/rb/spec/integration/selenium/webdriver/navigation_spec.rb @@ -30,22 +30,22 @@ result_url = url_for "resultPage.html" driver.navigate.to form_url - driver.title.should == form_title + expect(driver.title).to eq(form_title) driver.find_element(:id, 'imageButton').click wait.until { driver.title != form_title } - driver.current_url.should include(result_url) - driver.title.should == result_title + expect(driver.current_url).to include(result_url) + expect(driver.title).to eq(result_title) driver.navigate.back - driver.current_url.should include(form_url) - driver.title.should == form_title + expect(driver.current_url).to include(form_url) + expect(driver.title).to eq(form_title) driver.navigate.forward - driver.current_url.should include(result_url) - driver.title.should == result_title + expect(driver.current_url).to include(result_url) + expect(driver.title).to eq(result_title) end it "should refresh the page" do @@ -53,12 +53,12 @@ driver.navigate.to url_for("javascriptPage.html") driver.find_element(:link_text, "Change the page title!").click - driver.title.should == changed_title + expect(driver.title).to eq(changed_title) driver.navigate.refresh wait.until { driver.title != changed_title } - driver.title.should == "Testing Javascript" + expect(driver.title).to eq("Testing Javascript") end end end diff --git a/rb/spec/integration/selenium/webdriver/options_spec.rb b/rb/spec/integration/selenium/webdriver/options_spec.rb index 32b36a766c6c3..d523acdeb4fd3 100644 --- a/rb/spec/integration/selenium/webdriver/options_spec.rb +++ b/rb/spec/integration/selenium/webdriver/options_spec.rb @@ -26,23 +26,23 @@ module WebDriver describe 'logs' do compliant_on :driver => [:firefox] do it 'can fetch available log types' do - driver.manage.logs.available_types.should == [:browser, :driver] + expect(driver.manage.logs.available_types).to eq([:browser, :driver]) end it 'can get the browser log' do driver.navigate.to url_for("simpleTest.html") entries = driver.manage.logs.get(:browser) - entries.should_not be_empty - entries.first.should be_kind_of(LogEntry) + expect(entries).not_to be_empty + expect(entries.first).to be_kind_of(LogEntry) end it 'can get the driver log' do driver.navigate.to url_for("simpleTest.html") entries = driver.manage.logs.get(:driver) - entries.should_not be_empty - entries.first.should be_kind_of(LogEntry) + expect(entries).not_to be_empty + expect(entries.first).to be_kind_of(LogEntry) end end end @@ -56,8 +56,8 @@ module WebDriver cookies = driver.manage.all_cookies expect(cookies.size).to eq(1) - cookies.first[:name].should == "foo" - cookies.first[:value].should == "bar" + expect(cookies.first[:name]).to eq("foo") + expect(cookies.first[:value]).to eq("bar") end not_compliant_on :browser => :edge do @@ -76,7 +76,7 @@ module WebDriver driver.manage.add_cookie :name => "foo", :value => "bar" driver.manage.delete_all_cookies - driver.manage.all_cookies.should be_empty + expect(driver.manage.all_cookies).to be_empty end end @@ -90,8 +90,8 @@ module WebDriver :expires => expected actual = driver.manage.cookie_named("foo")[:expires] - actual.should be_kind_of(DateTime) - actual.should == expected + expect(actual).to be_kind_of(DateTime) + expect(actual).to eq(expected) end end end diff --git a/rb/spec/integration/selenium/webdriver/remote/driver_spec.rb b/rb/spec/integration/selenium/webdriver/remote/driver_spec.rb index 1957103bd4e05..ef5a5a313e67f 100644 --- a/rb/spec/integration/selenium/webdriver/remote/driver_spec.rb +++ b/rb/spec/integration/selenium/webdriver/remote/driver_spec.rb @@ -23,12 +23,12 @@ module Remote describe Driver do it "should expose session_id" do - driver.session_id.should be_kind_of(String) + expect(driver.session_id).to be_kind_of(String) end it "should expose remote status" do - driver.should be_kind_of(DriverExtensions::HasRemoteStatus) - driver.remote_status.should be_kind_of(Hash) + expect(driver).to be_kind_of(DriverExtensions::HasRemoteStatus) + expect(driver.remote_status).to be_kind_of(Hash) end end diff --git a/rb/spec/integration/selenium/webdriver/remote/element_spec.rb b/rb/spec/integration/selenium/webdriver/remote/element_spec.rb index eb9282eef4b74..66fbd8b5c5fb1 100644 --- a/rb/spec/integration/selenium/webdriver/remote/element_spec.rb +++ b/rb/spec/integration/selenium/webdriver/remote/element_spec.rb @@ -37,7 +37,7 @@ module WebDriver driver.switch_to.frame("upload_target") body = driver.find_element(:xpath => "//body") - body.text.should include("uses the set file detector") + expect(body.text).to include("uses the set file detector") end end end diff --git a/rb/spec/integration/selenium/webdriver/sql_database_spec.rb b/rb/spec/integration/selenium/webdriver/sql_database_spec.rb index 636c8855f99e3..282c0e73a57b5 100644 --- a/rb/spec/integration/selenium/webdriver/sql_database_spec.rb +++ b/rb/spec/integration/selenium/webdriver/sql_database_spec.rb @@ -37,39 +37,39 @@ driver.execute_sql insert, "DocFooBar" result = driver.execute_sql select - result.rows.size.should == 2 + expect(result.rows.size).to eq(2) - result.rows[0]['docname'].should == 'DocFoo' - result.rows[1]['docname'].should == 'DocFooBar' + expect(result.rows[0]['docname']).to eq('DocFoo') + expect(result.rows[1]['docname']).to eq('DocFooBar') driver.execute_sql delete result = driver.execute_sql select - result.rows.size.should == 0 + expect(result.rows.size).to eq(0) end it "knows the number of rows affected" do result = driver.execute_sql insert, "DocFooBar" - result.rows_affected.should == 1 + expect(result.rows_affected).to eq(1) result = driver.execute_sql select - result.rows_affected.should == 0 + expect(result.rows_affected).to eq(0) driver.execute_sql update - result.rows.affected.should == 1 + expect(result.rows.affected).to eq(1) end it "returns last inserted row id" do result = driver.execute_sql select - result.last_inserted_row_id.should == -1 + expect(result.last_inserted_row_id).to eq(-1) driver.execute_sql insert, "DocFoo" - result.last_inserted_row_id.should_not == -1 + expect(result.last_inserted_row_id).not_to eq(-1) result = driver.execute_sql select - result.last_inserted_row_id.should == -1 + expect(result.last_inserted_row_id).to eq(-1) result = driver.execute_sql delete - result.last_inserted_row_id.should == -1 + expect(result.last_inserted_row_id).to eq(-1) end end diff --git a/rb/spec/integration/selenium/webdriver/storage_spec.rb b/rb/spec/integration/selenium/webdriver/storage_spec.rb index a6bf9339358c5..7c0e148e4e3ac 100644 --- a/rb/spec/integration/selenium/webdriver/storage_spec.rb +++ b/rb/spec/integration/selenium/webdriver/storage_spec.rb @@ -30,14 +30,14 @@ module Selenium::WebDriver::DriverExtensions } it "can get and set items" do - storage.should be_empty + expect(storage).to be_empty storage['foo'] = 'bar' - storage['foo'].should == 'bar' + expect(storage['foo']).to eq('bar') storage['foo1'] = 'bar1' - storage['foo1'].should == 'bar1' + expect(storage['foo1']).to eq('bar1') - storage.size.should == 2 + expect(storage.size).to eq(2) end it "can get all keys" do @@ -45,8 +45,8 @@ module Selenium::WebDriver::DriverExtensions storage['foo2'] = 'bar2' storage['foo3'] = 'bar3' - storage.size.should == 3 - storage.keys.should == %w[foo1 foo2 foo3] + expect(storage.size).to eq(3) + expect(storage.keys).to eq(%w[foo1 foo2 foo3]) end it "can clear all items" do @@ -54,10 +54,10 @@ module Selenium::WebDriver::DriverExtensions storage['foo2'] = 'bar2' storage['foo3'] = 'bar3' - storage.size.should == 3 + expect(storage.size).to eq(3) storage.clear - storage.size.should == 0 - storage.keys.should be_empty + expect(storage.size).to eq(0) + expect(storage.keys).to be_empty end it "can delete an item" do @@ -65,15 +65,15 @@ module Selenium::WebDriver::DriverExtensions storage['foo2'] = 'bar2' storage['foo3'] = 'bar3' - storage.size.should == 3 - storage.delete('foo1').should == 'bar1' - storage.size.should == 2 + expect(storage.size).to eq(3) + expect(storage.delete('foo1')).to eq('bar1') + expect(storage.size).to eq(2) end it "knows if a key is set" do - storage.should_not have_key('foo1') + expect(storage).not_to have_key('foo1') storage['foo1'] = 'bar1' - storage.should have_key('foo1') + expect(storage).to have_key('foo1') end it "is Enumerable" do @@ -81,22 +81,22 @@ module Selenium::WebDriver::DriverExtensions storage['foo2'] = 'bar2' storage['foo3'] = 'bar3' - storage.to_a.should == [ + expect(storage.to_a).to eq([ ['foo1', 'bar1'], ['foo2', 'bar2'], ['foo3', 'bar3'] - ] + ]) end it "can fetch an item" do storage['foo1'] = 'bar1' - storage.fetch('foo1').should == 'bar1' + expect(storage.fetch('foo1')).to eq('bar1') end it "raises IndexError on missing key" do - lambda do + expect do storage.fetch('no-such-key') - end.should raise_error(IndexError, /missing key/) + end.to raise_error(IndexError, /missing key/) end end diff --git a/rb/spec/integration/selenium/webdriver/target_locator_spec.rb b/rb/spec/integration/selenium/webdriver/target_locator_spec.rb index 922d4999c0fd2..23dc6c95e584a 100644 --- a/rb/spec/integration/selenium/webdriver/target_locator_spec.rb +++ b/rb/spec/integration/selenium/webdriver/target_locator_spec.rb @@ -26,7 +26,7 @@ not_compliant_on :browser => :edge do it "should find the active element" do driver.navigate.to url_for("xhtmlTest.html") - driver.switch_to.active_element.should be_an_instance_of(WebDriver::Element) + expect(driver.switch_to.active_element).to be_an_instance_of(WebDriver::Element) end end @@ -36,7 +36,7 @@ driver.navigate.to url_for("iframes.html") driver.switch_to.frame("iframe1") - driver.find_element(:name, 'login').should be_kind_of(WebDriver::Element) + expect(driver.find_element(:name, 'login')).to be_kind_of(WebDriver::Element) end # Edge does not yet support /session/:sessionId/frame @@ -47,7 +47,7 @@ iframe = driver.find_element(:tag_name => "iframe") driver.switch_to.frame(iframe) - driver.find_element(:name, 'login').should be_kind_of(WebDriver::Element) + expect(driver.find_element(:name, 'login')).to be_kind_of(WebDriver::Element) end end end @@ -60,10 +60,10 @@ iframe = driver.find_element(:tag_name => "iframe") driver.switch_to.frame(iframe) - driver.find_element(:name, 'login').should be_kind_of(WebDriver::Element) + expect(driver.find_element(:name, 'login')).to be_kind_of(WebDriver::Element) driver.switch_to.parent_frame - driver.find_element(:id, 'iframe_page_heading').should be_kind_of(WebDriver::Element) + expect(driver.find_element(:id, 'iframe_page_heading')).to be_kind_of(WebDriver::Element) end end @@ -79,7 +79,7 @@ driver.navigate.to url_for("xhtmlTest.html") driver.find_element(:link, "Open new window").click - driver.title.should == "XHTML Test Page" + expect(driver.title).to eq("XHTML Test Page") driver.switch_to.window("result") do wait.until { driver.title == "We Arrive Here" } @@ -93,38 +93,38 @@ driver.navigate.to url_for("xhtmlTest.html") driver.find_element(:link, "Open new window").click - driver.title.should == "XHTML Test Page" + expect(driver.title).to eq("XHTML Test Page") - lambda { + expect { driver.switch_to.window("result") { raise "foo" } - }.should raise_error(RuntimeError, "foo") + }.to raise_error(RuntimeError, "foo") - driver.title.should == "XHTML Test Page" + expect(driver.title).to eq("XHTML Test Page") end it "should switch to a window" do driver.navigate.to url_for("xhtmlTest.html") driver.find_element(:link, "Open new window").click - driver.title.should == "XHTML Test Page" + expect(driver.title).to eq("XHTML Test Page") driver.switch_to.window("result") - driver.title.should == "We Arrive Here" + expect(driver.title).to eq("We Arrive Here") end it "should use the original window if the block closes the popup" do driver.navigate.to url_for("xhtmlTest.html") driver.find_element(:link, "Open new window").click - driver.title.should == "XHTML Test Page" + expect(driver.title).to eq("XHTML Test Page") driver.switch_to.window("result") do wait.until { driver.title == "We Arrive Here" } driver.close end - driver.current_url.should include("xhtmlTest.html") - driver.title.should == "XHTML Test Page" + expect(driver.current_url).to include("xhtmlTest.html") + expect(driver.title).to eq("XHTML Test Page") end it "should close current window when more than two windows exist" do @@ -163,7 +163,7 @@ end driver.switch_to.window(new_window) - driver.title.should == "We Arrive Here" + expect(driver.title).to eq("We Arrive Here") end it "should iterate over open windows when current window is closed" do @@ -180,7 +180,7 @@ end driver.switch_to.window(new_window) - driver.title.should == "We Arrive Here" + expect(driver.title).to eq("We Arrive Here") end it "should switch to a window and execute a block when current window is closed" do @@ -198,7 +198,7 @@ wait.until { driver.title == "XHTML Test Page" } end - driver.title.should == "XHTML Test Page" + expect(driver.title).to eq("XHTML Test Page") end end @@ -223,7 +223,7 @@ alert = wait_for_alert alert.accept - driver.title.should == "Testing Alerts" + expect(driver.title).to eq("Testing Alerts") end end @@ -240,7 +240,7 @@ wait_for_no_alert - driver.title.should == "Testing Alerts" + expect(driver.title).to eq("Testing Alerts") end end @@ -255,7 +255,7 @@ alert.accept text = driver.find_element(:id => "text").text - text.should == "cheese" + expect(text).to eq("cheese") end # Edge does not yet support session/:session_id/alert_text @@ -268,7 +268,7 @@ text = alert.text alert.accept - text.should == "cheese" + expect(text).to eq("cheese") end end @@ -289,7 +289,7 @@ not_compliant_on :browser => [:ie, :iphone, :safari, :phantomjs] do it "raises NoAlertOpenError if no alert is present" do - lambda { driver.switch_to.alert }.should raise_error( + expect { driver.switch_to.alert }.to raise_error( Selenium::WebDriver::Error::NoAlertPresentError, /alert|modal dialog/i) end end @@ -300,9 +300,9 @@ driver.find_element(:id => "alert").click wait_for_alert - lambda { driver.title }.should raise_error(Selenium::WebDriver::Error::UnhandledAlertError, /cheese/) + expect { driver.title }.to raise_error(Selenium::WebDriver::Error::UnhandledAlertError, /cheese/) - driver.title.should == "Testing Alerts" # :chrome does not auto-dismiss the alert + expect(driver.title).to eq("Testing Alerts") # :chrome does not auto-dismiss the alert end end diff --git a/rb/spec/integration/selenium/webdriver/timeout_spec.rb b/rb/spec/integration/selenium/webdriver/timeout_spec.rb index 9fefa625b3bd2..ff53c12c09a90 100644 --- a/rb/spec/integration/selenium/webdriver/timeout_spec.rb +++ b/rb/spec/integration/selenium/webdriver/timeout_spec.rb @@ -40,14 +40,14 @@ it "should still fail to find an element with implicit waits enabled" do driver.manage.timeouts.implicit_wait = 0.5 - lambda { driver.find_element(:id => "box0") }.should raise_error(WebDriver::Error::NoSuchElementError) + expect { driver.find_element(:id => "box0") }.to raise_error(WebDriver::Error::NoSuchElementError) end it "should return after first attempt to find one after disabling implicit waits" do driver.manage.timeouts.implicit_wait = 3 driver.manage.timeouts.implicit_wait = 0 - lambda { driver.find_element(:id => "box0") }.should raise_error(WebDriver::Error::NoSuchElementError) + expect { driver.find_element(:id => "box0") }.to raise_error(WebDriver::Error::NoSuchElementError) end it "should implicitly wait until at least one element is found when searching for many" do @@ -57,12 +57,12 @@ add.click add.click - driver.find_elements(:class_name => "redbox").should_not be_empty + expect(driver.find_elements(:class_name => "redbox")).not_to be_empty end it "should still fail to find elements when implicit waits are enabled" do driver.manage.timeouts.implicit_wait = 0.5 - driver.find_elements(:class_name => "redbox").should be_empty + expect(driver.find_elements(:class_name => "redbox")).to be_empty end it "should return after first attempt to find many after disabling implicit waits" do @@ -72,7 +72,7 @@ driver.manage.timeouts.implicit_wait = 0 add.click - driver.find_elements(:class_name => "redbox").should be_empty + expect(driver.find_elements(:class_name => "redbox")).to be_empty end end end diff --git a/rb/spec/integration/selenium/webdriver/touch_spec.rb b/rb/spec/integration/selenium/webdriver/touch_spec.rb index 6b327d76a263b..460cae49bfc8d 100644 --- a/rb/spec/integration/selenium/webdriver/touch_spec.rb +++ b/rb/spec/integration/selenium/webdriver/touch_spec.rb @@ -31,32 +31,32 @@ module Selenium::WebDriver::DriverExtensions it "can flick horizontally from element" do link = driver.find_element(:id => "link1") - link.location.x.should > 1500 + expect(link.location.x).to be > 1500 to_flick = driver.find_element(:id => "imagestart") driver.touch.flick(to_flick, -1000, 0, :normal).perform - link.location.x.should < 1500 + expect(link.location.x).to be < 1500 end it "can flick horizontally fast from element" do link = driver.find_element(:id => "link2") - link.location.x.should > 3500 + expect(link.location.x).to be > 3500 to_flick = driver.find_element(:id => "imagestart") driver.touch.flick(to_flick, -400, 0, :fast).perform - link.location.x.should < 3500 + expect(link.location.x).to be < 3500 end not_compliant_on :browser => :android do it "can flick horizontally" do link = driver.find_element(:id => "link1") - link.location.x.should > 1500 + expect(link.location.x).to be > 1500 driver.touch.flick(1000, 0).perform - link.location.x.should < 1500 + expect(link.location.x).to be < 1500 end end @@ -67,41 +67,41 @@ module Selenium::WebDriver::DriverExtensions it "can flick vertically from element" do link = driver.find_element(:id => "link3") - link.location.y.should > 4200 + expect(link.location.y).to be > 4200 to_flick = driver.find_element(:id => "imagestart") driver.touch.flick(to_flick, 0, -600, :normal).perform - link.location.y.should < 4000 + expect(link.location.y).to be < 4000 end it "can flick vertically fast from element" do link = driver.find_element(:id => "link4") - link.location.y.should > 8700 + expect(link.location.y).to be > 8700 to_flick = driver.find_element(:id => "imagestart") driver.touch.flick(to_flick, 0, -600, :fast).perform - link.location.y.should < 8700 + expect(link.location.y).to be < 8700 end it "can flick vertically" do link = driver.find_element(:id => "link3") - link.location.y.should > 4200 + expect(link.location.y).to be > 4200 to_flick = driver.find_element(:id => "imagestart") driver.touch.flick(0, 750).perform - link.location.y.should < 4200 + expect(link.location.y).to be < 4200 end it "can flick vertically fast" do link = driver.find_element(:id => "link4") - link.location.y.should > 8700 + expect(link.location.y).to be > 8700 driver.touch.flick(0, 1500).perform - link.location.y.should < 4000 + expect(link.location.y).to be < 4000 end end @@ -119,7 +119,7 @@ module Selenium::WebDriver::DriverExtensions to_scroll = driver.find_element(:id => "imagestart") driver.touch.scroll(to_scroll, 0, -800).perform - link.location.y.should < 3500 + expect(link.location.y).to be < 3500 end end @@ -129,12 +129,12 @@ module Selenium::WebDriver::DriverExtensions driver.touch.scroll(0, 800).perform - link.location.y.should < 3500 + expect(link.location.y).to be < 3500 end it "can scroll horizontally from element" do link = driver.find_element(:id => "link1") - link.location.x.should > 1500 + expect(link.location.x).to be > 1500 to_scroll = driver.find_element(:id => "imagestart") driver.touch.scroll(to_scroll, -1000, 0).perform @@ -144,7 +144,7 @@ module Selenium::WebDriver::DriverExtensions it "can scroll horizontally" do link = driver.find_element(:id => "link1") - link.location.x.should > 1500 + expect(link.location.x).to be > 1500 driver.touch.scroll(400, 0).perform @@ -169,7 +169,7 @@ module Selenium::WebDriver::DriverExtensions driver.touch.single_tap(e).perform same_page = driver.execute_script "return document.latch" - same_page.should be true + expect(same_page).to be true end end @@ -178,10 +178,10 @@ module Selenium::WebDriver::DriverExtensions it "can double tap an element" do image = driver.find_element(:id => "imagestart") - image.location.y.should > 100 + expect(image.location.y).to be > 100 driver.touch.double_tap(image).perform - image.location.y.should < 50 + expect(image.location.y).to be < 50 end end diff --git a/rb/spec/integration/selenium/webdriver/window_spec.rb b/rb/spec/integration/selenium/webdriver/window_spec.rb index 3faf81f1d9a08..7563129755326 100644 --- a/rb/spec/integration/selenium/webdriver/window_spec.rb +++ b/rb/spec/integration/selenium/webdriver/window_spec.rb @@ -28,10 +28,10 @@ module WebDriver it "gets the size of the current window" do size = window.size - size.should be_kind_of(Dimension) + expect(size).to be_kind_of(Dimension) - size.width.should > 0 - size.height.should > 0 + expect(size.width).to be > 0 + expect(size.height).to be > 0 end it "sets the size of the current window" do @@ -43,17 +43,17 @@ module WebDriver window.size = Dimension.new(target_width, target_height) new_size = window.size - new_size.width.should == target_width - new_size.height.should == target_height + expect(new_size.width).to eq(target_width) + expect(new_size.height).to eq(target_height) end it "gets the position of the current window" do pos = driver.manage.window.position - pos.should be_kind_of(Point) + expect(pos).to be_kind_of(Point) - pos.x.should >= 0 - pos.y.should >= 0 + expect(pos.x).to be >= 0 + expect(pos.y).to be >= 0 end it "sets the position of the current window" do @@ -65,8 +65,8 @@ module WebDriver window.position = Point.new(target_x, target_y) new_pos = window.position - new_pos.x.should == target_x - new_pos.y.should == target_y + expect(new_pos.x).to eq(target_x) + expect(new_pos.y).to eq(target_y) end end @@ -79,8 +79,8 @@ module WebDriver window.maximize new_size = window.size - new_size.width.should > old_size.width - new_size.height.should > old_size.height + expect(new_size.width).to be > old_size.width + expect(new_size.height).to be > old_size.height end end diff --git a/rb/spec/integration/selenium/webdriver/zipper_spec.rb b/rb/spec/integration/selenium/webdriver/zipper_spec.rb index 64f0fbaa67719..80cab351900da 100644 --- a/rb/spec/integration/selenium/webdriver/zipper_spec.rb +++ b/rb/spec/integration/selenium/webdriver/zipper_spec.rb @@ -51,7 +51,7 @@ def create_file end unzipped = Zipper.unzip(zip_file) - File.read(File.join(unzipped, base_file_name)).should == file_content + expect(File.read(File.join(unzipped, base_file_name))).to eq(file_content) end it "zips and unzips a single file" do @@ -62,7 +62,7 @@ def create_file end unzipped = Zipper.unzip(zip_file) - File.read(File.join(unzipped, base_file_name)).should == file_content + expect(File.read(File.join(unzipped, base_file_name))).to eq(file_content) end not_compliant_on :platform => :windows do @@ -76,7 +76,7 @@ def create_file end unzipped = Zipper.unzip(zip_file) - File.read(File.join(unzipped, "link")).should == file_content + expect(File.read(File.join(unzipped, "link"))).to eq(file_content) end end diff --git a/rb/spec/unit/selenium/client/base_spec.rb b/rb/spec/unit/selenium/client/base_spec.rb index a16fe2fe8e054..fbb3b74a0e83e 100644 --- a/rb/spec/unit/selenium/client/base_spec.rb +++ b/rb/spec/unit/selenium/client/base_spec.rb @@ -28,72 +28,72 @@ class BaseClient describe "#initialize with hash" do it "sets the host" do client = BaseClient.new :host => "the.host.com" - client.host.should == "the.host.com" + expect(client.host).to eq("the.host.com") end it "sets the port" do client = BaseClient.new :port => 4000 - client.port.should == 4000 + expect(client.port).to eq(4000) end it "sets the port as a string" do client = BaseClient.new :port => "4000" - client.port.should == 4000 + expect(client.port).to eq(4000) end it "sets the browser string" do client = BaseClient.new :browser => "*safari" - client.browser_string.should == "*safari" + expect(client.browser_string).to eq("*safari") end it "sets the browser url" do client = BaseClient.new :url => "http://ph7spot.com" - client.browser_url.should == "http://ph7spot.com" + expect(client.browser_url).to eq("http://ph7spot.com") end it "sets the default timeout" do client = BaseClient.new :timeout_in_seconds => 24 - client.default_timeout_in_seconds.should == 24 + expect(client.default_timeout_in_seconds).to eq(24) end it "sets the default javascript framework " do client = BaseClient.new :javascript_framework => :jquery - client.default_javascript_framework.should == :jquery + expect(client.default_javascript_framework).to eq(:jquery) end it "sets the default javascript framework to prototype when not explicitely set" do - BaseClient.new.default_javascript_framework.should == :prototype + expect(BaseClient.new.default_javascript_framework).to eq(:prototype) end it "sets highlight_located_element_by_default" do client = BaseClient.new :highlight_located_element => true - client.highlight_located_element_by_default.should be true + expect(client.highlight_located_element_by_default).to be true end it "sets highlight_located_element_by_default to false by default" do client = BaseClient.new :host => :a_host - client.highlight_located_element_by_default.should be false + expect(client.highlight_located_element_by_default).to be false end end describe "#initialize" do it "sets the default timeout to 5 minutes when not explicitely set" do - BaseClient.new.default_timeout_in_seconds.should == 5 * 60 + expect(BaseClient.new.default_timeout_in_seconds).to eq(5 * 60) end it "sets default_timeout_in_seconds to the client driver default timeout in seconds" do client = BaseClient.new :host, 1234, :browser, :url, 24 - client.default_timeout_in_seconds.should == 24 + expect(client.default_timeout_in_seconds).to eq(24) end it "sets default_timeout_in_seconds to 5 minutes by default" do client = BaseClient.new :host, 24, :browser, :url - client.default_timeout_in_seconds.should == 5 * 60 + expect(client.default_timeout_in_seconds).to eq(5 * 60) end it "sets highlight_located_element_by_default to false by default" do - BaseClient.new.highlight_located_element_by_default.should be false + expect(BaseClient.new.highlight_located_element_by_default).to be false end end @@ -101,8 +101,8 @@ class BaseClient it "executes a getNewBrowserSession command with the browser string an url" do client = BaseClient.new :host, 24, :the_browser, :the_url - client.stub(:remote_control_command) - client.should_receive(:string_command).with("getNewBrowserSession", [:the_browser, :the_url, "", ""]) + allow(client).to receive(:remote_control_command) + expect(client).to receive(:string_command).with("getNewBrowserSession", [:the_browser, :the_url, "", ""]) client.start_new_browser_session end @@ -111,8 +111,8 @@ class BaseClient client = BaseClient.new :host, 24, :the_browser, :the_url client.javascript_extension = :the_javascript_extension - client.stub(:remote_control_command) - client.should_receive(:string_command).with("getNewBrowserSession", [:the_browser, :the_url, :the_javascript_extension, ""]) + allow(client).to receive(:remote_control_command) + expect(client).to receive(:string_command).with("getNewBrowserSession", [:the_browser, :the_url, :the_javascript_extension, ""]) client.start_new_browser_session end @@ -121,8 +121,8 @@ class BaseClient client = BaseClient.new :host, 24, :the_browser, :the_url client.javascript_extension = :the_javascript_extension - client.stub(:remote_control_command) - client.should_receive(:string_command).with("getNewBrowserSession", [:the_browser, :the_url, :the_javascript_extension, "captureNetworkTraffic=true"]) + allow(client).to receive(:remote_control_command) + expect(client).to receive(:string_command).with("getNewBrowserSession", [:the_browser, :the_url, :the_javascript_extension, "captureNetworkTraffic=true"]) client.start_new_browser_session(:captureNetworkTraffic => true) end @@ -131,8 +131,8 @@ class BaseClient client = BaseClient.new :host, 24, :the_browser, :the_url client.javascript_extension = :the_javascript_extension - client.stub(:remote_control_command) - client.should_receive(:string_command).with("getNewBrowserSession", [:the_browser, :the_url, :the_javascript_extension, "captureNetworkTraffic=true;quack=false"]) + allow(client).to receive(:remote_control_command) + expect(client).to receive(:string_command).with("getNewBrowserSession", [:the_browser, :the_url, :the_javascript_extension, "captureNetworkTraffic=true;quack=false"]) client.start_new_browser_session(:captureNetworkTraffic => true, :quack => false) end @@ -140,20 +140,20 @@ class BaseClient it "sets the current sessionId with getNewBrowserSession response" do client = BaseClient.new :host, 24, :the_browser, :the_url - client.stub(:remote_control_command) - client.should_receive(:string_command).with("getNewBrowserSession", instance_of(Array)). + allow(client).to receive(:remote_control_command) + expect(client).to receive(:string_command).with("getNewBrowserSession", instance_of(Array)). and_return("the new session id") client.start_new_browser_session - client.session_id.should == "the new session id" + expect(client.session_id).to eq("the new session id") end it "sets remote control timeout to the driver default timeout" do client = BaseClient.new :host, 24, :the_browser, :the_url, 24 - client.should_receive(:string_command).with("getNewBrowserSession", instance_of(Array)) - client.should_receive(:remote_control_timeout_in_seconds=).with(24) + expect(client).to receive(:string_command).with("getNewBrowserSession", instance_of(Array)) + expect(client).to receive(:remote_control_timeout_in_seconds=).with(24) client.start_new_browser_session end @@ -161,8 +161,8 @@ class BaseClient it "sets up auto-higlight of located element when option is set" do client = BaseClient.new :highlight_located_element => true - client.stub(:remote_control_command) - client.should_receive(:highlight_located_element=).with(true) + allow(client).to receive(:remote_control_command) + expect(client).to receive(:highlight_located_element=).with(true) client.start_new_browser_session end @@ -170,8 +170,8 @@ class BaseClient it "does not set up auto-higlight of located element when option is not set" do client = BaseClient.new :highlight_located_element => false - client.stub(:remote_control_command) - client.should_not_receive(:highlight_located_element=) + allow(client).to receive(:remote_control_command) + expect(client).not_to receive(:highlight_located_element=) client.start_new_browser_session end @@ -180,72 +180,72 @@ class BaseClient describe "session_started?" do it "returns false when no session has been started" do client = BaseClient.new :host, 24, :browser, :url - client.session_started?.should be_false + expect(client.session_started?).to be_falsey end it "returns true when session has been started" do client = BaseClient.new :host, 24, :browser, :url - client.stub(:string_command).and_return("A Session Id") - client.stub(:remote_control_command) + allow(client).to receive(:string_command).and_return("A Session Id") + allow(client).to receive(:remote_control_command) client.start_new_browser_session - client.session_started?.should be true + expect(client.session_started?).to be true end it "returns false when session has been stopped" do client = BaseClient.new :host, 24, :browser, :url - client.stub(:string_command).and_return("A Session Id") - client.stub(:remote_control_command) + allow(client).to receive(:string_command).and_return("A Session Id") + allow(client).to receive(:remote_control_command) client.start_new_browser_session client.stop - client.session_started?.should be false + expect(client.session_started?).to be false end end describe "chrome_backend?" do it "returns true when the browser string is *firefox" do client = BaseClient.new :host, 24, "*firefox", :url - client.chrome_backend?.should be true + expect(client.chrome_backend?).to be true end it "returns false when the browser string is *iexplore" do client = BaseClient.new :host, 24, "*iexplore", :url - client.chrome_backend?.should be false + expect(client.chrome_backend?).to be false end it "returns false when the browser string is *safari" do client = BaseClient.new :host, 24, "*safari", :url - client.chrome_backend?.should be false + expect(client.chrome_backend?).to be false end it "returns true when the browser string is *chrome" do client = BaseClient.new :host, 24, "*chrome", :url - client.chrome_backend?.should be true + expect(client.chrome_backend?).to be true end it "returns true when the browser string is *firefox2" do client = BaseClient.new :host, 24, "*firefox2", :url - client.chrome_backend?.should be true + expect(client.chrome_backend?).to be true end it "returns true when the browser string is *firefox3" do client = BaseClient.new :host, 24, "*firefox3", :url - client.chrome_backend?.should be true + expect(client.chrome_backend?).to be true end it "returns false when the browser string is *firefoxproxy" do client = BaseClient.new :host, 24, "*firefoxproxy", :url - client.chrome_backend?.should be false + expect(client.chrome_backend?).to be false end it "returns false when the browser string is *pifirefox" do client = BaseClient.new :host, 24, "*pifirefox", :url - client.chrome_backend?.should be false + expect(client.chrome_backend?).to be false end end diff --git a/rb/spec/unit/selenium/client/extensions_spec.rb b/rb/spec/unit/selenium/client/extensions_spec.rb index 86e92d9206e95..84ed2253b7253 100644 --- a/rb/spec/unit/selenium/client/extensions_spec.rb +++ b/rb/spec/unit/selenium/client/extensions_spec.rb @@ -28,86 +28,86 @@ class ExtensionsClient describe "#wait_for_text" do it "waits for the innerHTML content of an element when a locator is provided" do - client.should_receive(:wait_for_condition).with(/findElement\('a_locator'\)/, anything) + expect(client).to receive(:wait_for_condition).with(/findElement\('a_locator'\)/, anything) client.wait_for_text "some text", :element => "a_locator" end it "waits for the page content when no locator is provided" do - client.should_receive(:wait_for_condition).with(%r{document.body.innerHTML.match\(/some text/\)}m, anything) + expect(client).to receive(:wait_for_condition).with(%r{document.body.innerHTML.match\(/some text/\)}m, anything) client.wait_for_text "some text" end it "waits for the page content regexp when no locator is provided" do - client.should_receive(:wait_for_condition).with(%r{document.body.innerHTML.match\(/some text/\)}m, anything) + expect(client).to receive(:wait_for_condition).with(%r{document.body.innerHTML.match\(/some text/\)}m, anything) client.wait_for_text(/some text/) end it "uses default timeout when none is provided" do - client.should_receive(:wait_for_condition).with(anything, nil) + expect(client).to receive(:wait_for_condition).with(anything, nil) client.wait_for_text "some text" end it "uses explicit timeout when provided" do - client.should_receive(:wait_for_condition).with(anything, :explicit_timeout) + expect(client).to receive(:wait_for_condition).with(anything, :explicit_timeout) client.wait_for_text "some text", :timeout_in_seconds => :explicit_timeout end end describe "#wait_for_no_text" do it "waits for the innerHTML content of an element when a locator is provided" do - client.should_receive(:wait_for_condition).with(/findElement\('a_locator'\)/, anything) + expect(client).to receive(:wait_for_condition).with(/findElement\('a_locator'\)/, anything) client.wait_for_no_text "some text", :element => "a_locator" end it "waits for the page content for regexp when no locator is provided" do - client.should_receive(:wait_for_condition).with(%r{document.body.innerHTML.match\(/some text/\)}m, anything) + expect(client).to receive(:wait_for_condition).with(%r{document.body.innerHTML.match\(/some text/\)}m, anything) client.wait_for_no_text(/some text/) end it "waits for the page content when no locator is provided" do - client.should_receive(:wait_for_condition).with(%r{document.body.innerHTML.match\(/some text/\)}m, anything) + expect(client).to receive(:wait_for_condition).with(%r{document.body.innerHTML.match\(/some text/\)}m, anything) client.wait_for_no_text "some text" end it "uses default timeout when none is provided" do - client.should_receive(:wait_for_condition).with(anything, nil) + expect(client).to receive(:wait_for_condition).with(anything, nil) client.wait_for_no_text "some text" end it "uses explicit timeout when provided" do - client.should_receive(:wait_for_condition).with(anything, :explicit_timeout) + expect(client).to receive(:wait_for_condition).with(anything, :explicit_timeout) client.wait_for_no_text "some text", :timeout_in_seconds => :explicit_timeout end end describe "#wait_for_ajax" do it "uses Ajax.activeRequestCount when default js framework is prototype" do - client.stub(:default_javascript_framework).and_return(:prototype) - client.should_receive(:wait_for_condition).with("selenium.browserbot.getCurrentWindow().Ajax.activeRequestCount == 0;", anything) + allow(client).to receive(:default_javascript_framework).and_return(:prototype) + expect(client).to receive(:wait_for_condition).with("selenium.browserbot.getCurrentWindow().Ajax.activeRequestCount == 0;", anything) client.wait_for_ajax end it "uses jQuery.active when default js framework is jQuery" do - client.stub(:default_javascript_framework).and_return(:jquery) - client.should_receive(:wait_for_condition).with("selenium.browserbot.getCurrentWindow().jQuery.active == 0;", anything) + allow(client).to receive(:default_javascript_framework).and_return(:jquery) + expect(client).to receive(:wait_for_condition).with("selenium.browserbot.getCurrentWindow().jQuery.active == 0;", anything) client.wait_for_ajax end it "can override default js framework" do - client.stub(:default_javascript_framework).and_return(:prototype) - client.should_receive(:wait_for_condition).with("selenium.browserbot.getCurrentWindow().jQuery.active == 0;", anything) + allow(client).to receive(:default_javascript_framework).and_return(:prototype) + expect(client).to receive(:wait_for_condition).with("selenium.browserbot.getCurrentWindow().jQuery.active == 0;", anything) client.wait_for_ajax :javascript_framework => :jquery end it "uses default timeout when none is provided" do - client.stub(:default_javascript_framework).and_return(:prototype) - client.should_receive(:wait_for_condition).with(anything, nil) + allow(client).to receive(:default_javascript_framework).and_return(:prototype) + expect(client).to receive(:wait_for_condition).with(anything, nil) client.wait_for_ajax end it "uses explicit timeout when provided" do - client.stub(:default_javascript_framework).and_return(:prototype) - client.should_receive(:wait_for_condition).with(anything, :explicit_timeout) + allow(client).to receive(:default_javascript_framework).and_return(:prototype) + expect(client).to receive(:wait_for_condition).with(anything, :explicit_timeout) client.wait_for_ajax :timeout_in_seconds => :explicit_timeout end @@ -115,78 +115,78 @@ class ExtensionsClient describe "#wait_for_effect" do it "uses Effect.Queue.size() when default js framework is prototype" do - client.stub(:default_javascript_framework).and_return(:prototype) - client.should_receive(:wait_for_condition).with("selenium.browserbot.getCurrentWindow().Effect.Queue.size() == 0;", anything) + allow(client).to receive(:default_javascript_framework).and_return(:prototype) + expect(client).to receive(:wait_for_condition).with("selenium.browserbot.getCurrentWindow().Effect.Queue.size() == 0;", anything) client.wait_for_effects end it "uses default timeout when none is provided" do - client.stub(:default_javascript_framework).and_return(:prototype) - client.should_receive(:wait_for_condition).with(anything, nil) + allow(client).to receive(:default_javascript_framework).and_return(:prototype) + expect(client).to receive(:wait_for_condition).with(anything, nil) client.wait_for_effects end it "uses explicit timeout when provided" do - client.stub(:default_javascript_framework).and_return(:prototype) - client.should_receive(:wait_for_condition).with(anything, :explicit_timeout) + allow(client).to receive(:default_javascript_framework).and_return(:prototype) + expect(client).to receive(:wait_for_condition).with(anything, :explicit_timeout) client.wait_for_effects :timeout_in_seconds => :explicit_timeout end end describe "#wait_for_field_value" do it "uses provided locator" do - client.should_receive(:wait_for_condition).with(/findElement\('a_locator'\)/, anything) + expect(client).to receive(:wait_for_condition).with(/findElement\('a_locator'\)/, anything) client.wait_for_field_value "a_locator", "a value" end it "uses provided field value" do - client.should_receive(:wait_for_condition).with(/element.value == 'a value'/, anything) + expect(client).to receive(:wait_for_condition).with(/element.value == 'a value'/, anything) client.wait_for_field_value "a_locator", "a value" end it "uses explicit timeout when provided" do - client.should_receive(:wait_for_condition).with(anything, :the_timeout) + expect(client).to receive(:wait_for_condition).with(anything, :the_timeout) client.wait_for_field_value "a_locator", "a value", :timeout_in_seconds => :the_timeout end end describe "#wait_for_no_field_value" do it "uses provided locator" do - client.should_receive(:wait_for_condition).with(/findElement\('a_locator'\)/, anything) + expect(client).to receive(:wait_for_condition).with(/findElement\('a_locator'\)/, anything) client.wait_for_no_field_value "a_locator", "a value" end it "uses provided field value" do - client.should_receive(:wait_for_condition).with(/element.value != 'a value'/, anything) + expect(client).to receive(:wait_for_condition).with(/element.value != 'a value'/, anything) client.wait_for_no_field_value "a_locator", "a value" end it "uses explicit timeout when provided" do - client.should_receive(:wait_for_condition).with(anything, :the_timeout) + expect(client).to receive(:wait_for_condition).with(anything, :the_timeout) client.wait_for_no_field_value "a_locator", "a value", :timeout_in_seconds => :the_timeout end end describe "#wait_for_visible" do it "uses provided locator" do - client.should_receive(:wait_for_condition).with("selenium.isVisible('a_locator')", anything) + expect(client).to receive(:wait_for_condition).with("selenium.isVisible('a_locator')", anything) client.wait_for_visible "a_locator" end it "uses explicit timeout when provided" do - client.should_receive(:wait_for_condition).with(anything, :the_timeout) + expect(client).to receive(:wait_for_condition).with(anything, :the_timeout) client.wait_for_visible "a_locator", :timeout_in_seconds => :the_timeout end end describe "#wait_for_not_visible" do it "uses provided locator" do - client.should_receive(:wait_for_condition).with("!selenium.isVisible('a_locator')", anything) + expect(client).to receive(:wait_for_condition).with("!selenium.isVisible('a_locator')", anything) client.wait_for_not_visible "a_locator" end it "uses explicit timeout when provided" do - client.should_receive(:wait_for_condition).with(anything, :the_timeout) + expect(client).to receive(:wait_for_condition).with(anything, :the_timeout) client.wait_for_not_visible "a_locator", :timeout_in_seconds => :the_timeout end end diff --git a/rb/spec/unit/selenium/client/idiomatic_spec.rb b/rb/spec/unit/selenium/client/idiomatic_spec.rb index bccc6afc2a5d8..27a648ec43c54 100644 --- a/rb/spec/unit/selenium/client/idiomatic_spec.rb +++ b/rb/spec/unit/selenium/client/idiomatic_spec.rb @@ -27,201 +27,201 @@ class IdiomaticClient let(:client) { IdiomaticClient.new } it "has #text is an alias for get_text" do - client.should_receive(:string_command).with("getText", [:the_locator,]).and_return(:the_text) - client.text(:the_locator).should == :the_text + expect(client).to receive(:string_command).with("getText", [:the_locator,]).and_return(:the_text) + expect(client.text(:the_locator)).to eq(:the_text) end it "#title returns the result of the getTitle command" do - client.should_receive(:string_command).with("getTitle").and_return(:the_title) - client.title.should == :the_title + expect(client).to receive(:string_command).with("getTitle").and_return(:the_title) + expect(client.title).to eq(:the_title) end it "#location returns the result of the getLocation command" do - client.should_receive(:string_command).with("getLocation").and_return(:the_location) - client.location.should == :the_location + expect(client).to receive(:string_command).with("getLocation").and_return(:the_location) + expect(client.location).to eq(:the_location) end describe "#wait_for_page" do it "waits for a page to load, converting seconds timeout to milliseconds" do - client.should_receive(:remote_control_command).with("waitForPageToLoad", [2000,]) + expect(client).to receive(:remote_control_command).with("waitForPageToLoad", [2000,]) client.wait_for_page 2 end it "waits for a page to load with the default timeout when none is specified" do - client.should_receive(:remote_control_command).with("waitForPageToLoad", [7000,]) - client.stub(:default_timeout_in_seconds).and_return(7) + expect(client).to receive(:remote_control_command).with("waitForPageToLoad", [7000,]) + allow(client).to receive(:default_timeout_in_seconds).and_return(7) client.wait_for_page end it "waits for a page to load with a string timeout for backward compatibility" do - client.should_receive(:remote_control_command).with("waitForPageToLoad", [2000,]) + expect(client).to receive(:remote_control_command).with("waitForPageToLoad", [2000,]) client.wait_for_page "2" end it "has #wait_for_page_to_load as an alias providing easy transition to people used to the old API" do - client.should_receive(:remote_control_command).with("waitForPageToLoad", [24000,]) + expect(client).to receive(:remote_control_command).with("waitForPageToLoad", [24000,]) client.wait_for_page_to_load 24 end end describe "#wait_for_popup" do it "returns the result of the waitForPopUp command" do - client.should_receive(:remote_control_command).with("waitForPopUp", [:the_window_id, 0]).and_return(:the_value) - client.wait_for_popup(:the_window_id, 0).should == :the_value + expect(client).to receive(:remote_control_command).with("waitForPopUp", [:the_window_id, 0]).and_return(:the_value) + expect(client.wait_for_popup(:the_window_id, 0)).to eq(:the_value) end it "converts the timeout from seconds to milliseconds" do - client.should_receive(:remote_control_command).with("waitForPopUp", [:the_window_id, 3000]).and_return(:the_value) - client.wait_for_popup(:the_window_id, 3).should == :the_value + expect(client).to receive(:remote_control_command).with("waitForPopUp", [:the_window_id, 3000]).and_return(:the_value) + expect(client.wait_for_popup(:the_window_id, 3)).to eq(:the_value) end it "accepts timeout as a string for backward compatibility" do - client.should_receive(:remote_control_command).with("waitForPopUp", [:the_window_id, 5000]).and_return(:the_value) - client.wait_for_popup(:the_window_id, "5").should == :the_value + expect(client).to receive(:remote_control_command).with("waitForPopUp", [:the_window_id, 5000]).and_return(:the_value) + expect(client.wait_for_popup(:the_window_id, "5")).to eq(:the_value) end it "uses the default timeout when none is specified" do - client.should_receive(:remote_control_command).with("waitForPopUp", [:the_window_id, 7000]).and_return(:the_value) - client.stub(:default_timeout_in_seconds).and_return(7) + expect(client).to receive(:remote_control_command).with("waitForPopUp", [:the_window_id, 7000]).and_return(:the_value) + allow(client).to receive(:default_timeout_in_seconds).and_return(7) client.wait_for_popup :the_window_id end end describe "#wait_for_condition" do it "waits for a page to load using the default timeout when none is specified" do - client.should_receive(:remote_control_command).with("waitForCondition", ["some javascript", 7000,]) - client.stub(:default_timeout_in_seconds).and_return(7) + expect(client).to receive(:remote_control_command).with("waitForCondition", ["some javascript", 7000,]) + allow(client).to receive(:default_timeout_in_seconds).and_return(7) client.wait_for_condition "some javascript" end it "waits for a page to load using the given timeout converted to milliseconds" do - client.should_receive(:remote_control_command).with("waitForCondition", ["some javascript", 24000,]) - client.stub(:default_timeout_in_seconds).and_return(7) + expect(client).to receive(:remote_control_command).with("waitForCondition", ["some javascript", 24000,]) + allow(client).to receive(:default_timeout_in_seconds).and_return(7) client.wait_for_condition "some javascript", 24 end it "accepts timeout as a string for backward compatibility" do - client.should_receive(:remote_control_command).with("waitForCondition", ["some javascript", 64000,]) - client.stub(:default_timeout_in_seconds).and_return(7) + expect(client).to receive(:remote_control_command).with("waitForCondition", ["some javascript", 64000,]) + allow(client).to receive(:default_timeout_in_seconds).and_return(7) client.wait_for_condition "some javascript", "64" end end describe "#wait_for" do it "does nothing when no options are given" do - client.should_receive(:remote_control_command).never + expect(client).to receive(:remote_control_command).never client.wait_for({}) end it "waits for page with explicit timeout when one is provided" do - client.should_receive(:wait_for_page).with(:the_timeout) + expect(client).to receive(:wait_for_page).with(:the_timeout) client.wait_for :wait_for => :page, :timeout_in_seconds => :the_timeout end it "waits for ajax to complete when ajax option is provided" do - client.should_receive(:wait_for_ajax) + expect(client).to receive(:wait_for_ajax) client.wait_for :wait_for => :ajax end it "waits for ajax using the given javascript framework override" do - client.should_receive(:wait_for_ajax).with(hash_including(:javascript_framework => :jquery)) + expect(client).to receive(:wait_for_ajax).with(hash_including(:javascript_framework => :jquery)) client.wait_for :wait_for => :ajax, :javascript_framework => :jquery end it "waits for ajax with explicit timeout when one is provided" do - client.should_receive(:wait_for_ajax).with(hash_including(:timeout_in_seconds => :the_timeout)) + expect(client).to receive(:wait_for_ajax).with(hash_including(:timeout_in_seconds => :the_timeout)) client.wait_for :wait_for => :ajax, :timeout_in_seconds => :the_timeout end it "waits for element to be present when element option is provided" do - client.should_receive(:wait_for_element).with(:the_new_element_id, anything) + expect(client).to receive(:wait_for_element).with(:the_new_element_id, anything) client.wait_for :wait_for => :element, :element => :the_new_element_id end it "waits for element with explicit timeout when one is provided" do - client.should_receive(:wait_for_element).with(:the_new_element_id, hash_including(:timeout_in_seconds => :the_timeout)) + expect(client).to receive(:wait_for_element).with(:the_new_element_id, hash_including(:timeout_in_seconds => :the_timeout)) client.wait_for :wait_for => :element, :element => :the_new_element_id, :timeout_in_seconds => :the_timeout end it "waits for no element to be present when no_element option is provided" do - client.should_receive(:wait_for_no_element).with(:the_new_element_id, hash_including(:element => :the_new_element_id)) + expect(client).to receive(:wait_for_no_element).with(:the_new_element_id, hash_including(:element => :the_new_element_id)) client.wait_for :wait_for => :no_element, :element => :the_new_element_id end it "waits for no element with explicit timeout when one is provided" do - client.should_receive(:wait_for_no_element).with(:the_new_element_id, hash_including(:element => :the_new_element_id, :timeout_in_seconds => :the_timeout)) + expect(client).to receive(:wait_for_no_element).with(:the_new_element_id, hash_including(:element => :the_new_element_id, :timeout_in_seconds => :the_timeout)) client.wait_for :wait_for => :no_element, :element => :the_new_element_id, :timeout_in_seconds => :the_timeout end it "waits for text to be present when text option is provided" do - client.should_receive(:wait_for_text).with("some text", hash_including(:element => "a locator", :text => "some text")) + expect(client).to receive(:wait_for_text).with("some text", hash_including(:element => "a locator", :text => "some text")) client.wait_for :wait_for => :text, :element => "a locator", :text => "some text" end it "waits for text with explicit timeout when one is provided" do - client.should_receive(:wait_for_text).with("some text", hash_including(:timeout_in_seconds => :the_timeout)) + expect(client).to receive(:wait_for_text).with("some text", hash_including(:timeout_in_seconds => :the_timeout)) client.wait_for :wait_for => :text, :text => "some text", :timeout_in_seconds => :the_timeout end it "waits for text to NOT be present when no_text option is provided" do - client.should_receive(:wait_for_no_text).with("some text", hash_including(:element => 'a_locator')) + expect(client).to receive(:wait_for_no_text).with("some text", hash_including(:element => 'a_locator')) client.wait_for :wait_for => :no_text, :element => 'a_locator', :text => "some text" end it "waits for no text with explicit timeout and locator when none are provided" do - client.should_receive(:wait_for_no_text).with("some text", hash_including(:timeout_in_seconds => :the_timeout)) + expect(client).to receive(:wait_for_no_text).with("some text", hash_including(:timeout_in_seconds => :the_timeout)) client.wait_for :wait_for => :no_text, :text => "some text", :timeout_in_seconds => :the_timeout end it "waits for effects to complete when effects option is provided" do - client.should_receive(:wait_for_effects) + expect(client).to receive(:wait_for_effects) client.wait_for :wait_for => :effects end it "waits for effects with explicit timeout when one is provided" do - client.should_receive(:wait_for_effects).with(hash_including(:timeout_in_seconds => :the_timeout)) + expect(client).to receive(:wait_for_effects).with(hash_including(:timeout_in_seconds => :the_timeout)) client.wait_for :wait_for => :effects, :timeout_in_seconds => :the_timeout end it "waits for effects using the given javascript framework override" do - client.should_receive(:wait_for_effects).with(hash_including(:javascript_framework => :jquery)) + expect(client).to receive(:wait_for_effects).with(hash_including(:javascript_framework => :jquery)) client.wait_for :wait_for => :effects, :javascript_framework => :jquery end it "waits for popup to appear when popup option is provided" do - client.should_receive(:wait_for_popup).with(:the_window_id, nil) + expect(client).to receive(:wait_for_popup).with(:the_window_id, nil) client.wait_for :wait_for => :popup, :window => :the_window_id end it "waits for popup with explicit timeout when provided" do - client.should_receive(:wait_for_popup).with(:the_window_id, :the_timeout) + expect(client).to receive(:wait_for_popup).with(:the_window_id, :the_timeout) client.wait_for :wait_for => :popup, :window => :the_window_id, :timeout_in_seconds => :the_timeout end it "selects the popup when the select option is true" do - client.should_receive(:wait_for_popup).with(:the_window_id, nil) - client.should_receive(:select_window).with(:the_window_id) + expect(client).to receive(:wait_for_popup).with(:the_window_id, nil) + expect(client).to receive(:select_window).with(:the_window_id) client.wait_for :wait_for => :popup, :window => :the_window_id, :select => true end it "does not select the popup when the select option is false" do - client.should_receive(:wait_for_popup).with(:the_window_id, nil) - client.should_receive(:select_window).with(:the_window_id).never + expect(client).to receive(:wait_for_popup).with(:the_window_id, nil) + expect(client).to receive(:select_window).with(:the_window_id).never client.wait_for :wait_for => :popup, :window => :the_window_id end it "waits for field value when value option is provided" do - client.should_receive(:wait_for_field_value).with(:the_locator, :expected_value, anything) + expect(client).to receive(:wait_for_field_value).with(:the_locator, :expected_value, anything) client.wait_for :wait_for => :value, :element => :the_locator, :value => :expected_value end it "waits for field using explicit timeout when provided" do - client.should_receive(:wait_for_field_value).with(:the_locator, :expected_value, + expect(client).to receive(:wait_for_field_value).with(:the_locator, :expected_value, hash_including(:timeout_in_seconds => :the_timeout)) client.wait_for :wait_for => :value, :element => :the_locator, @@ -230,12 +230,12 @@ class IdiomaticClient end it "waits for no field value when value option is provided" do - client.should_receive(:wait_for_no_field_value).with(:the_locator, :expected_value, anything) + expect(client).to receive(:wait_for_no_field_value).with(:the_locator, :expected_value, anything) client.wait_for :wait_for => :no_value, :element => :the_locator, :value => :expected_value end it "waits for no field value using explicit timeout when provided" do - client.should_receive(:wait_for_no_field_value).with(:the_locator, + expect(client).to receive(:wait_for_no_field_value).with(:the_locator, :expected_value, hash_including(:timeout_in_seconds => :the_timeout)) client.wait_for :wait_for => :no_value, :element => :the_locator, @@ -244,275 +244,275 @@ class IdiomaticClient end it "waits for element to be visible when visible option is provided" do - client.should_receive(:wait_for_visible).with(:the_locator, anything) + expect(client).to receive(:wait_for_visible).with(:the_locator, anything) client.wait_for :wait_for => :visible, :element => :the_locator, :value => :expected_value end it "waits for element to be visible using explicit timeout when provided" do - client.should_receive(:wait_for_visible).with(:the_locator, + expect(client).to receive(:wait_for_visible).with(:the_locator, hash_including(:timeout_in_seconds => :the_timeout)) client.wait_for :wait_for => :visible, :element => :the_locator, :timeout_in_seconds => :the_timeout end it "waits for element to not be visible when visible option is provided" do - client.should_receive(:wait_for_not_visible).with(:the_locator, anything) + expect(client).to receive(:wait_for_not_visible).with(:the_locator, anything) client.wait_for :wait_for => :not_visible, :element => :the_locator, :value => :expected_value end it "waits for element to not be visible using explicit timeout when provided" do - client.should_receive(:wait_for_not_visible).with(:the_locator, + expect(client).to receive(:wait_for_not_visible).with(:the_locator, hash_including(:timeout_in_seconds => :the_timeout)) client.wait_for :wait_for => :not_visible, :element => :the_locator, :timeout_in_seconds => :the_timeout end it "waits for given javascript to return true when condition option is provided" do - client.should_receive(:wait_for_condition).with("some javascript", nil) + expect(client).to receive(:wait_for_condition).with("some javascript", nil) client.wait_for :wait_for => :condition, :javascript => "some javascript" end end describe "#body_text" do it "returns the result of the getBodyText command" do - client.should_receive(:string_command).with("getBodyText").and_return(:the_text) - client.body_text.should == :the_text + expect(client).to receive(:string_command).with("getBodyText").and_return(:the_text) + expect(client.body_text).to eq(:the_text) end end describe "#click" do it "clicks on an element when no options are given" do - client.should_receive(:remote_control_command).with("click", [:the_locator,]) + expect(client).to receive(:remote_control_command).with("click", [:the_locator,]) client.click :the_locator end it "calls wait_for with options provided" do - client.should_receive(:remote_control_command).with("click", [:the_locator,]) - client.should_receive(:wait_for).with(:wait_for => :page) + expect(client).to receive(:remote_control_command).with("click", [:the_locator,]) + expect(client).to receive(:wait_for).with(:wait_for => :page) client.click :the_locator, :wait_for => :page end end describe "#value" do it "value returns the result of the getValue command" do - client.should_receive(:string_command).with("getValue", [:the_locator,]).and_return(:the_value) - client.value(:the_locator).should == :the_value + expect(client).to receive(:string_command).with("getValue", [:the_locator,]).and_return(:the_value) + expect(client.value(:the_locator)).to eq(:the_value) end end describe "#field" do it "field returns the result of the getValue command" do - client.should_receive(:string_command).with("getValue", [:the_locator,]).and_return(:the_value) - client.field(:the_locator).should == :the_value + expect(client).to receive(:string_command).with("getValue", [:the_locator,]).and_return(:the_value) + expect(client.field(:the_locator)).to eq(:the_value) end end describe "#checked?" do it "checked? returns the result of the isChecked command" do - client.should_receive(:boolean_command).with("isChecked", [:the_locator,]).and_return(:the_value) - client.checked?(:the_locator).should == :the_value + expect(client).to receive(:boolean_command).with("isChecked", [:the_locator,]).and_return(:the_value) + expect(client.checked?(:the_locator)).to eq(:the_value) end end describe "#text?" do it "returns the result of the isTextPresent command" do - client.should_receive(:boolean_command).with("isTextPresent", [:the_pattern,]).and_return(:the_result) - client.text?(:the_pattern).should == :the_result + expect(client).to receive(:boolean_command).with("isTextPresent", [:the_pattern,]).and_return(:the_result) + expect(client.text?(:the_pattern)).to eq(:the_result) end end describe "#element?" do it "returns the result of the isElementPresent command" do - client.should_receive(:boolean_command).with("isElementPresent", [:the_locator,]).and_return(:the_result) - client.element?(:the_locator).should == :the_result + expect(client).to receive(:boolean_command).with("isElementPresent", [:the_locator,]).and_return(:the_result) + expect(client.element?(:the_locator)).to eq(:the_result) end end describe "visible?" do it "returns the result of the isTextPresent command" do - client.should_receive(:boolean_command).with("isVisible", [:the_locator,]).and_return(:the_result) - client.visible?(:the_locator).should == :the_result + expect(client).to receive(:boolean_command).with("isVisible", [:the_locator,]).and_return(:the_result) + expect(client.visible?(:the_locator)).to eq(:the_result) end end describe "#alert? or #alert" do it "returns the result of the isAlertPresent command" do - client.should_receive(:boolean_command).with("isAlertPresent").and_return(:the_result) - client.alert?.should == :the_result + expect(client).to receive(:boolean_command).with("isAlertPresent").and_return(:the_result) + expect(client.alert?).to eq(:the_result) end it "returns the result of the getAlert command" do - client.should_receive(:string_command).with("getAlert").and_return(:the_result) - client.alert.should == :the_result + expect(client).to receive(:string_command).with("getAlert").and_return(:the_result) + expect(client.alert).to eq(:the_result) end end describe "#confirmation? or #confirmation" do it "returns the result of the isConfirmationPresent command" do - client.should_receive(:boolean_command).with("isConfirmationPresent").and_return(:the_result) - client.confirmation?.should == :the_result + expect(client).to receive(:boolean_command).with("isConfirmationPresent").and_return(:the_result) + expect(client.confirmation?).to eq(:the_result) end it "returns the result of the getConfirmation command" do - client.should_receive(:string_command).with("getConfirmation").and_return(:the_result) - client.confirmation.should == :the_result + expect(client).to receive(:string_command).with("getConfirmation").and_return(:the_result) + expect(client.confirmation).to eq(:the_result) end end describe "#prompt? and #prompt" do it "prompt? returns the result of the isPromptPresent command" do - client.should_receive(:boolean_command).with("isPromptPresent").and_return(:the_result) - client.prompt?.should == :the_result + expect(client).to receive(:boolean_command).with("isPromptPresent").and_return(:the_result) + expect(client.prompt?).to eq(:the_result) end it "prompt returns the result of the getPrompt command" do - client.should_receive(:string_command).with("getPrompt").and_return(:the_result) - client.prompt.should == :the_result + expect(client).to receive(:string_command).with("getPrompt").and_return(:the_result) + expect(client.prompt).to eq(:the_result) end it "prompt returns the result of the getEval command" do - client.should_receive(:string_command).with("getEval", [:the_script,]).and_return(:the_result) - client.js_eval(:the_script).should == :the_result + expect(client).to receive(:string_command).with("getEval", [:the_script,]).and_return(:the_result) + expect(client.js_eval(:the_script)).to eq(:the_result) end end describe "table_cell_text" do it "table_cell_text returns the result of the getTable command" do - client.should_receive(:string_command).with("getTable", [:the_cell_address,]).and_return(:the_value) - client.table_cell_text(:the_cell_address).should == :the_value + expect(client).to receive(:string_command).with("getTable", [:the_cell_address,]).and_return(:the_value) + expect(client.table_cell_text(:the_cell_address)).to eq(:the_value) end end describe "#cookies, #cookie, #cookie?" do it "returns the result of the getCookie command" do - client.should_receive(:string_command).with("getCookie").and_return(:the_value) - client.cookies.should == :the_value + expect(client).to receive(:string_command).with("getCookie").and_return(:the_value) + expect(client.cookies).to eq(:the_value) end it "returns the result of the getCookieByName command" do - client.should_receive(:string_command).with("getCookieByName", [:the_name,]).and_return(:the_value) - client.cookie(:the_name).should == :the_value + expect(client).to receive(:string_command).with("getCookieByName", [:the_name,]).and_return(:the_value) + expect(client.cookie(:the_name)).to eq(:the_value) end it "returns the result of the isCookiePresent command" do - client.should_receive(:boolean_command).with("isCookiePresent", [:the_name,]).and_return(:the_value) - client.cookie?(:the_name).should == :the_value + expect(client).to receive(:boolean_command).with("isCookiePresent", [:the_name,]).and_return(:the_value) + expect(client.cookie?(:the_name)).to eq(:the_value) end end describe "#create_cookie" do it "returns the result of the createCookie command" do - client.should_receive(:remote_control_command).with("createCookie", [:the_name_value_pair, "options"]).and_return(:the_value) - client.create_cookie(:the_name_value_pair, "options").should == :the_value + expect(client).to receive(:remote_control_command).with("createCookie", [:the_name_value_pair, "options"]).and_return(:the_value) + expect(client.create_cookie(:the_name_value_pair, "options")).to eq(:the_value) end it "returns the result of the createCookie command when no options are given" do - client.should_receive(:remote_control_command).with("createCookie", [:the_name_value_pair, ""]).and_return(:the_value) - client.create_cookie(:the_name_value_pair).should == :the_value + expect(client).to receive(:remote_control_command).with("createCookie", [:the_name_value_pair, ""]).and_return(:the_value) + expect(client.create_cookie(:the_name_value_pair)).to eq(:the_value) end it "converts hash options to cookie strings" do - client.should_receive(:remote_control_command).with do |cmd, args| - cmd.should == "createCookie" + expect(client).to receive(:remote_control_command) { |cmd, args| + expect(cmd).to eq("createCookie") - args.size.should == 2 - args.first.should == :the_name_value_pair - [ "max_age=60, domain=.foo.com", - "domain=.foo.com, max_age=60" ].should include(args.last) - end.and_return(:the_value) + expect(args.size).to eq(2) + expect(args.first).to eq(:the_name_value_pair) + expect([ "max_age=60, domain=.foo.com", + "domain=.foo.com, max_age=60" ]).to include(args.last) + }.and_return(:the_value) result = client.create_cookie(:the_name_value_pair, {:max_age => 60, :domain => ".foo.com"}) - result.should == :the_value + expect(result).to eq(:the_value) end end describe "#delete_cookie" do it "returns the result of the createCookie command" do - client.should_receive(:remote_control_command).with("deleteCookie", [:the_name, "options"]).and_return(:the_value) - client.delete_cookie(:the_name, "options").should == :the_value + expect(client).to receive(:remote_control_command).with("deleteCookie", [:the_name, "options"]).and_return(:the_value) + expect(client.delete_cookie(:the_name, "options")).to eq(:the_value) end it "options are optional for delete_cookie when no options are given" do - client.should_receive(:remote_control_command).with("deleteCookie", [:the_name, ""]).and_return(:the_value) - client.delete_cookie(:the_name).should == :the_value + expect(client).to receive(:remote_control_command).with("deleteCookie", [:the_name, ""]).and_return(:the_value) + expect(client.delete_cookie(:the_name)).to eq(:the_value) end it "converts hash options to cookie strings" do - client.should_receive(:remote_control_command).with("deleteCookie", [:the_name, "domain=.foo.com, max_age=60"]).and_return(:the_value) + expect(client).to receive(:remote_control_command).with("deleteCookie", [:the_name, "domain=.foo.com, max_age=60"]).and_return(:the_value) result = client.delete_cookie(:the_name, {:max_age => 60, :domain => ".foo.com"}) - result.should == :the_value + expect(result).to eq(:the_value) end end describe "#all_window_ids, #all_window_titles or #all_window_names" do it "returns the result of the getAllWindowIds command" do - client.should_receive(:string_array_command).with("getAllWindowIds").and_return(:the_value) - client.all_window_ids.should == :the_value + expect(client).to receive(:string_array_command).with("getAllWindowIds").and_return(:the_value) + expect(client.all_window_ids).to eq(:the_value) end it "returns the result of the getAllWindowNames command" do - client.should_receive(:string_array_command).with("getAllWindowNames").and_return(:the_value) - client.all_window_names.should == :the_value + expect(client).to receive(:string_array_command).with("getAllWindowNames").and_return(:the_value) + expect(client.all_window_names).to eq(:the_value) end it "returns the result of the getAllWindowTitles command" do - client.should_receive(:string_array_command).with("getAllWindowTitles").and_return(:the_value) - client.all_window_titles.should == :the_value + expect(client).to receive(:string_array_command).with("getAllWindowTitles").and_return(:the_value) + expect(client.all_window_titles).to eq(:the_value) end end describe "#browser_network_traffic" do it "returns the result of the captureNetworkTraffic command" do - client.should_receive(:remote_control_command).with("captureNetworkTraffic", ["json"]).and_return(:the_value) - client.browser_network_traffic(:json).should == :the_value + expect(client).to receive(:remote_control_command).with("captureNetworkTraffic", ["json"]).and_return(:the_value) + expect(client.browser_network_traffic(:json)).to eq(:the_value) end it "uses plain as the default format" do - client.should_receive(:remote_control_command).with("captureNetworkTraffic", ["plain"]).and_return(:the_value) - client.browser_network_traffic.should == :the_value + expect(client).to receive(:remote_control_command).with("captureNetworkTraffic", ["plain"]).and_return(:the_value) + expect(client.browser_network_traffic).to eq(:the_value) end it "raises a RuntimeError when format is nil" do - lambda { client.browser_network_traffic(nil) }.should raise_error(RuntimeError) + expect { client.browser_network_traffic(nil) }.to raise_error(RuntimeError) end it "raises a RuntimeError when format is an unknown format" do - lambda { client.browser_network_traffic(:random_format) }.should raise_error(RuntimeError) + expect { client.browser_network_traffic(:random_format) }.to raise_error(RuntimeError) end end describe "#browser_xpath_library=" do it "invokes the useXpathLibrary command" do - client.should_receive(:remote_control_command).with("useXpathLibrary", ["ajaxslt"]).and_return(:the_value) + expect(client).to receive(:remote_control_command).with("useXpathLibrary", ["ajaxslt"]).and_return(:the_value) client.browser_xpath_library = :ajaxslt end it "raises a RuntimeError whe library name is unknown" do - lambda { client.browser_xpath_library = :random_library }.should raise_error(RuntimeError) + expect { client.browser_xpath_library = :random_library }.to raise_error(RuntimeError) end end describe "#highlight_located_element=" do it "setting highlight_located_element to true enables auto-hilighting in selenium core" do - client.should_receive(:js_eval).with("selenium.browserbot.shouldHighlightLocatedElement = true") + expect(client).to receive(:js_eval).with("selenium.browserbot.shouldHighlightLocatedElement = true") client.highlight_located_element = true end it "setting highlight_located_element to false disables auto-hilighting in selenium core" do - client.should_receive(:js_eval).with("selenium.browserbot.shouldHighlightLocatedElement = false") + expect(client).to receive(:js_eval).with("selenium.browserbot.shouldHighlightLocatedElement = false") client.highlight_located_element = false end end describe "#execution_delay or #execution_delay=" do it "execution_delay returns the result of the getSpeed command" do - client.should_receive(:string_command).with("getSpeed").and_return(:the_speed) - client.execution_delay.should == :the_speed + expect(client).to receive(:string_command).with("getSpeed").and_return(:the_speed) + expect(client.execution_delay).to eq(:the_speed) end it "execution_delay= executes the setSpeed command" do - client.should_receive(:remote_control_command).with("setSpeed", [24]) + expect(client).to receive(:remote_control_command).with("setSpeed", [24]) client.execution_delay= 24 end end diff --git a/rb/spec/unit/selenium/client/javascript_expression_builder_spec.rb b/rb/spec/unit/selenium/client/javascript_expression_builder_spec.rb index 26528fc973fa1..6473a05c93a81 100644 --- a/rb/spec/unit/selenium/client/javascript_expression_builder_spec.rb +++ b/rb/spec/unit/selenium/client/javascript_expression_builder_spec.rb @@ -26,73 +26,73 @@ def builder(*args) it "can append arbitrary text to builder" do builder.append("hello").append(" world") - builder.script.should == "hello world" + expect(builder.script).to eq("hello world") end it "returns the correct #no_pending_ajax_requests script for Prototype" do builder = builder(:prototype) - builder.no_pending_ajax_requests.script.should == "selenium.browserbot.getCurrentWindow().Ajax.activeRequestCount == 0;" + expect(builder.no_pending_ajax_requests.script).to eq("selenium.browserbot.getCurrentWindow().Ajax.activeRequestCount == 0;") end it "returns the correct #no_pending_ajax_requests script for jQuery" do builder = builder(:jquery) - builder.no_pending_ajax_requests.script.should == "selenium.browserbot.getCurrentWindow().jQuery.active == 0;" + expect(builder.no_pending_ajax_requests.script).to eq("selenium.browserbot.getCurrentWindow().jQuery.active == 0;") end it "returns the correct #no_pending_effects for Prototype" do builder = builder(:prototype) - builder.no_pending_effects.script.should == "selenium.browserbot.getCurrentWindow().Effect.Queue.size() == 0;" + expect(builder.no_pending_effects.script).to eq("selenium.browserbot.getCurrentWindow().Effect.Queue.size() == 0;") end describe "#quote_escaped" do it "returns a locator as is when it has no single quotes" do - builder.quote_escaped("the_locator").should == "the_locator" + expect(builder.quote_escaped("the_locator")).to eq("the_locator") end it "escapes single quotes" do - builder.quote_escaped("//div[@id='demo-effect-appear']").should == "//div[@id=\\'demo-effect-appear\\']" + expect(builder.quote_escaped("//div[@id='demo-effect-appear']")).to eq("//div[@id=\\'demo-effect-appear\\']") end it "escapes backslashes" do - builder.quote_escaped("webratlink=evalregex:/Pastry Lovers \\(Organizer\\)/").should == "webratlink=evalregex:/Pastry Lovers \\\\(Organizer\\\\)/" + expect(builder.quote_escaped("webratlink=evalregex:/Pastry Lovers \\(Organizer\\)/")).to eq("webratlink=evalregex:/Pastry Lovers \\\\(Organizer\\\\)/") end end describe "#text_match" do it "matches on entire string when pattern is a string" do - builder.text_match("some text").should == "element.innerHTML == 'some text'" + expect(builder.text_match("some text")).to eq("element.innerHTML == 'some text'") end it "performs a regexp match when pattern is a regexp" do - builder.text_match(/some text/).should == "null != element.innerHTML.match(/some text/)" + expect(builder.text_match(/some text/)).to eq("null != element.innerHTML.match(/some text/)") end it "escapes rexpexp when pattern is a regexp" do - builder.text_match(/some.*text/).should == "null != element.innerHTML.match(/some.*text/)" + expect(builder.text_match(/some.*text/)).to eq("null != element.innerHTML.match(/some.*text/)") end end describe "#find_element" do it "adds a script to find an element" do - builder.find_element('a_locator').script.should =~ /element\s+=\s+selenium.browserbot.findElement\('a_locator'\);/m + expect(builder.find_element('a_locator').script).to match(/element\s+=\s+selenium.browserbot.findElement\('a_locator'\);/m) end it "should handle embedded evalregex locators" do - builder.find_element("webratlink=evalregex:/Pastry Lovers \\(Organizer\\)/").script.should =~ /element\s+=\s+selenium.browserbot.findElement\('webratlink=evalregex:\/Pastry Lovers \\\\\(Organizer\\\\\)\/'\);/m + expect(builder.find_element("webratlink=evalregex:/Pastry Lovers \\(Organizer\\)/").script).to match(/element\s+=\s+selenium.browserbot.findElement\('webratlink=evalregex:\/Pastry Lovers \\\\\(Organizer\\\\\)\/'\);/m) end end describe "#javascript_framework_for" do it "returns JavascriptFrameworks::Prototype when argument is :prototype" do - builder.javascript_framework_for(:prototype).should == Selenium::Client::JavascriptFrameworks::Prototype + expect(builder.javascript_framework_for(:prototype)).to eq(Selenium::Client::JavascriptFrameworks::Prototype) end it "returns JavascriptFrameworks::JQuery when argument is :jquery" do - builder.javascript_framework_for(:jquery).should == Selenium::Client::JavascriptFrameworks::JQuery + expect(builder.javascript_framework_for(:jquery)).to eq(Selenium::Client::JavascriptFrameworks::JQuery) end it "raises a Runtime for unsupported frameworks" do - lambda { builder.javascript_framework_for(:unsupported_framework) }.should raise_error(RuntimeError) + expect { builder.javascript_framework_for(:unsupported_framework) }.to raise_error(RuntimeError) end end end diff --git a/rb/spec/unit/selenium/client/javascript_frameworks/jquery_spec.rb b/rb/spec/unit/selenium/client/javascript_frameworks/jquery_spec.rb index ec26ddc233876..53f55d4e42994 100644 --- a/rb/spec/unit/selenium/client/javascript_frameworks/jquery_spec.rb +++ b/rb/spec/unit/selenium/client/javascript_frameworks/jquery_spec.rb @@ -23,7 +23,7 @@ it "returns 'jQuery.active'" do art = Selenium::Client::JavascriptFrameworks::JQuery.ajax_request_tracker - art.should == "jQuery.active" + expect(art).to eq("jQuery.active") end end \ No newline at end of file diff --git a/rb/spec/unit/selenium/client/javascript_frameworks/prototype_spec.rb b/rb/spec/unit/selenium/client/javascript_frameworks/prototype_spec.rb index cab9be82e9166..f59b41c5a8c8f 100644 --- a/rb/spec/unit/selenium/client/javascript_frameworks/prototype_spec.rb +++ b/rb/spec/unit/selenium/client/javascript_frameworks/prototype_spec.rb @@ -23,7 +23,7 @@ it "returns 'Ajax.activeRequestCount'" do art = Selenium::Client::JavascriptFrameworks::Prototype.ajax_request_tracker - art.should == "Ajax.activeRequestCount" + expect(art).to eq("Ajax.activeRequestCount") end end \ No newline at end of file diff --git a/rb/spec/unit/selenium/client/protocol_spec.rb b/rb/spec/unit/selenium/client/protocol_spec.rb index 5445a2a009986..8ca3620864834 100644 --- a/rb/spec/unit/selenium/client/protocol_spec.rb +++ b/rb/spec/unit/selenium/client/protocol_spec.rb @@ -29,115 +29,115 @@ class ProtocolClient describe "#remote_control_command" do it "returns the content of the HTTP response when the command succeeds" do client.instance_variable_set :@default_timeout_in_seconds, 1 - client.stub(:http_request_for).with(:a_verb, :some_args).and_return(:the_request) - client.should_receive(:http_post).with(:the_request).and_return(["OK", "OK,the response"]) - client.remote_control_command(:a_verb, :some_args).should == "the response" + allow(client).to receive(:http_request_for).with(:a_verb, :some_args).and_return(:the_request) + expect(client).to receive(:http_post).with(:the_request).and_return(["OK", "OK,the response"]) + expect(client.remote_control_command(:a_verb, :some_args)).to eq("the response") end it "raises a SeleniumCommandError when the command fails" do client.instance_variable_set :@default_timeout_in_seconds, 1 - client.stub(:http_request_for).with(:a_verb, :some_args).and_return(:the_request) - client.should_receive(:http_post).with(:the_request).and_return(["ER", "ERROR,the error message"]) - lambda { client.remote_control_command(:a_verb, :some_args) }.should raise_error(Selenium::Client::CommandError) + allow(client).to receive(:http_request_for).with(:a_verb, :some_args).and_return(:the_request) + expect(client).to receive(:http_post).with(:the_request).and_return(["ER", "ERROR,the error message"]) + expect { client.remote_control_command(:a_verb, :some_args) }.to raise_error(Selenium::Client::CommandError) end it "succeeds when given zero args" do client.instance_variable_set :@default_timeout_in_seconds, 1 - client.should_receive(:http_request_for).with(:a_verb, []).and_return(:the_request) - client.stub(:http_post).with(:the_request).and_return(["OK", "OK,the response"]) + expect(client).to receive(:http_request_for).with(:a_verb, []).and_return(:the_request) + allow(client).to receive(:http_post).with(:the_request).and_return(["OK", "OK,the response"]) client.remote_control_command(:a_verb) end end describe "#string_command" do it "returns the selenese command response" do - client.should_receive(:remote_control_command).with(:a_verb, :some_args).and_return("A String") - client.string_command(:a_verb, :some_args).should == "A String" + expect(client).to receive(:remote_control_command).with(:a_verb, :some_args).and_return("A String") + expect(client.string_command(:a_verb, :some_args)).to eq("A String") end it "succeeds when given zero args" do - client.should_receive(:remote_control_command).with(:a_verb, []) + expect(client).to receive(:remote_control_command).with(:a_verb, []) client.string_command:a_verb end end describe "#get_string" do # private? it "parses the command response as a CSV row" do - client.should_receive(:remote_control_command).with(:a_verb, :some_args).and_return("One,Two,Three") - client.string_array_command(:a_verb, :some_args).should == ["One", "Two", "Three"] + expect(client).to receive(:remote_control_command).with(:a_verb, :some_args).and_return("One,Two,Three") + expect(client.string_array_command(:a_verb, :some_args)).to eq(["One", "Two", "Three"]) end it "preserves spaces" do - client.should_receive(:remote_control_command).with(:a_verb, :some_args).and_return(" One , Two & Three ") - client.string_array_command(:a_verb, :some_args).should == [" One ", " Two & Three "] + expect(client).to receive(:remote_control_command).with(:a_verb, :some_args).and_return(" One , Two & Three ") + expect(client.string_array_command(:a_verb, :some_args)).to eq([" One ", " Two & Three "]) end it "ignores commas escaped with a backspace" do - client.should_receive(:remote_control_command).with(:a_verb, :some_args).and_return("One,Two\\,Three") - client.string_array_command(:a_verb, :some_args).should == ["One", "Two,Three"] + expect(client).to receive(:remote_control_command).with(:a_verb, :some_args).and_return("One,Two\\,Three") + expect(client.string_array_command(:a_verb, :some_args)).to eq(["One", "Two,Three"]) end end describe "parse_boolean_value" do it "returns true when string is true" do - client.send(:parse_boolean_value, "true").should == true + expect(client.send(:parse_boolean_value, "true")).to eq(true) end it "returns false when string is false" do - client.send(:parse_boolean_value, "false").should == false + expect(client.send(:parse_boolean_value, "false")).to eq(false) end it "parse_boolean_value raise a ProtocolError when string is neither true nor false" do - lambda { + expect { client.send(:parse_boolean_value, "unexpected") - }.should raise_error(Selenium::Client::ProtocolError, "Invalid Selenese boolean value that is neither 'true' nor 'false': got 'unexpected'") + }.to raise_error(Selenium::Client::ProtocolError, "Invalid Selenese boolean value that is neither 'true' nor 'false': got 'unexpected'") end end describe "#boolean_command or #boolean_array_command" do it "returns true when string_command returns 'true'" do - client.stub(:string_command).with(:a_verb, :some_args).and_return("true") - client.boolean_command(:a_verb, :some_args).should == true + allow(client).to receive(:string_command).with(:a_verb, :some_args).and_return("true") + expect(client.boolean_command(:a_verb, :some_args)).to eq(true) end it "succeeds when given zero args" do - client.should_receive(:string_command).with(:a_verb, []).and_return("true") + expect(client).to receive(:string_command).with(:a_verb, []).and_return("true") client.boolean_command(:a_verb) end it "returns false when string_command returns 'false'" do - client.stub(:string_command).with(:a_verb, :some_args).and_return("false") - client.boolean_command(:a_verb, :some_args).should == false + allow(client).to receive(:string_command).with(:a_verb, :some_args).and_return("false") + expect(client.boolean_command(:a_verb, :some_args)).to eq(false) end it "returns an array of evaluated boolean values" do - client.stub(:string_array_command).with(:a_verb, :some_args). + allow(client).to receive(:string_array_command).with(:a_verb, :some_args). and_return(["true", "false", "true", "true", "false"]) - client.boolean_array_command(:a_verb, :some_args).should == [true, false, true, true, false] + expect(client.boolean_array_command(:a_verb, :some_args)).to eq([true, false, true, true, false]) end end describe "#http_request_for" do it "returns cmd=verb for a verb" do - client.send(:http_request_for, "aCommand", []).should == "cmd=aCommand" + expect(client.send(:http_request_for, "aCommand", [])).to eq("cmd=aCommand") end it "escapes the command" do - client.send(:http_request_for, "a Command & More", []).should == "cmd=a+Command+%26+More" + expect(client.send(:http_request_for, "a Command & More", [])).to eq("cmd=a+Command+%26+More") end it "adds a session_id parameter when client has a current session id" do - client.stub(:session_id).and_return(24) - client.send(:http_request_for, "aCommand", []).should == "cmd=aCommand&sessionId=24" + allow(client).to receive(:session_id).and_return(24) + expect(client.send(:http_request_for, "aCommand", [])).to eq("cmd=aCommand&sessionId=24") end it "sets args as parameters whose key is their index" do - client.send(:http_request_for, "aCommand", [24, "foo", true]).should == "cmd=aCommand&1=24&2=foo&3=true" + expect(client.send(:http_request_for, "aCommand", [24, "foo", true])).to eq("cmd=aCommand&1=24&2=foo&3=true") end it "escapes arg values" do - client.send(:http_request_for, "aCommand", [ "This & That" ]).should == "cmd=aCommand&1=This+%26+That" + expect(client.send(:http_request_for, "aCommand", [ "This & That" ])).to eq("cmd=aCommand&1=This+%26+That") end end end diff --git a/rb/spec/unit/selenium/client/selenium_helper_spec.rb b/rb/spec/unit/selenium/client/selenium_helper_spec.rb index e993c51805b9d..9b14edd8332be 100644 --- a/rb/spec/unit/selenium/client/selenium_helper_spec.rb +++ b/rb/spec/unit/selenium/client/selenium_helper_spec.rb @@ -35,41 +35,41 @@ class SeleniumHelperClass end it "delegates open to @selenium" do - object.selenium.should_receive(:open).with(:the_url).and_return(:the_result) + expect(object.selenium).to receive(:open).with(:the_url).and_return(:the_result) - object.open(:the_url).should == :the_result + expect(object.open(:the_url)).to eq(:the_result) end it "delegates type to @selenium" do - object.selenium.should_receive(:type).with(:the_locator, :the_value) \ + expect(object.selenium).to receive(:type).with(:the_locator, :the_value) \ .and_return(:the_result) - object.type(:the_locator, :the_value).should == :the_result + expect(object.type(:the_locator, :the_value)).to eq(:the_result) end it "delegates select to @selenium" do - object.selenium.should_receive(:type).with(:the_input_locator, + expect(object.selenium).to receive(:type).with(:the_input_locator, :the_option_locator) \ .and_return(:the_result) - object.type(:the_input_locator, :the_option_locator).should == :the_result + expect(object.type(:the_input_locator, :the_option_locator)).to eq(:the_result) end it "delegates to any no-arg method defined on @selenium" do - object.selenium.should_receive(:a_noarg_method).with().and_return(:the_result) + expect(object.selenium).to receive(:a_noarg_method).with(no_args).and_return(:the_result) - object.a_noarg_method.should == :the_result + expect(object.a_noarg_method).to eq(:the_result) end it "delegates to any arg method defined on @selenium" do - object.selenium.should_receive(:a_method).with(:alpha, :beta)\ + expect(object.selenium).to receive(:a_method).with(:alpha, :beta)\ .and_return(:the_result) - object.a_method(:alpha, :beta).should == :the_result + expect(object.a_method(:alpha, :beta)).to eq(:the_result) end it "calls default method_missing when a method is not defined on @selenium" do - lambda { object.a_method(:alpha, :beta) }.should raise_error(NoMethodError) + expect { object.a_method(:alpha, :beta) }.to raise_error(NoMethodError) end end diff --git a/rb/spec/unit/selenium/rake/task_spec.rb b/rb/spec/unit/selenium/rake/task_spec.rb index 12fc1066e5ad1..57dd0f7c12d7c 100644 --- a/rb/spec/unit/selenium/rake/task_spec.rb +++ b/rb/spec/unit/selenium/rake/task_spec.rb @@ -24,9 +24,9 @@ let(:mock_server) { double(Selenium::Server).as_null_object } it "raises an error if no jar file is specified" do - lambda { + expect { Selenium::Rake::ServerTask.new - }.should raise_error(Selenium::Rake::MissingJarFileError) + }.to raise_error(Selenium::Rake::MissingJarFileError) end it "launches the server with default options" do @@ -37,17 +37,17 @@ :log => true, } - Selenium::Server.should_receive(:new). + expect(Selenium::Server).to receive(:new). with("selenium-server.jar", expected_opts). and_return(mock_server) task = Selenium::Rake::ServerTask.new { |t| t.jar = "selenium-server.jar" } - task.port.should == 4444 - task.timeout.should == 30 - task.background.should be true - task.log.should be true - task.opts.should == [] + expect(task.port).to eq(4444) + expect(task.timeout).to eq(30) + expect(task.background).to be true + expect(task.log).to be true + expect(task.opts).to eq([]) end it "lets the user override the default options" do @@ -58,7 +58,7 @@ :log => false, } - Selenium::Server.should_receive(:new). + expect(Selenium::Server).to receive(:new). with("selenium-server.jar", expected_opts). and_return(mock_server) @@ -72,22 +72,22 @@ t.opts << "-some" << "args" } - task.port.should == 5555 - task.timeout.should == 120 - task.background.should be false - task.log.should be false - task.opts.should == ["-some", "args"] + expect(task.port).to eq(5555) + expect(task.timeout).to eq(120) + expect(task.background).to be false + expect(task.log).to be false + expect(task.opts).to eq(["-some", "args"]) end it "lets the user specify a version to use which it will automatically download" do required_version = '10.2.0' jar_file = "selenium-server-standalone-#{required_version}.jar" - Selenium::Server.should_receive(:new). + expect(Selenium::Server).to receive(:new). with(jar_file, anything()). and_return(mock_server) - Selenium::Server.should_receive(:download). + expect(Selenium::Server).to receive(:download). with(required_version). and_return(jar_file) diff --git a/rb/spec/unit/selenium/server_spec.rb b/rb/spec/unit/selenium/server_spec.rb index 4188c6e050052..0bf8f723a041e 100644 --- a/rb/spec/unit/selenium/server_spec.rb +++ b/rb/spec/unit/selenium/server_spec.rb @@ -25,47 +25,47 @@ let(:mock_poller) { double("SocketPoller", :connected? => true, :closed? => true)} it "raises an error if the jar file does not exist" do - lambda { + expect { Selenium::Server.new("doesnt-exist.jar") - }.should raise_error(Errno::ENOENT) + }.to raise_error(Errno::ENOENT) end it "uses the given jar file and port" do - File.should_receive(:exist?).with("selenium-server-test.jar").and_return(true) + expect(File).to receive(:exist?).with("selenium-server-test.jar").and_return(true) - ChildProcess.should_receive(:build). + expect(ChildProcess).to receive(:build). with("java", "-jar", "selenium-server-test.jar", "-port", "1234"). and_return(mock_process) server = Selenium::Server.new("selenium-server-test.jar", :port => 1234, :background => true) - server.stub(:socket).and_return(mock_poller) + allow(server).to receive(:socket).and_return(mock_poller) server.start end it "waits for the server process by default" do - File.should_receive(:exist?).with("selenium-server-test.jar").and_return(true) + expect(File).to receive(:exist?).with("selenium-server-test.jar").and_return(true) - ChildProcess.should_receive(:build). + expect(ChildProcess).to receive(:build). with("java", "-jar", "selenium-server-test.jar", "-port", "4444"). and_return(mock_process) server = Selenium::Server.new("selenium-server-test.jar") - server.stub(:socket).and_return(mock_poller) + allow(server).to receive(:socket).and_return(mock_poller) - mock_process.should_receive(:wait) + expect(mock_process).to receive(:wait) server.start end it "adds additional args" do - File.should_receive(:exist?).with("selenium-server-test.jar").and_return(true) + expect(File).to receive(:exist?).with("selenium-server-test.jar").and_return(true) - ChildProcess.should_receive(:build). + expect(ChildProcess).to receive(:build). with("java", "-jar", "selenium-server-test.jar", "-port", "4444", "foo", "bar"). and_return(mock_process) server = Selenium::Server.new("selenium-server-test.jar", :background => true) - server.stub(:socket).and_return(mock_poller) + allow(server).to receive(:socket).and_return(mock_poller) server << ["foo", "bar"] @@ -80,8 +80,8 @@ begin actual_download_file_name = Selenium::Server.download(required_version) - actual_download_file_name.should == expected_download_file_name - File.should exist(expected_download_file_name) + expect(actual_download_file_name).to eq(expected_download_file_name) + expect(File).to exist(expected_download_file_name) ensure FileUtils.rm_rf expected_download_file_name end @@ -93,19 +93,19 @@ expected_options = {:port => 5555} fake_server = Object.new - Selenium::Server.should_receive(:download).with(required_version).and_return(expected_download_file_name) - Selenium::Server.should_receive(:new).with(expected_download_file_name, expected_options).and_return(fake_server) + expect(Selenium::Server).to receive(:download).with(required_version).and_return(expected_download_file_name) + expect(Selenium::Server).to receive(:new).with(expected_download_file_name, expected_options).and_return(fake_server) server = Selenium::Server.get required_version, expected_options - server.should == fake_server + expect(server).to eq(fake_server) end it "automatically repairs http_proxy settings that do not start with http://" do with_env("http_proxy" => "proxy.com") do - Selenium::Server.net_http.proxy_address.should == 'proxy.com' + expect(Selenium::Server.net_http.proxy_address).to eq('proxy.com') end with_env("HTTP_PROXY" => "proxy.com") do - Selenium::Server.net_http.proxy_address.should == 'proxy.com' + expect(Selenium::Server.net_http.proxy_address).to eq('proxy.com') end end @@ -113,7 +113,7 @@ required_version = '10.2.0' expected_download_file_name = "selenium-server-standalone-#{required_version}.jar" - File.should_receive(:exists?).with(expected_download_file_name).and_return true + expect(File).to receive(:exists?).with(expected_download_file_name).and_return true Selenium::Server.download required_version end @@ -123,44 +123,44 @@ example_xml ="selenium-release2.39/selenium-server-2.39.0.zip2.42/selenium-server-standalone-#{latest_version}.jar" stub_request(:get, "http://selenium-release.storage.googleapis.com/").to_return(:body => example_xml) - Selenium::Server.latest.should == latest_version + expect(Selenium::Server.latest).to eq(latest_version) end it "should download the latest version if that has been specified" do required_version, minor_version = '2.42.2', '2.42' expected_download_file_name = "selenium-server-standalone-#{required_version}.jar" - Selenium::Server.should_receive(:latest).and_return required_version + expect(Selenium::Server).to receive(:latest).and_return required_version stub_request(:get, "http://selenium-release.storage.googleapis.com/#{minor_version}/#{expected_download_file_name}").to_return(:body => "this is pretending to be a jar file for testing purposes") begin actual_download_file_name = Selenium::Server.download(:latest) - actual_download_file_name.should == expected_download_file_name - File.should exist(expected_download_file_name) + expect(actual_download_file_name).to eq(expected_download_file_name) + expect(File).to exist(expected_download_file_name) ensure FileUtils.rm_rf expected_download_file_name end end it "raises Selenium::Server::Error if the server is not launched within the timeout" do - File.should_receive(:exist?).with("selenium-server-test.jar").and_return(true) + expect(File).to receive(:exist?).with("selenium-server-test.jar").and_return(true) poller = double('SocketPoller') - poller.should_receive(:connected?).and_return(false) + expect(poller).to receive(:connected?).and_return(false) server = Selenium::Server.new("selenium-server-test.jar", :background => true) - server.stub(:socket).and_return(poller) + allow(server).to receive(:socket).and_return(poller) - lambda { server.start }.should raise_error(Selenium::Server::Error) + expect { server.start }.to raise_error(Selenium::Server::Error) end it "sets options after instantiation" do - File.should_receive(:exist?).with("selenium-server-test.jar").and_return(true) + expect(File).to receive(:exist?).with("selenium-server-test.jar").and_return(true) server = Selenium::Server.new("selenium-server-test.jar") - server.port.should == 4444 - server.timeout.should == 30 - server.background.should be false - server.log.should be_nil + expect(server.port).to eq(4444) + expect(server.timeout).to eq(30) + expect(server.background).to be false + expect(server.log).to be_nil server.port = 1234 server.timeout = 5 diff --git a/rb/spec/unit/selenium/webdriver/action_builder_spec.rb b/rb/spec/unit/selenium/webdriver/action_builder_spec.rb index 84304d4accf94..e7ee2401c5682 100644 --- a/rb/spec/unit/selenium/webdriver/action_builder_spec.rb +++ b/rb/spec/unit/selenium/webdriver/action_builder_spec.rb @@ -27,9 +27,9 @@ let(:builder) { Selenium::WebDriver::ActionBuilder.new(mouse, keyboard) } it "should create all keyboard actions" do - keyboard.should_receive(:press).with(:shift) - keyboard.should_receive(:send_keys).with("abc") - keyboard.should_receive(:release).with(:control) + expect(keyboard).to receive(:press).with(:shift) + expect(keyboard).to receive(:send_keys).with("abc") + expect(keyboard).to receive(:release).with(:control) builder.key_down(:shift). send_keys("abc"). @@ -37,8 +37,8 @@ end it "should pass an element to keyboard actions" do - mouse.should_receive(:click).with(element) - keyboard.should_receive(:press).with(:shift) + expect(mouse).to receive(:click).with(element) + expect(keyboard).to receive(:press).with(:shift) builder.key_down(element, :shift).perform end @@ -47,12 +47,12 @@ element2 = Selenium::WebDriver::Element.new(bridge, 'element2') element3 = Selenium::WebDriver::Element.new(bridge, 'element3') - mouse.should_receive(:click).with(element) - keyboard.should_receive(:press).with(:shift) - mouse.should_receive(:click).with(element2) - keyboard.should_receive(:send_keys).with("abc") - mouse.should_receive(:click).with(element3) - keyboard.should_receive(:release).with(:control) + expect(mouse).to receive(:click).with(element) + expect(keyboard).to receive(:press).with(:shift) + expect(mouse).to receive(:click).with(element2) + expect(keyboard).to receive(:send_keys).with("abc") + expect(mouse).to receive(:click).with(element3) + expect(keyboard).to receive(:release).with(:control) builder.key_down(element, :shift ). send_keys(element2, "abc"). @@ -60,12 +60,12 @@ end it "should create all mouse actions" do - mouse.should_receive(:down).with(element) - mouse.should_receive(:up).with(element) - mouse.should_receive(:click).with(element) - mouse.should_receive(:double_click).with(element) - mouse.should_receive(:move_to).with(element) - mouse.should_receive(:context_click).with(element) + expect(mouse).to receive(:down).with(element) + expect(mouse).to receive(:up).with(element) + expect(mouse).to receive(:click).with(element) + expect(mouse).to receive(:double_click).with(element) + expect(mouse).to receive(:move_to).with(element) + expect(mouse).to receive(:context_click).with(element) builder.click_and_hold(element). release(element). @@ -79,9 +79,9 @@ source = element target = Selenium::WebDriver::Element.new(bridge, 'element2') - mouse.should_receive(:down).with(source) - mouse.should_receive(:move_to).with(target) - mouse.should_receive(:up) + expect(mouse).to receive(:down).with(source) + expect(mouse).to receive(:move_to).with(target) + expect(mouse).to receive(:up) builder.drag_and_drop(source, target).perform end @@ -89,17 +89,17 @@ it "should drag and drop with offsets" do source = element - mouse.should_receive(:down).with(source) - mouse.should_receive(:move_by).with(-300, 400) - mouse.should_receive(:up) + expect(mouse).to receive(:down).with(source) + expect(mouse).to receive(:move_by).with(-300, 400) + expect(mouse).to receive(:up) builder.drag_and_drop_by(source, -300, 400).perform end it "can move the mouse by coordinates" do - mouse.should_receive(:down).with(element) - mouse.should_receive(:move_by).with(-300, 400) - mouse.should_receive(:up) + expect(mouse).to receive(:down).with(element) + expect(mouse).to receive(:move_by).with(-300, 400) + expect(mouse).to receive(:up) builder.click_and_hold(element). move_by(-300, 400). @@ -107,8 +107,8 @@ end it 'can click, hold and release at the current location' do - mouse.should_receive(:down).with(nil) - mouse.should_receive(:up) + expect(mouse).to receive(:down).with(nil) + expect(mouse).to receive(:up) builder.click_and_hold.release.perform end diff --git a/rb/spec/unit/selenium/webdriver/android/bridge_spec.rb b/rb/spec/unit/selenium/webdriver/android/bridge_spec.rb index 6ea7240a1f327..18dcbbfdf4db5 100644 --- a/rb/spec/unit/selenium/webdriver/android/bridge_spec.rb +++ b/rb/spec/unit/selenium/webdriver/android/bridge_spec.rb @@ -29,17 +29,17 @@ module Android let(:http) { double(Remote::Http::Default, :call => resp).as_null_object } it "uses the default Android driver URL" do - http.should_receive(:server_url=).with default_url + expect(http).to receive(:server_url=).with default_url Bridge.new(:http_client => http) end it "uses the user-provided URL" do - http.should_receive(:server_url=).with URI.parse("http://example.com") + expect(http).to receive(:server_url=).with URI.parse("http://example.com") Bridge.new(:http_client => http, :url => "http://example.com") end it "uses the default HTTP client when none is specified" do - Remote::Http::Default.should_receive(:new).and_return http + expect(Remote::Http::Default).to receive(:new).and_return http Bridge.new end @@ -48,7 +48,7 @@ module Android custom_caps['foo'] = 'bar' expect(http).to receive(:call) do |_, _, payload| - payload[:desiredCapabilities]['foo'].should == 'bar' + expect(payload[:desiredCapabilities]['foo']).to eq('bar') resp end diff --git a/rb/spec/unit/selenium/webdriver/chrome/bridge_spec.rb b/rb/spec/unit/selenium/webdriver/chrome/bridge_spec.rb index aa2364fbb0428..06f0eb84fe3af 100644 --- a/rb/spec/unit/selenium/webdriver/chrome/bridge_spec.rb +++ b/rb/spec/unit/selenium/webdriver/chrome/bridge_spec.rb @@ -33,75 +33,75 @@ module Chrome before do @default_capabilities = Remote::Capabilities.chrome.as_json - Remote::Capabilities.stub(:chrome).and_return(caps) - Service.stub(:default_service).and_return(service) + allow(Remote::Capabilities).to receive(:chrome).and_return(caps) + allow(Service).to receive(:default_service).and_return(service) end it "sets the nativeEvents capability" do Bridge.new(:http_client => http, :native_events => true) - caps['chromeOptions']['nativeEvents'].should be true - caps['chrome.nativeEvents'].should be true + expect(caps['chromeOptions']['nativeEvents']).to be true + expect(caps['chrome.nativeEvents']).to be true end it "sets the args capability" do Bridge.new(:http_client => http, :args => %w[--foo=bar]) - caps['chromeOptions']['args'].should == %w[--foo=bar] - caps['chrome.switches'].should == %w[--foo=bar] + expect(caps['chromeOptions']['args']).to eq(%w[--foo=bar]) + expect(caps['chrome.switches']).to eq(%w[--foo=bar]) end it "sets the proxy capabilitiy" do proxy = Proxy.new(:http => "localhost:1234") Bridge.new(:http_client => http, :proxy => proxy) - caps['proxy'].should == proxy + expect(caps['proxy']).to eq(proxy) end it "sets the chrome.verbose capability" do Bridge.new(:http_client => http, :verbose => true) - caps['chromeOptions']['verbose'].should be true - caps['chrome.verbose'].should be true + expect(caps['chromeOptions']['verbose']).to be true + expect(caps['chrome.verbose']).to be true end it "sets the chrome.detach capability" do Bridge.new(:http_client => http) # true by default - caps['chromeOptions']['detach'].should be true - caps['chrome.detach'].should be true + expect(caps['chromeOptions']['detach']).to be true + expect(caps['chrome.detach']).to be true end it "sets the prefs capability" do Bridge.new(:http_client => http, :prefs => {:foo => "bar"}) - caps['chromeOptions']['prefs'].should == {:foo => "bar"} - caps['chrome.prefs'].should == {:foo => "bar"} + expect(caps['chromeOptions']['prefs']).to eq({:foo => "bar"}) + expect(caps['chrome.prefs']).to eq({:foo => "bar"}) end it "lets the user override chrome.detach" do Bridge.new(:http_client => http, :detach => false) - caps['chromeOptions']['detach'].should be false - caps['chrome.detach'].should be false + expect(caps['chromeOptions']['detach']).to be false + expect(caps['chrome.detach']).to be false end it "lets the user override chrome.noWebsiteTestingDefaults" do Bridge.new(:http_client => http, :no_website_testing_defaults => true) - caps['chromeOptions']['noWebsiteTestingDefaults'].should be true - caps['chrome.noWebsiteTestingDefaults'].should be true + expect(caps['chromeOptions']['noWebsiteTestingDefaults']).to be true + expect(caps['chrome.noWebsiteTestingDefaults']).to be true end it "uses the user-provided server URL if given" do - Service.should_not_receive(:default_service) - http.should_receive(:server_url=).with(URI.parse("http://example.com")) + expect(Service).not_to receive(:default_service) + expect(http).to receive(:server_url=).with(URI.parse("http://example.com")) Bridge.new(:http_client => http, :url => "http://example.com") end it "raises an ArgumentError if args is not an Array" do - lambda { Bridge.new(:args => "--foo=bar")}.should raise_error(ArgumentError) + expect { Bridge.new(:args => "--foo=bar")}.to raise_error(ArgumentError) end it "uses the given profile" do @@ -113,11 +113,11 @@ module Chrome Bridge.new(:http_client => http, :profile => profile) profile_data = profile.as_json - caps['chromeOptions']['profile'].should == profile_data['zip'] - caps['chromeOptions']['extensions'].should == profile_data['extensions'] + expect(caps['chromeOptions']['profile']).to eq(profile_data['zip']) + expect(caps['chromeOptions']['extensions']).to eq(profile_data['extensions']) - caps['chrome.profile'].should == profile_data['zip'] - caps['chrome.extensions'].should == profile_data['extensions'] + expect(caps['chrome.profile']).to eq(profile_data['zip']) + expect(caps['chrome.extensions']).to eq(profile_data['extensions']) end it 'takes desired capabilities' do @@ -125,7 +125,7 @@ module Chrome custom_caps['chromeOptions'] = {'foo' => 'bar'} expect(http).to receive(:call) do |_, _, payload| - payload[:desiredCapabilities]['chromeOptions'].should include('foo' => 'bar') + expect(payload[:desiredCapabilities]['chromeOptions']).to include('foo' => 'bar') resp end @@ -137,7 +137,7 @@ module Chrome custom_caps['chromeOptions'] = {'args' => %w[foo bar]} expect(http).to receive(:call) do |_, _, payload| - payload[:desiredCapabilities]['chromeOptions']['args'].should == ['baz'] + expect(payload[:desiredCapabilities]['chromeOptions']['args']).to eq(['baz']) resp end @@ -145,7 +145,7 @@ module Chrome end it 'accepts :service_log_path' do - Service.should_receive(:default_service).with("--log-path=/foo/bar") + expect(Service).to receive(:default_service).with("--log-path=/foo/bar") Bridge.new(:http_client => http, :service_log_path => "/foo/bar") end end diff --git a/rb/spec/unit/selenium/webdriver/chrome/profile_spec.rb b/rb/spec/unit/selenium/webdriver/chrome/profile_spec.rb index 5a745da0ad410..efe09873e446b 100644 --- a/rb/spec/unit/selenium/webdriver/chrome/profile_spec.rb +++ b/rb/spec/unit/selenium/webdriver/chrome/profile_spec.rb @@ -30,43 +30,43 @@ module Chrome let(:model_profile) { Profile.new(model) } before do - File.stub(:exist?).with(model).and_return true - File.stub(:directory?).with(model).and_return true + allow(File).to receive(:exist?).with(model).and_return true + allow(File).to receive(:directory?).with(model).and_return true - Dir.stub(:mktmpdir => "/tmp/some/path") - FileUtils.stub(:rm_rf) - FileUtils.stub(:mkdir_p) - FileUtils.stub(:cp_r) + allow(Dir).to receive_messages(:mktmpdir => "/tmp/some/path") + allow(FileUtils).to receive(:rm_rf) + allow(FileUtils).to receive(:mkdir_p) + allow(FileUtils).to receive(:cp_r) end it "should set and get preference paths" do profile['foo.bar.baz'] = true - profile['foo.bar.baz'].should == true + expect(profile['foo.bar.baz']).to eq(true) end it "reads existing prefs" do - File.should_receive(:read).with("/some/path/Default/Preferences"). + expect(File).to receive(:read).with("/some/path/Default/Preferences"). and_return('{"autofill": {"enabled": false}}') - model_profile['autofill.enabled'].should == false + expect(model_profile['autofill.enabled']).to eq(false) end it "writes out prefs" do - File.should_receive(:read).with("/some/path/Default/Preferences"). + expect(File).to receive(:read).with("/some/path/Default/Preferences"). and_return('{"autofill": {"enabled": false}}') model_profile['some.other.pref'] = 123 mock_io = StringIO.new - FileUtils.should_receive(:mkdir_p).with("/tmp/some/path/Default") - File.should_receive(:open).with("/tmp/some/path/Default/Preferences", "w").and_yield(mock_io) + expect(FileUtils).to receive(:mkdir_p).with("/tmp/some/path/Default") + expect(File).to receive(:open).with("/tmp/some/path/Default/Preferences", "w").and_yield(mock_io) model_profile.layout_on_disk result = WebDriver.json_load(mock_io.string) - result['autofill']['enabled'].should == false - result['some']['other']['pref'].should == 123 + expect(result['autofill']['enabled']).to eq(false) + expect(result['some']['other']['pref']).to eq(123) end end diff --git a/rb/spec/unit/selenium/webdriver/chrome/service_spec.rb b/rb/spec/unit/selenium/webdriver/chrome/service_spec.rb index 2f35bf550f82e..0a0df4a768788 100644 --- a/rb/spec/unit/selenium/webdriver/chrome/service_spec.rb +++ b/rb/spec/unit/selenium/webdriver/chrome/service_spec.rb @@ -32,12 +32,12 @@ module Chrome before { Service.instance_variable_set("@executable_path", nil) } it "uses the user-provided path if set" do - Platform.stub(:os => :unix) - Platform.stub(:assert_executable).with("/some/path") + allow(Platform).to receive_messages(:os => :unix) + allow(Platform).to receive(:assert_executable).with("/some/path") Chrome.driver_path = "/some/path" expect(ChildProcess).to receive(:build) do |*args| - args.first.should == "/some/path" + expect(args.first).to eq("/some/path") mock_process end @@ -45,17 +45,17 @@ module Chrome end it "finds the Chrome server binary by searching PATH" do - Platform.stub(:os => :unix) - Platform.should_receive(:find_binary).once.and_return("/some/path") - Platform.should_receive(:assert_executable).with("/some/path") + allow(Platform).to receive_messages(:os => :unix) + expect(Platform).to receive(:find_binary).once.and_return("/some/path") + expect(Platform).to receive(:assert_executable).with("/some/path") - Service.executable_path.should == "/some/path" + expect(Service.executable_path).to eq("/some/path") end it "raises a nice error if the server binary can't be found" do - Platform.stub(:find_binary).and_return(nil) + allow(Platform).to receive(:find_binary).and_return(nil) - lambda { Service.executable_path }.should raise_error(Error::WebDriverError, /github.com\/SeleniumHQ/) + expect { Service.executable_path }.to raise_error(Error::WebDriverError, /github.com\/SeleniumHQ/) end end diff --git a/rb/spec/unit/selenium/webdriver/common/driver_extensions/has_network_connection_spec.rb b/rb/spec/unit/selenium/webdriver/common/driver_extensions/has_network_connection_spec.rb index 643904f7da793..5641d02a1c86b 100644 --- a/rb/spec/unit/selenium/webdriver/common/driver_extensions/has_network_connection_spec.rb +++ b/rb/spec/unit/selenium/webdriver/common/driver_extensions/has_network_connection_spec.rb @@ -31,13 +31,13 @@ class FakeDriver describe "#network_connection" do it "returns the correct connection type" do - @bridge.stub(:getNetworkConnection) { 1 } + allow(@bridge).to receive(:getNetworkConnection) { 1 } expect(driver.network_connection_type).to eq :airplane_mode end it "returns an unknown connection value" do - @bridge.stub(:getNetworkConnection) { 5 } + allow(@bridge).to receive(:getNetworkConnection) { 5 } expect(driver.network_connection_type).to eq 5 end diff --git a/rb/spec/unit/selenium/webdriver/error_spec.rb b/rb/spec/unit/selenium/webdriver/error_spec.rb index 9f66a00341415..c8449de69a1ba 100644 --- a/rb/spec/unit/selenium/webdriver/error_spec.rb +++ b/rb/spec/unit/selenium/webdriver/error_spec.rb @@ -25,33 +25,33 @@ module WebDriver context "backwards compatibility" do it "aliases StaleElementReferenceError as ObsoleteElementError" do - lambda { + expect { raise Error::StaleElementReferenceError - }.should raise_error(Error::ObsoleteElementError) + }.to raise_error(Error::ObsoleteElementError) end it "aliases UnknownError as UnhandledError" do - lambda { + expect { raise Error::UnknownError - }.should raise_error(Error::UnhandledError) + }.to raise_error(Error::UnhandledError) end it "aliases JavascriptError as UnexpectedJavascriptError" do - lambda { + expect { raise Error::JavascriptError - }.should raise_error(Error::UnexpectedJavascriptError) + }.to raise_error(Error::UnexpectedJavascriptError) end it "aliases NoAlertPresentError as NoAlertOpenError" do - lambda { + expect { raise Error::NoAlertPresentError - }.should raise_error(Error::NoAlertOpenError) + }.to raise_error(Error::NoAlertOpenError) end it "aliases ElementNotVisibleError as ElementNotDisplayedError" do - lambda { + expect { raise Error::ElementNotVisibleError - }.should raise_error(Error::ElementNotDisplayedError) + }.to raise_error(Error::ElementNotDisplayedError) end end diff --git a/rb/spec/unit/selenium/webdriver/file_reaper_spec.rb b/rb/spec/unit/selenium/webdriver/file_reaper_spec.rb index c3bdfa04386a8..27fa160a11fd5 100644 --- a/rb/spec/unit/selenium/webdriver/file_reaper_spec.rb +++ b/rb/spec/unit/selenium/webdriver/file_reaper_spec.rb @@ -29,16 +29,16 @@ module WebDriver end it 'reaps files that have been added' do - tmp_file.should exist + expect(tmp_file).to exist FileReaper << tmp_file.to_s - FileReaper.reap!.should be true + expect(FileReaper.reap!).to be true - tmp_file.should_not exist + expect(tmp_file).not_to exist end it 'fails if the file has not been added' do - tmp_file.should exist + expect(tmp_file).to exist expect { FileReaper.reap(tmp_file.to_s) @@ -46,26 +46,26 @@ module WebDriver end it 'does not reap if reaping has been disabled' do - tmp_file.should exist + expect(tmp_file).to exist FileReaper.reap = false FileReaper << tmp_file.to_s - FileReaper.reap!.should be false + expect(FileReaper.reap!).to be false - tmp_file.should exist + expect(tmp_file).to exist end unless Platform.jruby? || Platform.windows? it 'reaps files only for the current pid' do - tmp_file.should exist + expect(tmp_file).to exist FileReaper << tmp_file.to_s pid = fork { FileReaper.reap!; exit; exit } Process.wait pid - tmp_file.should exist + expect(tmp_file).to exist end end diff --git a/rb/spec/unit/selenium/webdriver/firefox/bridge_spec.rb b/rb/spec/unit/selenium/webdriver/firefox/bridge_spec.rb index fef7b078cff78..3f26a73213114 100644 --- a/rb/spec/unit/selenium/webdriver/firefox/bridge_spec.rb +++ b/rb/spec/unit/selenium/webdriver/firefox/bridge_spec.rb @@ -32,19 +32,19 @@ module Firefox before do @default_capabilities = Remote::Capabilities.firefox.as_json - Remote::Capabilities.stub(:firefox).and_return(caps) - Launcher.stub(:new).and_return(launcher) + allow(Remote::Capabilities).to receive(:firefox).and_return(caps) + allow(Launcher).to receive(:new).and_return(launcher) end it "sets the proxy capability" do proxy = Proxy.new(:http => "localhost:9090") - caps.should_receive(:proxy=).with proxy + expect(caps).to receive(:proxy=).with proxy Bridge.new(:http_client => http, :proxy => proxy) end it "raises ArgumentError if passed invalid options" do - lambda { Bridge.new(:foo => 'bar') }.should raise_error(ArgumentError) + expect { Bridge.new(:foo => 'bar') }.to raise_error(ArgumentError) end it 'takes desired capabilities' do @@ -52,7 +52,7 @@ module Firefox custom_caps['foo'] = 'bar' expect(http).to receive(:call) do |_, _, payload| - payload[:desiredCapabilities]['foo'].should == 'bar' + expect(payload[:desiredCapabilities]['foo']).to eq('bar') resp end diff --git a/rb/spec/unit/selenium/webdriver/firefox/extension_spec.rb b/rb/spec/unit/selenium/webdriver/firefox/extension_spec.rb index 62c3ac8a4e38b..55262746b1482 100644 --- a/rb/spec/unit/selenium/webdriver/firefox/extension_spec.rb +++ b/rb/spec/unit/selenium/webdriver/firefox/extension_spec.rb @@ -25,7 +25,7 @@ module Firefox describe Extension do before do - File.stub(:exist? => true) + allow(File).to receive_messages(:exist? => true) end let(:extension) { @@ -36,7 +36,7 @@ def ext.read_id(dir); read_id_from_install_rdf(dir); end } it 'finds the rdf extension id as attribute' do - File.stub(:read).with('/foo/install.rdf').and_return <<-XML + allow(File).to receive(:read).with('/foo/install.rdf').and_return <<-XML @@ -45,11 +45,11 @@ def ext.read_id(dir); read_id_from_install_rdf(dir); end XML - extension.read_id('/foo').should == '{f5198635-4eb3-47a5-b6a5-366b15cd2107}' + expect(extension.read_id('/foo')).to eq('{f5198635-4eb3-47a5-b6a5-366b15cd2107}') end it 'finds the rdf extension id as text' do - File.stub(:read).with('/foo/install.rdf').and_return <<-XML + allow(File).to receive(:read).with('/foo/install.rdf').and_return <<-XML @@ -57,11 +57,11 @@ def ext.read_id(dir); read_id_from_install_rdf(dir); end XML - extension.read_id('/foo').should == '{f5198635-4eb3-47a5-b6a5-366b15cd2107}' + expect(extension.read_id('/foo')).to eq('{f5198635-4eb3-47a5-b6a5-366b15cd2107}') end it 'raises if the node id is not found' do - File.stub(:read).with('/foo/install.rdf').and_return <<-XML + allow(File).to receive(:read).with('/foo/install.rdf').and_return <<-XML XML diff --git a/rb/spec/unit/selenium/webdriver/ie/bridge_spec.rb b/rb/spec/unit/selenium/webdriver/ie/bridge_spec.rb index 3eda321996f3a..8c4e4c1c1d0c2 100644 --- a/rb/spec/unit/selenium/webdriver/ie/bridge_spec.rb +++ b/rb/spec/unit/selenium/webdriver/ie/bridge_spec.rb @@ -31,13 +31,13 @@ module IE let(:http) { double(Remote::Http::Default, :call => resp).as_null_object } before do - Server.stub(:get => server) + allow(Server).to receive_messages(:get => server) @default_capabilities = Remote::Capabilities.internet_explorer - Remote::Capabilities.stub(:internet_explorer => caps) + allow(Remote::Capabilities).to receive_messages(:internet_explorer => caps) end it "raises ArgumentError if passed invalid options" do - lambda { Bridge.new(:foo => 'bar') }.should raise_error(ArgumentError) + expect { Bridge.new(:foo => 'bar') }.to raise_error(ArgumentError) end it "accepts the :introduce_flakiness_by_ignoring_security_domains option" do @@ -46,13 +46,13 @@ module IE :http_client => http ) - caps['ignoreProtectedModeSettings'].should be true + expect(caps['ignoreProtectedModeSettings']).to be true end it "has native events enabled by default" do Bridge.new(:http_client => http) - caps['nativeEvents'].should be true + expect(caps['nativeEvents']).to be true end it "can disable native events" do @@ -61,12 +61,12 @@ module IE :http_client => http ) - caps['nativeEvents'].should be false + expect(caps['nativeEvents']).to be false end it 'sets the server log level and log file' do - server.should_receive(:log_level=).with :trace - server.should_receive(:log_file=).with '/foo/bar' + expect(server).to receive(:log_level=).with :trace + expect(server).to receive(:log_file=).with '/foo/bar' Bridge.new( :log_level => :trace, @@ -76,7 +76,7 @@ module IE end it 'should be able to set implementation' do - Server.should_receive(:get).with(:implementation => :vendor).and_return(server) + expect(Server).to receive(:get).with(:implementation => :vendor).and_return(server) Bridge.new( :implementation => :vendor, @@ -89,7 +89,7 @@ module IE custom_caps['ignoreProtectedModeSettings'] = true expect(http).to receive(:call) do |_, _, payload| - payload[:desiredCapabilities]['ignoreProtectedModeSettings'].should be true + expect(payload[:desiredCapabilities]['ignoreProtectedModeSettings']).to be true resp end @@ -101,7 +101,7 @@ module IE custom_caps['ignoreProtectedModeSettings'] = false expect(http).to receive(:call) do |_, _, payload| - payload[:desiredCapabilities]['ignoreProtectedModeSettings'].should be true + expect(payload[:desiredCapabilities]['ignoreProtectedModeSettings']).to be true resp end diff --git a/rb/spec/unit/selenium/webdriver/iphone/bridge_spec.rb b/rb/spec/unit/selenium/webdriver/iphone/bridge_spec.rb index fc8b292be311b..c9062cb57ef62 100644 --- a/rb/spec/unit/selenium/webdriver/iphone/bridge_spec.rb +++ b/rb/spec/unit/selenium/webdriver/iphone/bridge_spec.rb @@ -29,17 +29,17 @@ module IPhone let(:http) { double(Remote::Http::Default, :call => resp).as_null_object } it "uses the default iPhone driver URL" do - http.should_receive(:server_url=).with default_url + expect(http).to receive(:server_url=).with default_url Bridge.new(:http_client => http) end it "uses the user-provided URL" do - http.should_receive(:server_url=).with URI.parse("http://example.com") + expect(http).to receive(:server_url=).with URI.parse("http://example.com") Bridge.new(:http_client => http, :url => "http://example.com") end it "uses the default HTTP client when none is specified" do - Remote::Http::Default.should_receive(:new).and_return http + expect(Remote::Http::Default).to receive(:new).and_return http Bridge.new end @@ -48,7 +48,7 @@ module IPhone custom_caps['foo'] = 'bar' expect(http).to receive(:call) do |_, _, payload| - payload[:desiredCapabilities]['foo'].should == 'bar' + expect(payload[:desiredCapabilities]['foo']).to eq('bar') resp end diff --git a/rb/spec/unit/selenium/webdriver/phantomjs/bridge_spec.rb b/rb/spec/unit/selenium/webdriver/phantomjs/bridge_spec.rb index f7d70e1fad192..c153b3d3c9462 100644 --- a/rb/spec/unit/selenium/webdriver/phantomjs/bridge_spec.rb +++ b/rb/spec/unit/selenium/webdriver/phantomjs/bridge_spec.rb @@ -30,16 +30,16 @@ module PhantomJS let(:http) { double(Remote::Http::Default, :call => resp).as_null_object } before do - Service.stub(:default_service).and_return(service) + allow(Service).to receive(:default_service).and_return(service) end it 'starts the server with the given arguments' do - service.should_receive(:start).with(%w[--foo --bar]) + expect(service).to receive(:start).with(%w[--foo --bar]) Bridge.new(:http_client => http, :args => %w[--foo --bar]) end it 'reads server arguments from desired capabilities if not given directly' do - service.should_receive(:start).with(%w[--foo --bar]) + expect(service).to receive(:start).with(%w[--foo --bar]) caps = Remote::Capabilities.phantomjs caps['phantomjs.cli.args'] = %w[--foo --bar] @@ -51,7 +51,7 @@ module PhantomJS custom_caps = Remote::Capabilities.new(:browser_name => 'foo') expect(http).to receive(:call) do |verb, post, payload| - payload[:desiredCapabilities].should == custom_caps + expect(payload[:desiredCapabilities]).to eq(custom_caps) resp end @@ -59,7 +59,7 @@ module PhantomJS end it 'lets direct arguments take presedence over capabilities' do - service.should_receive(:start).with(%w[--foo --bar]) + expect(service).to receive(:start).with(%w[--foo --bar]) caps = Remote::Capabilities.phantomjs caps['phantomjs.cli.args'] = %w[--baz] diff --git a/rb/spec/unit/selenium/webdriver/proxy_spec.rb b/rb/spec/unit/selenium/webdriver/proxy_spec.rb index 513497162aca4..111fc8a32cbe9 100755 --- a/rb/spec/unit/selenium/webdriver/proxy_spec.rb +++ b/rb/spec/unit/selenium/webdriver/proxy_spec.rb @@ -41,55 +41,55 @@ module WebDriver end it "raises ArgumentError if passed invalid options" do - lambda { Proxy.new(:invalid_options => 'invalid') }.should raise_error(ArgumentError) + expect { Proxy.new(:invalid_options => 'invalid') }.to raise_error(ArgumentError) end it "raises ArgumentError if passed an invalid proxy type" do - lambda { Proxy.new(:type => :invalid) }.should raise_error(ArgumentError) + expect { Proxy.new(:type => :invalid) }.to raise_error(ArgumentError) end it "raises ArgumentError if the proxy type is changed" do proxy = Proxy.new(:type => :direct) - lambda { proxy.type = :system }.should raise_error(ArgumentError) + expect { proxy.type = :system }.to raise_error(ArgumentError) end it "should allow valid options for a manual proxy" do proxy = Proxy.new(proxy_settings) - proxy.ftp.should == proxy_settings[:ftp] - proxy.http.should == proxy_settings[:http] - proxy.no_proxy.should == proxy_settings[:no_proxy] - proxy.ssl.should == proxy_settings[:ssl] - proxy.socks.should == proxy_settings[:socks] - proxy.socks_username.should == proxy_settings[:socks_username] - proxy.socks_password.should == proxy_settings[:socks_password] + expect(proxy.ftp).to eq(proxy_settings[:ftp]) + expect(proxy.http).to eq(proxy_settings[:http]) + expect(proxy.no_proxy).to eq(proxy_settings[:no_proxy]) + expect(proxy.ssl).to eq(proxy_settings[:ssl]) + expect(proxy.socks).to eq(proxy_settings[:socks]) + expect(proxy.socks_username).to eq(proxy_settings[:socks_username]) + expect(proxy.socks_password).to eq(proxy_settings[:socks_password]) end it "should return a hash of the json properties to serialize" do proxy_json = Proxy.new(proxy_settings).as_json - proxy_json['proxyType'].should == "MANUAL" - proxy_json['ftpProxy'].should == proxy_settings[:ftp] - proxy_json['httpProxy'].should == proxy_settings[:http] - proxy_json['noProxy'].should == proxy_settings[:no_proxy] - proxy_json['sslProxy'].should == proxy_settings[:ssl] - proxy_json['socksProxy'].should == proxy_settings[:socks] - proxy_json['socksUsername'].should == proxy_settings[:socks_username] - proxy_json['socksPassword'].should == proxy_settings[:socks_password] + expect(proxy_json['proxyType']).to eq("MANUAL") + expect(proxy_json['ftpProxy']).to eq(proxy_settings[:ftp]) + expect(proxy_json['httpProxy']).to eq(proxy_settings[:http]) + expect(proxy_json['noProxy']).to eq(proxy_settings[:no_proxy]) + expect(proxy_json['sslProxy']).to eq(proxy_settings[:ssl]) + expect(proxy_json['socksProxy']).to eq(proxy_settings[:socks]) + expect(proxy_json['socksUsername']).to eq(proxy_settings[:socks_username]) + expect(proxy_json['socksPassword']).to eq(proxy_settings[:socks_password]) end it "should configure a PAC proxy" do proxy_json = Proxy.new(pac_proxy_settings).as_json - proxy_json['proxyType'].should == "PAC" - proxy_json['proxyAutoconfigUrl'].should == pac_proxy_settings[:pac] + expect(proxy_json['proxyType']).to eq("PAC") + expect(proxy_json['proxyAutoconfigUrl']).to eq(pac_proxy_settings[:pac]) end it "should configure an auto-detected proxy" do proxy_json = Proxy.new(:auto_detect => true).as_json - proxy_json['proxyType'].should == "AUTODETECT" - proxy_json['autodetect'].should be true + expect(proxy_json['proxyType']).to eq("AUTODETECT") + expect(proxy_json['autodetect']).to be true end it "should only add settings that are not nil" do @@ -98,26 +98,26 @@ module WebDriver proxy = Proxy.new(settings) proxy_json = proxy.as_json - proxy_json.delete('proxyType').should == settings[:type].to_s.upcase - proxy_json.delete('httpProxy').should == settings[:http] + expect(proxy_json.delete('proxyType')).to eq(settings[:type].to_s.upcase) + expect(proxy_json.delete('httpProxy')).to eq(settings[:http]) - proxy_json.should be_empty + expect(proxy_json).to be_empty end it "returns a JSON string" do proxy = Proxy.new(proxy_settings) - proxy.to_json.should be_kind_of(String) + expect(proxy.to_json).to be_kind_of(String) end it "can be serialized and deserialized" do proxy = Proxy.new(proxy_settings) other = Proxy.json_create(proxy.as_json) - proxy.should == other + expect(proxy).to eq(other) end it 'deserializes to nil if proxyType is UNSPECIFIED' do - Proxy.json_create('proxyType' => 'UNSPECIFIED').should be_nil + expect(Proxy.json_create('proxyType' => 'UNSPECIFIED')).to be_nil end end diff --git a/rb/spec/unit/selenium/webdriver/remote/bridge_spec.rb b/rb/spec/unit/selenium/webdriver/remote/bridge_spec.rb index 52eb798ab1e9c..7229a37e183c7 100644 --- a/rb/spec/unit/selenium/webdriver/remote/bridge_spec.rb +++ b/rb/spec/unit/selenium/webdriver/remote/bridge_spec.rb @@ -25,7 +25,7 @@ module Remote describe Bridge do it "raises ArgumentError if passed invalid options" do - lambda { Bridge.new(:foo => 'bar') }.should raise_error(ArgumentError) + expect { Bridge.new(:foo => 'bar') }.to raise_error(ArgumentError) end it "raises WebDriverError if uploading non-files" do @@ -35,7 +35,7 @@ module Remote :status => 200, :body => request_body, :headers => headers) bridge = Bridge.new - lambda { bridge.upload("NotAFile")}.should raise_error(Error::WebDriverError) + expect { bridge.upload("NotAFile")}.to raise_error(Error::WebDriverError) end end diff --git a/rb/spec/unit/selenium/webdriver/remote/capabilities_spec.rb b/rb/spec/unit/selenium/webdriver/remote/capabilities_spec.rb index 846117df0eb8e..7d11b95b7bc4d 100644 --- a/rb/spec/unit/selenium/webdriver/remote/capabilities_spec.rb +++ b/rb/spec/unit/selenium/webdriver/remote/capabilities_spec.rb @@ -26,106 +26,106 @@ module Remote it "has default capabilities for Android" do caps = Capabilities.android - caps.browser_name.should == "android" - caps.platform.should == :android + expect(caps.browser_name).to eq("android") + expect(caps.platform).to eq(:android) end it "has default capabilities for Chrome" do caps = Capabilities.chrome - caps.browser_name.should == "chrome" + expect(caps.browser_name).to eq("chrome") end it "has default capabilities for Edge" do caps = Capabilities.edge - caps.browser_name.should == "MicrosoftEdge" + expect(caps.browser_name).to eq("MicrosoftEdge") end it "has default capabilities for Firefox" do caps = Capabilities.firefox - caps.browser_name.should == "firefox" + expect(caps.browser_name).to eq("firefox") end it "has default capabilities for HtmlUnit" do caps = Capabilities.htmlunit - caps.browser_name.should == "htmlunit" + expect(caps.browser_name).to eq("htmlunit") end it "has default capabilities for Internet Explorer" do caps = Capabilities.internet_explorer - caps.browser_name.should == "internet explorer" + expect(caps.browser_name).to eq("internet explorer") end it "has default capabilities for iPhone" do caps = Capabilities.iphone - caps.browser_name.should == "iPhone" + expect(caps.browser_name).to eq("iPhone") end it "has default capabilities for iPad" do caps = Capabilities.ipad - caps.browser_name.should == "iPad" + expect(caps.browser_name).to eq("iPad") end it "should default to no proxy" do - Capabilities.new.proxy.should be_nil + expect(Capabilities.new.proxy).to be_nil end it "can set and get standard capabilities" do caps = Capabilities.new caps.browser_name = "foo" - caps.browser_name.should == "foo" + expect(caps.browser_name).to eq("foo") caps.native_events = true - caps.native_events.should == true + expect(caps.native_events).to eq(true) end it "can set and get arbitrary capabilities" do caps = Capabilities.chrome caps['chrome'] = :foo - caps['chrome'].should == :foo + expect(caps['chrome']).to eq(:foo) end it "should set the given proxy" do proxy = Proxy.new capabilities = Capabilities.new(:proxy => proxy) - capabilities.proxy.should == proxy + expect(capabilities.proxy).to eq(proxy) end it "should accept a Hash" do capabilities = Capabilities.new(:proxy => {:http => "foo:123"}) - capabilities.proxy.http.should == "foo:123" + expect(capabilities.proxy.http).to eq("foo:123") end it "should return a hash of the json properties to serialize" do capabilities_hash = Capabilities.new(:proxy => {:http => "some value"}).as_json proxy_hash = capabilities_hash["proxy"] - capabilities_hash["proxy"].should be_kind_of(Hash) - proxy_hash['httpProxy'].should == "some value" - proxy_hash['proxyType'].should == "MANUAL" + expect(capabilities_hash["proxy"]).to be_kind_of(Hash) + expect(proxy_hash['httpProxy']).to eq("some value") + expect(proxy_hash['proxyType']).to eq("MANUAL") end it "should not contain proxy hash when no proxy settings" do capabilities_hash = Capabilities.new.as_json - capabilities_hash.should_not have_key("proxy") + expect(capabilities_hash).not_to have_key("proxy") end it "can merge capabilities" do a, b = Capabilities.chrome, Capabilities.htmlunit a.merge!(b) - a.browser_name.should == "htmlunit" - a.javascript_enabled.should be false + expect(a.browser_name).to eq("htmlunit") + expect(a.javascript_enabled).to be false end it "can be serialized and deserialized to JSON" do caps = Capabilities.new(:browser_name => "firefox", :custom_capability => true) - caps.should == Capabilities.json_create(caps.as_json) + expect(caps).to eq(Capabilities.json_create(caps.as_json)) end it 'does not camel case the :firefox_binary capability' do - Capabilities.new(:firefox_binary => "/foo/bar").as_json.should include('firefox_binary') + expect(Capabilities.new(:firefox_binary => "/foo/bar").as_json).to include('firefox_binary') end end end diff --git a/rb/spec/unit/selenium/webdriver/remote/http/common_spec.rb b/rb/spec/unit/selenium/webdriver/remote/http/common_spec.rb index d5be2795fe979..5cb3a2802b2a1 100644 --- a/rb/spec/unit/selenium/webdriver/remote/http/common_spec.rb +++ b/rb/spec/unit/selenium/webdriver/remote/http/common_spec.rb @@ -29,7 +29,7 @@ module Http common = Common.new common.server_url = URI.parse("http://server") - common.should_receive(:request). + expect(common).to receive(:request). with(:post, URI.parse("http://server/clear"), hash_including("Content-Length" => "2"), "{}") diff --git a/rb/spec/unit/selenium/webdriver/remote/http/default_spec.rb b/rb/spec/unit/selenium/webdriver/remote/http/default_spec.rb index 823c03e382f6b..a751c407d6aef 100644 --- a/rb/spec/unit/selenium/webdriver/remote/http/default_spec.rb +++ b/rb/spec/unit/selenium/webdriver/remote/http/default_spec.rb @@ -35,26 +35,26 @@ module Http client.timeout = 10 http = client.send :http - http.open_timeout.should == 10 - http.read_timeout.should == 10 + expect(http.open_timeout).to eq(10) + expect(http.read_timeout).to eq(10) end it "uses the specified proxy" do client.proxy = Proxy.new(:http => "http://foo:bar@proxy.org:8080") http = client.send :http - http.should be_proxy - http.proxy_address.should == "proxy.org" - http.proxy_port.should == 8080 - http.proxy_user.should == "foo" - http.proxy_pass.should == "bar" + expect(http).to be_proxy + expect(http.proxy_address).to eq("proxy.org") + expect(http.proxy_port).to eq(8080) + expect(http.proxy_user).to eq("foo") + expect(http.proxy_pass).to eq("bar") - http.address.should == "example.com" + expect(http.address).to eq("example.com") end it "raises an error if the proxy is not an HTTP proxy" do client.proxy = Proxy.new(:ftp => "ftp://example.com") - lambda { client.send :http }.should raise_error(Error::WebDriverError) + expect { client.send :http }.to raise_error(Error::WebDriverError) end ["http_proxy", "HTTP_PROXY"].each { |proxy_var| @@ -62,9 +62,9 @@ module Http with_env(proxy_var => "http://proxy.org:8080") do http = client.send :http - http.should be_proxy - http.proxy_address.should == "proxy.org" - http.proxy_port.should == 8080 + expect(http).to be_proxy + expect(http.proxy_address).to eq("proxy.org") + expect(http.proxy_port).to eq(8080) end end @@ -72,9 +72,9 @@ module Http with_env(proxy_var => "proxy.org:8080") do http = client.send :http - http.should be_proxy - http.proxy_address.should == "proxy.org" - http.proxy_port.should == 8080 + expect(http).to be_proxy + expect(http.proxy_address).to eq("proxy.org") + expect(http.proxy_port).to eq(8080) end end } @@ -83,7 +83,7 @@ module Http it "honors the #{no_proxy_var} environment variable when matching" do with_env("HTTP_PROXY" => "proxy.org:8080", no_proxy_var => "example.com") do http = client.send :http - http.should_not be_proxy + expect(http).not_to be_proxy end end @@ -91,16 +91,16 @@ module Http with_env("HTTP_PROXY" => "proxy.org:8080", no_proxy_var => "foo.com") do http = client.send :http - http.should be_proxy - http.proxy_address.should == "proxy.org" - http.proxy_port.should == 8080 + expect(http).to be_proxy + expect(http.proxy_address).to eq("proxy.org") + expect(http.proxy_port).to eq(8080) end end it "understands a comma separated list of domains in #{no_proxy_var}" do with_env("HTTP_PROXY" => "proxy.org:8080", no_proxy_var => "example.com,foo.com") do http = client.send :http - http.should_not be_proxy + expect(http).not_to be_proxy end end @@ -108,7 +108,7 @@ module Http it "understands an asterisk in #{no_proxy_var}" do with_env("HTTP_PROXY" => "proxy.org:8080", no_proxy_var => "*") do http = client.send :http - http.should_not be_proxy + expect(http).not_to be_proxy end end end @@ -118,7 +118,7 @@ module Http client.server_url = URI.parse("http://127.0.0.1:4444/wd/hub") http = client.send :http - http.should_not be_proxy + expect(http).not_to be_proxy end end end @@ -126,11 +126,11 @@ module Http it "raises a sane error if a proxy is refusing connections" do with_env("http_proxy" => "http://localhost:1234") do http = client.send :http - http.should_receive(:request).and_raise Errno::ECONNREFUSED.new("Connection refused") + expect(http).to receive(:request).and_raise Errno::ECONNREFUSED.new("Connection refused") - lambda { + expect { client.call :post, 'http://example.com/foo/bar', {} - }.should raise_error(Errno::ECONNREFUSED, %r[using proxy: http://localhost:1234]) + }.to raise_error(Errno::ECONNREFUSED, %r[using proxy: http://localhost:1234]) end end diff --git a/rb/spec/unit/selenium/webdriver/safari/bridge_spec.rb b/rb/spec/unit/selenium/webdriver/safari/bridge_spec.rb index 79963f48c7de8..9b4db84ea8018 100644 --- a/rb/spec/unit/selenium/webdriver/safari/bridge_spec.rb +++ b/rb/spec/unit/selenium/webdriver/safari/bridge_spec.rb @@ -40,9 +40,9 @@ module Safari before do @default_capabilities = Remote::Capabilities.safari.as_json - Remote::Capabilities.stub(:safari).and_return(caps) - Server.stub(:new).and_return(server) - Browser.stub(:new).and_return(browser) + allow(Remote::Capabilities).to receive(:safari).and_return(caps) + allow(Server).to receive(:new).and_return(server) + allow(Browser).to receive(:new).and_return(browser) end @@ -51,7 +51,7 @@ module Safari custom_caps['foo'] = 'bar' expect(server).to receive(:send) do |payload| - payload[:command][:parameters][:desiredCapabilities]['foo'].should == 'bar' + expect(payload[:command][:parameters][:desiredCapabilities]['foo']).to eq('bar') end Bridge.new(desired_capabilities: custom_caps) @@ -62,7 +62,7 @@ module Safari custom_caps['cleanSession'] = false expect(server).to receive(:send) do |payload| - payload[:command][:parameters][:desiredCapabilities]['safari.options']['cleanSession'].should == true + expect(payload[:command][:parameters][:desiredCapabilities]['safari.options']['cleanSession']).to eq(true) end Bridge.new(:clean_session => true) diff --git a/rb/spec/unit/selenium/webdriver/search_context_spec.rb b/rb/spec/unit/selenium/webdriver/search_context_spec.rb index b232cbe84c942..cd8753dd1f896 100644 --- a/rb/spec/unit/selenium/webdriver/search_context_spec.rb +++ b/rb/spec/unit/selenium/webdriver/search_context_spec.rb @@ -36,19 +36,19 @@ def initialize(bridge) context "finding a single element" do it "accepts a hash" do - bridge.should_receive(:find_element_by).with('id', "bar", nil).and_return(element) - search_context.find_element(:id => "bar").should == element + expect(bridge).to receive(:find_element_by).with('id', "bar", nil).and_return(element) + expect(search_context.find_element(:id => "bar")).to eq(element) end it "accepts two arguments" do - bridge.should_receive(:find_element_by).with('id', "bar", nil).and_return(element) - search_context.find_element(:id, "bar").should == element + expect(bridge).to receive(:find_element_by).with('id', "bar", nil).and_return(element) + expect(search_context.find_element(:id, "bar")).to eq(element) end it "raises an error if given an invalid 'by'" do - lambda { + expect { search_context.find_element(:foo => "bar") - }.should raise_error(ArgumentError, 'cannot find element by :foo') + }.to raise_error(ArgumentError, 'cannot find element by :foo') end it "does not modify the hash given" do @@ -56,25 +56,25 @@ def initialize(bridge) search_context.find_element(selector) - selector.should == {:id => "foo"} + expect(selector).to eq({:id => "foo"}) end end context "finding multiple elements" do it "accepts a hash" do - bridge.should_receive(:find_elements_by).with('id', "bar", nil).and_return([]) - search_context.find_elements(:id => "bar").should == [] + expect(bridge).to receive(:find_elements_by).with('id', "bar", nil).and_return([]) + expect(search_context.find_elements(:id => "bar")).to eq([]) end it "accepts two arguments" do - bridge.should_receive(:find_elements_by).with('id', "bar", nil).and_return([]) - search_context.find_elements(:id, "bar").should == [] + expect(bridge).to receive(:find_elements_by).with('id', "bar", nil).and_return([]) + expect(search_context.find_elements(:id, "bar")).to eq([]) end it "raises an error if given an invalid 'by'" do - lambda { + expect { search_context.find_elements(:foo => "bar") - }.should raise_error(ArgumentError, 'cannot find elements by :foo') + }.to raise_error(ArgumentError, 'cannot find elements by :foo') end end end diff --git a/rb/spec/unit/selenium/webdriver/socket_poller_spec.rb b/rb/spec/unit/selenium/webdriver/socket_poller_spec.rb index 13a0b36eded06..0b254f047f381 100644 --- a/rb/spec/unit/selenium/webdriver/socket_poller_spec.rb +++ b/rb/spec/unit/selenium/webdriver/socket_poller_spec.rb @@ -30,15 +30,15 @@ def setup_connect(*states) if Platform.jruby? states.each { |state| if state - TCPSocket.should_receive(:new).and_return socket + expect(TCPSocket).to receive(:new).and_return socket else - TCPSocket.should_receive(:new).and_raise Errno::ECONNREFUSED + expect(TCPSocket).to receive(:new).and_raise Errno::ECONNREFUSED end } else - Socket.stub(:new).and_return socket + allow(Socket).to receive(:new).and_return socket states.each { |state| - socket.should_receive(:connect_nonblock). + expect(socket).to receive(:connect_nonblock). and_raise(state ? Errno::EISCONN.new("connection in progress") : Errno::ECONNREFUSED.new("connection refused")) } end @@ -47,7 +47,7 @@ def setup_connect(*states) describe "#connected?" do it "returns true when the socket is listening" do setup_connect false, true - poller.should be_connected + expect(poller).to be_connected end it "returns false if the socket is not listening after the given timeout" do @@ -57,8 +57,8 @@ def setup_connect(*states) wait = Time.parse("2010-01-01 00:00:04") stop = Time.parse("2010-01-01 00:00:06") - Time.should_receive(:now).and_return(start, wait, stop) - poller.should_not be_connected + expect(Time).to receive(:now).and_return(start, wait, stop) + expect(poller).not_to be_connected end end @@ -66,7 +66,7 @@ def setup_connect(*states) it "returns true when the socket is closed" do setup_connect true, true, false - poller.should be_closed + expect(poller).to be_closed end it "returns false if the socket is still listening after the given timeout" do @@ -77,8 +77,8 @@ def setup_connect(*states) stop = Time.parse("2010-01-01 00:00:06") # on rbx, we can't add expectations to Time.now since it will be called by the kernel code. - poller.should_receive(:time_now).and_return(start, wait, stop) - poller.should_not be_closed + expect(poller).to receive(:time_now).and_return(start, wait, stop) + expect(poller).not_to be_closed end end diff --git a/rb/spec/unit/selenium/webdriver/support/color_spec.rb b/rb/spec/unit/selenium/webdriver/support/color_spec.rb index 5d76d200b720f..f30561115ddd1 100644 --- a/rb/spec/unit/selenium/webdriver/support/color_spec.rb +++ b/rb/spec/unit/selenium/webdriver/support/color_spec.rb @@ -25,96 +25,96 @@ module Support describe Color do it "converts rgb to rgb" do str = "rgb(1, 2, 3)" - Color.from_string(str).rgb.should == str + expect(Color.from_string(str).rgb).to eq(str) end it "converts rgb to rgba" do str = "rgb(1, 2, 3)" - Color.from_string(str).rgba.should == "rgba(1, 2, 3, 1)" + expect(Color.from_string(str).rgba).to eq("rgba(1, 2, 3, 1)") end it "converts rgb percent to rgba" do str = "rgb(10%, 20%, 30%)" - Color.from_string(str).rgba.should == "rgba(25, 51, 76, 1)" + expect(Color.from_string(str).rgba).to eq("rgba(25, 51, 76, 1)") end it "allows whitespace in rgb string" do str = "rgb(\t1, 2 , 3)" - Color.from_string(str).rgb.should == "rgb(1, 2, 3)" + expect(Color.from_string(str).rgb).to eq("rgb(1, 2, 3)") end it "converts rgba to rgba" do str = "rgba(1, 2, 3, 0.5)" - Color.from_string(str).rgba.should == str + expect(Color.from_string(str).rgba).to eq(str) end it "converts rgba percent to rgba" do str = "rgba(10%, 20%, 30%, 0.5)" - Color.from_string(str).rgba.should == "rgba(25, 51, 76, 0.5)" + expect(Color.from_string(str).rgba).to eq("rgba(25, 51, 76, 0.5)") end it "converts hex to hex" do str = "#ff00a0" - Color.from_string(str).hex.should == str + expect(Color.from_string(str).hex).to eq(str) end it "converts hex to rgb" do hex = "#01Ff03" rgb = "rgb(1, 255, 3)" - Color.from_string(hex).rgb.should == rgb + expect(Color.from_string(hex).rgb).to eq(rgb) end it "converts hex to rgba" do hex = "#01Ff03" rgba = "rgba(1, 255, 3, 1)" - Color.from_string(hex).rgba.should == rgba + expect(Color.from_string(hex).rgba).to eq(rgba) hex = "#00ff33"; rgba = "rgba(0, 255, 51, 1)" - Color.from_string(hex).rgba.should == rgba + expect(Color.from_string(hex).rgba).to eq(rgba) end it "converts rgb to hex" do - Color.from_string("rgb(1, 255, 3)").hex.should == "#01ff03" + expect(Color.from_string("rgb(1, 255, 3)").hex).to eq("#01ff03") end it "converts hex3 to rgba" do - Color.from_string("#0f3").rgba.should == "rgba(0, 255, 51, 1)" + expect(Color.from_string("#0f3").rgba).to eq("rgba(0, 255, 51, 1)") end it "converts hsl to rgba" do hsl = "hsl(120, 100%, 25%)" rgba = "rgba(0, 128, 0, 1)" - Color.from_string(hsl).rgba.should == rgba + expect(Color.from_string(hsl).rgba).to eq(rgba) hsl = "hsl(100, 0%, 50%)" rgba = "rgba(128, 128, 128, 1)" - Color.from_string(hsl).rgba.should == "rgba(128, 128, 128, 1)" + expect(Color.from_string(hsl).rgba).to eq("rgba(128, 128, 128, 1)") end it "converts hsla to rgba" do hsla = "hsla(120, 100%, 25%, 1)" rgba = "rgba(0, 128, 0, 1)" - Color.from_string(hsla).rgba.should == rgba + expect(Color.from_string(hsla).rgba).to eq(rgba) hsla = "hsla(100, 0%, 50%, 0.5)" rgba = "rgba(128, 128, 128, 0.5)" - Color.from_string(hsla).rgba.should == rgba + expect(Color.from_string(hsla).rgba).to eq(rgba) end it "is equal to a color with the same values" do rgba = "rgba(30, 30, 30, 0.2)" other = "rgba(30, 30, 30, 1)" - Color.from_string(rgba).should == Color.from_string(rgba) - Color.from_string(rgba).should_not == Color.from_string(other) + expect(Color.from_string(rgba)).to eq(Color.from_string(rgba)) + expect(Color.from_string(rgba)).not_to eq(Color.from_string(other)) end it "implements #hash correctly" do @@ -127,7 +127,7 @@ module Support h[b] = 2 h[c] = 3 - h.values.sort.should == [2, 3] + expect(h.values.sort).to eq([2, 3]) end end diff --git a/rb/spec/unit/selenium/webdriver/support/event_firing_spec.rb b/rb/spec/unit/selenium/webdriver/support/event_firing_spec.rb index b109169f0ba31..5647449d19aa6 100644 --- a/rb/spec/unit/selenium/webdriver/support/event_firing_spec.rb +++ b/rb/spec/unit/selenium/webdriver/support/event_firing_spec.rb @@ -34,25 +34,25 @@ module Support it "fires events for navigate.to" do url = "http://example.com" - listener.should_receive(:before_navigate_to).with(url, instance_of(Driver)) - bridge.should_receive(:get).with(url) - listener.should_receive(:after_navigate_to).with(url, instance_of(Driver)) + expect(listener).to receive(:before_navigate_to).with(url, instance_of(Driver)) + expect(bridge).to receive(:get).with(url) + expect(listener).to receive(:after_navigate_to).with(url, instance_of(Driver)) driver.navigate.to(url) end it "fires events for navigate.back" do - listener.should_receive(:before_navigate_back).with instance_of(Driver) - bridge.should_receive(:goBack) - listener.should_receive(:after_navigate_back).with instance_of(Driver) + expect(listener).to receive(:before_navigate_back).with instance_of(Driver) + expect(bridge).to receive(:goBack) + expect(listener).to receive(:after_navigate_back).with instance_of(Driver) driver.navigate.back end it "fires events for navigate.forward" do - listener.should_receive(:before_navigate_forward).with instance_of(Driver) - bridge.should_receive(:goForward) - listener.should_receive(:after_navigate_forward).with instance_of(Driver) + expect(listener).to receive(:before_navigate_forward).with instance_of(Driver) + expect(bridge).to receive(:goForward) + expect(listener).to receive(:after_navigate_forward).with instance_of(Driver) driver.navigate.forward end @@ -60,17 +60,17 @@ module Support context "finding elements" do it "fires events for find_element" do - listener.should_receive(:before_find).with('id', "foo", instance_of(Driver)) - bridge.should_receive(:find_element_by).with('id', "foo", nil).and_return(element) - listener.should_receive(:after_find).with('id', "foo", instance_of(Driver)) + expect(listener).to receive(:before_find).with('id', "foo", instance_of(Driver)) + expect(bridge).to receive(:find_element_by).with('id', "foo", nil).and_return(element) + expect(listener).to receive(:after_find).with('id', "foo", instance_of(Driver)) driver.find_element(:id => "foo") end it "fires events for find_elements" do - listener.should_receive(:before_find).with('class name', "foo", instance_of(Driver)) - bridge.should_receive(:find_elements_by).with('class name', "foo", nil).and_return([element]) - listener.should_receive(:after_find).with('class name', "foo", instance_of(Driver)) + expect(listener).to receive(:before_find).with('class name', "foo", instance_of(Driver)) + expect(bridge).to receive(:find_elements_by).with('class name', "foo", nil).and_return([element]) + expect(listener).to receive(:after_find).with('class name', "foo", instance_of(Driver)) driver.find_elements(:class => "foo") end @@ -78,17 +78,17 @@ module Support context "changing elements" do it "fires events for send_keys" do - listener.should_receive(:before_change_value_of).with(instance_of(Element), instance_of(Driver)) - bridge.should_receive(:sendKeysToElement).with("ref", ["cheese"]) - listener.should_receive(:after_change_value_of).with(instance_of(Element), instance_of(Driver)) + expect(listener).to receive(:before_change_value_of).with(instance_of(Element), instance_of(Driver)) + expect(bridge).to receive(:sendKeysToElement).with("ref", ["cheese"]) + expect(listener).to receive(:after_change_value_of).with(instance_of(Element), instance_of(Driver)) element.send_keys "cheese" end it "fires events for clear" do - listener.should_receive(:before_change_value_of).with(instance_of(Element), instance_of(Driver)) - bridge.should_receive(:clearElement).with("ref") - listener.should_receive(:after_change_value_of).with(instance_of(Element), instance_of(Driver)) + expect(listener).to receive(:before_change_value_of).with(instance_of(Element), instance_of(Driver)) + expect(bridge).to receive(:clearElement).with("ref") + expect(listener).to receive(:after_change_value_of).with(instance_of(Element), instance_of(Driver)) element.clear end @@ -98,9 +98,9 @@ module Support it "fires events for execute_script" do script, arg = 'script', 'arg' - listener.should_receive(:before_execute_script).with(script, instance_of(Driver)) - bridge.should_receive(:executeScript).with(script, arg) - listener.should_receive(:after_execute_script).with(script, instance_of(Driver)) + expect(listener).to receive(:before_execute_script).with(script, instance_of(Driver)) + expect(bridge).to receive(:executeScript).with(script, arg) + expect(listener).to receive(:after_execute_script).with(script, instance_of(Driver)) driver.execute_script script, arg end @@ -108,17 +108,17 @@ module Support context "closing and quitting" do it "fires events for close" do - listener.should_receive(:before_close).with instance_of(Driver) - bridge.should_receive(:close) - listener.should_receive(:after_close).with instance_of(Driver) + expect(listener).to receive(:before_close).with instance_of(Driver) + expect(bridge).to receive(:close) + expect(listener).to receive(:after_close).with instance_of(Driver) driver.close end it "fires events for quit" do - listener.should_receive(:before_quit).with instance_of(Driver) - bridge.should_receive(:quit) - listener.should_receive(:after_quit).with instance_of(Driver) + expect(listener).to receive(:before_quit).with instance_of(Driver) + expect(bridge).to receive(:quit) + expect(listener).to receive(:after_quit).with instance_of(Driver) driver.quit end diff --git a/rb/spec/unit/selenium/webdriver/support/select_spec.rb b/rb/spec/unit/selenium/webdriver/support/select_spec.rb index 997fcf2857bf0..8945ecb1d4236 100644 --- a/rb/spec/unit/selenium/webdriver/support/select_spec.rb +++ b/rb/spec/unit/selenium/webdriver/support/select_spec.rb @@ -30,7 +30,7 @@ module Support let(:multi_select) { s = double(Element, :tag_name => 'select') - s.stub(:attribute).with(:multiple).and_return "multiple" + allow(s).to receive(:attribute).with(:multiple).and_return "multiple" s } @@ -38,9 +38,9 @@ module Support it 'raises ArgumentError if passed a non-select Element' do link = double(Element, :tag_name => "a") - lambda { + expect { Select.new link - }.should raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it 'indicates whether a select is multiple correctly' do @@ -51,78 +51,78 @@ module Support double(Element, :tag_name => "select") ] - selects[0].stub(:attribute).with(:multiple).and_return("false") - selects[1].stub(:attribute).with(:multiple).and_return(nil) - selects[2].stub(:attribute).with(:multiple).and_return("true") - selects[3].stub(:attribute).with(:multiple).and_return("multiple") + allow(selects[0]).to receive(:attribute).with(:multiple).and_return("false") + allow(selects[1]).to receive(:attribute).with(:multiple).and_return(nil) + allow(selects[2]).to receive(:attribute).with(:multiple).and_return("true") + allow(selects[3]).to receive(:attribute).with(:multiple).and_return("multiple") - Select.new(selects[0]).should_not be_multiple - Select.new(selects[1]).should_not be_multiple - Select.new(selects[2]).should be_multiple - Select.new(selects[3]).should be_multiple + expect(Select.new(selects[0])).not_to be_multiple + expect(Select.new(selects[1])).not_to be_multiple + expect(Select.new(selects[2])).to be_multiple + expect(Select.new(selects[3])).to be_multiple end it 'returns all options' do options = [] - multi_select.should_receive(:find_elements). + expect(multi_select).to receive(:find_elements). with(:tag_name, 'option'). once. and_return(options) - Select.new(multi_select).options.should eql(options) + expect(Select.new(multi_select).options).to eql(options) end it 'returns all selected options' do bad_option = double(Element, :selected? => false) good_option = double(Element, :selected? => true) - multi_select.should_receive(:find_elements). + expect(multi_select).to receive(:find_elements). with(:tag_name, 'option'). once. and_return([bad_option, good_option]) opts = Select.new(multi_select).selected_options - opts.size.should == 1 - opts.first.should == good_option + expect(opts.size).to eq(1) + expect(opts.first).to eq(good_option) end it 'returns the first selected option' do first_option = double(Element, :selected? => true) second_option = double(Element, :selected? => true) - multi_select.should_receive(:find_elements). + expect(multi_select).to receive(:find_elements). with(:tag_name, 'option'). once. and_return([first_option, second_option]) option = Select.new(multi_select).first_selected_option - option.should == first_option + expect(option).to eq(first_option) end it 'raises a NoSuchElementError if nothing is selected' do option = double(Element, :selected? => false) - multi_select.should_receive(:find_elements). + expect(multi_select).to receive(:find_elements). with(:tag_name, 'option'). once. and_return([option]) - lambda { + expect { Select.new(multi_select).first_selected_option - }.should raise_error(Error::NoSuchElementError) + }.to raise_error(Error::NoSuchElementError) end it 'allows options to be selected by visible text' do option = double(Element, :selected? => false) - multi_select.should_receive(:find_elements). + expect(multi_select).to receive(:find_elements). with(:xpath, './/option[normalize-space(.) = "fish"]'). once. and_return([option]) - option.should_receive(:click).once + expect(option).to receive(:click).once Select.new(multi_select).select_by(:text, 'fish') end @@ -131,13 +131,13 @@ module Support first_option = double(Element, :selected? => true) second_option = double(Element, :selected? => false) - first_option.should_receive(:attribute).with(:index).and_return "0" - first_option.should_receive(:click).never + expect(first_option).to receive(:attribute).with(:index).and_return "0" + expect(first_option).to receive(:click).never - second_option.should_receive(:attribute).with(:index).and_return '1' - second_option.should_receive(:click).once + expect(second_option).to receive(:attribute).with(:index).and_return '1' + expect(second_option).to receive(:click).once - multi_select.should_receive(:find_elements). + expect(multi_select).to receive(:find_elements). with(:tag_name, 'option'). and_return([first_option, second_option]) @@ -146,11 +146,11 @@ module Support it 'allows options to be selected by returned value' do first_option = double(Element, :selected? => false) - multi_select.should_receive(:find_elements). + expect(multi_select).to receive(:find_elements). with(:xpath, './/option[@value = "b"]'). and_return([first_option]) - first_option.should_receive(:click).once + expect(first_option).to receive(:click).once Select.new(multi_select).select_by(:value, 'b') end @@ -159,35 +159,35 @@ module Support first_option = double(Element, :selected? => true) second_option = double(Element, :selected? => false) - multi_select.should_receive(:find_elements). + expect(multi_select).to receive(:find_elements). with(:tag_name, 'option'). once. and_return([first_option, second_option]) - first_option.should_receive(:click).once - second_option.should_receive(:click).never + expect(first_option).to receive(:click).once + expect(second_option).to receive(:click).never Select.new(multi_select).deselect_all end it 'can not deselect all when select does not support multiple selections' do - select.should_receive(:attribute).with(:multiple).and_return nil + expect(select).to receive(:attribute).with(:multiple).and_return nil - lambda { + expect { Select.new(select).deselect_all - }.should raise_error(Error::UnsupportedOperationError) + }.to raise_error(Error::UnsupportedOperationError) end it 'can deselect options by visible text' do first_option = double(Element, :selected? => true) second_option = double(Element, :selected? => false) - multi_select.should_receive(:find_elements). + expect(multi_select).to receive(:find_elements). with(:xpath, './/option[normalize-space(.) = "b"]'). and_return([first_option, second_option]) - first_option.should_receive(:click).once - second_option.should_receive(:click).never + expect(first_option).to receive(:click).once + expect(second_option).to receive(:click).never Select.new(multi_select).deselect_by(:text, 'b') end @@ -196,15 +196,15 @@ module Support first_option = double(Element, :selected? => true) second_option = double(Element) - multi_select.should_receive(:find_elements). + expect(multi_select).to receive(:find_elements). with(:tag_name, 'option'). and_return([first_option, second_option]) - first_option.should_receive(:attribute).with(:index).and_return("2") - second_option.should_receive(:attribute).with(:index).and_return("1") + expect(first_option).to receive(:attribute).with(:index).and_return("2") + expect(second_option).to receive(:attribute).with(:index).and_return("1") - first_option.should_receive(:click).once - second_option.should_receive(:click).never + expect(first_option).to receive(:click).once + expect(second_option).to receive(:click).never Select.new(multi_select).deselect_by(:index, 2) end @@ -213,94 +213,94 @@ module Support first_option = double(Element, :selected? => true) second_option = double(Element, :selected? => false) - multi_select.should_receive(:find_elements). + expect(multi_select).to receive(:find_elements). with(:xpath, './/option[@value = "b"]'). and_return([first_option, second_option]) - first_option.should_receive(:click).once - second_option.should_receive(:click).never + expect(first_option).to receive(:click).once + expect(second_option).to receive(:click).never Select.new(multi_select).deselect_by(:value, 'b') end it 'should fall back to slow lookups when "get by visible text fails" and there is a space' do first_option = double(Element, :selected? => false, :text => 'foo bar') - first_option.stub(:to_a => [first_option]) + allow(first_option).to receive_messages(:to_a => [first_option]) xpath1 = './/option[normalize-space(.) = "foo bar"]' xpath2 = './/option[contains(., "foo")]' - select.should_receive(:attribute).with(:multiple).and_return 'false' - select.should_receive(:find_elements).with(:xpath, xpath1).once.and_return([]) - select.should_receive(:find_elements).with(:xpath, xpath2).once.and_return([first_option]) + expect(select).to receive(:attribute).with(:multiple).and_return 'false' + expect(select).to receive(:find_elements).with(:xpath, xpath1).once.and_return([]) + expect(select).to receive(:find_elements).with(:xpath, xpath2).once.and_return([first_option]) - first_option.should_receive(:click).once + expect(first_option).to receive(:click).once Select.new(select).select_by(:text, 'foo bar') end it 'should raise NoSuchElementError if there are no selects to select' do - select.should_receive(:attribute).with(:multiple).and_return('false') - select.should_receive(:find_elements).at_least(3).times.and_return [] + expect(select).to receive(:attribute).with(:multiple).and_return('false') + expect(select).to receive(:find_elements).at_least(3).times.and_return [] s = Select.new select - lambda { + expect { s.select_by :index, 12 - }.should raise_error(Error::NoSuchElementError) + }.to raise_error(Error::NoSuchElementError) - lambda { + expect { s.select_by :value, 'not there' - }.should raise_error(Error::NoSuchElementError) + }.to raise_error(Error::NoSuchElementError) - lambda { + expect { s.select_by :text, 'also not there' - }.should raise_error(Error::NoSuchElementError) + }.to raise_error(Error::NoSuchElementError) end it 'should raise NoSuchElementError if there are no selects to deselect' do - select.should_receive(:attribute).with(:multiple).and_return('false') - select.should_receive(:find_elements).at_least(3).times.and_return [] + expect(select).to receive(:attribute).with(:multiple).and_return('false') + expect(select).to receive(:find_elements).at_least(3).times.and_return [] s = Select.new select - lambda { + expect { s.deselect_by :index, 12 - }.should raise_error(Error::NoSuchElementError) + }.to raise_error(Error::NoSuchElementError) - lambda { + expect { s.deselect_by :value, 'not there' - }.should raise_error(Error::NoSuchElementError) + }.to raise_error(Error::NoSuchElementError) - lambda { + expect { s.deselect_by :text, 'also not there' - }.should raise_error(Error::NoSuchElementError) + }.to raise_error(Error::NoSuchElementError) end end # Select describe Select::Escaper do it 'converts an unquoted string into one with quotes' do - Select::Escaper.escape('abc').should == '"abc"' - Select::Escaper.escape('abc aqewqqw').should == '"abc aqewqqw"' - Select::Escaper.escape('').should == '""' - Select::Escaper.escape(' ').should == '" "' - Select::Escaper.escape(' abc ').should == '" abc "' + expect(Select::Escaper.escape('abc')).to eq('"abc"') + expect(Select::Escaper.escape('abc aqewqqw')).to eq('"abc aqewqqw"') + expect(Select::Escaper.escape('')).to eq('""') + expect(Select::Escaper.escape(' ')).to eq('" "') + expect(Select::Escaper.escape(' abc ')).to eq('" abc "') end it 'double quotes a string that contains a single quote' do - Select::Escaper.escape("f'oo").should == %{"f'oo"} + expect(Select::Escaper.escape("f'oo")).to eq(%{"f'oo"}) end it 'single quotes a string that contains a double quote' do - Select::Escaper.escape('f"oo').should == %{'f"oo'} + expect(Select::Escaper.escape('f"oo')).to eq(%{'f"oo'}) end it 'provides concatenated strings when string to escape contains both single and double quotes' do - Select::Escaper.escape(%{f"o'o}).should == %{concat("f", '"', "o'o")} + expect(Select::Escaper.escape(%{f"o'o})).to eq(%{concat("f", '"', "o'o")}) end it 'provides concatenated strings when string ends with quote' do - Select::Escaper.escape(%{'"}).should == %{concat("'", '"')} + expect(Select::Escaper.escape(%{'"})).to eq(%{concat("'", '"')}) end end # Select::Escaper diff --git a/rb/spec/unit/selenium/webdriver/wait_spec.rb b/rb/spec/unit/selenium/webdriver/wait_spec.rb index c6438be64e54e..45d91ca675f42 100644 --- a/rb/spec/unit/selenium/webdriver/wait_spec.rb +++ b/rb/spec/unit/selenium/webdriver/wait_spec.rb @@ -27,13 +27,13 @@ def wait(*args) Wait.new(*args) end it 'should wait until the returned value is true' do returned = true - wait.until { returned = !returned }.should be true + expect(wait.until { returned = !returned }).to be true end it 'should raise a TimeOutError if the the timer runs out' do - lambda { + expect { wait(:timeout => 0.1).until { false } - }.should raise_error(Error::TimeOutError) + }.to raise_error(Error::TimeOutError) end it "should silently capture NoSuchElementErrors" do @@ -47,21 +47,21 @@ def wait(*args) Wait.new(*args) end end } - wait.until(&block).should be true + expect(wait.until(&block)).to be true end it "will use the message from any NoSuchElementError raised while waiting" do block = lambda { raise Error::NoSuchElementError, "foo" } - lambda { + expect { wait(:timeout => 0.5).until(&block) - }.should raise_error(Error::TimeOutError, /foo/) + }.to raise_error(Error::TimeOutError, /foo/) end it "should let users configure what exceptions to ignore" do - lambda { + expect { wait(:ignore => NoMethodError, :timeout => 0.5).until { raise NoMethodError } - }.should raise_error(Error::TimeOutError, /NoMethodError/) + }.to raise_error(Error::TimeOutError, /NoMethodError/) end end end