Skip to content

Commit

Permalink
rb: Switch to RSpec expect syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
p0deje committed Sep 17, 2015
1 parent 87730e4 commit dd422b8
Show file tree
Hide file tree
Showing 67 changed files with 1,003 additions and 1,003 deletions.
2 changes: 1 addition & 1 deletion rb/selenium-webdriver.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 9 additions & 9 deletions rb/spec/integration/selenium/client/api/click_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 11 additions & 11 deletions rb/spec/integration/selenium/client/api/cookie_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,35 @@
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
page.open "http://localhost:4444/selenium-server/org/openqa/selenium/tests/html/path1/cookie1.html"
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
6 changes: 3 additions & 3 deletions rb/spec/integration/selenium/client/api/element_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions rb/spec/integration/selenium/client/api/screenshot_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 =~ /<head>/
expect(page.get_html_source).to match(/<head>/)
end

# Raising Java Error on Windows
Expand All @@ -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

Expand All @@ -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
16 changes: 8 additions & 8 deletions rb/spec/integration/selenium/client/api/select_window_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions rb/spec/integration/selenium/client/api/wait_for_ajax_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,24 @@
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

describe "jQuery" do
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@
selenium.start :driver => webdriver

selenium.open '/'
selenium.title.should == webdriver.title
expect(selenium.title).to eq(webdriver.title)
end
end
12 changes: 6 additions & 6 deletions rb/spec/integration/selenium/webdriver/app_cache_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions rb/spec/integration/selenium/webdriver/chrome/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading

0 comments on commit dd422b8

Please sign in to comment.