diff --git a/.travis.yml b/.travis.yml index 5bec8e4..22914ee 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,15 +28,15 @@ matrix: gemfile: gemfiles/2.7.gemfile env: QMAKE=/usr/lib/x86_64-linux-gnu/qt4/bin/qmake - rvm: 1.9.3 - gemfile: gemfiles/2.11.gemfile + gemfile: gemfiles/2.12.gemfile env: QMAKE=/usr/lib/x86_64-linux-gnu/qt4/bin/qmake - - rvm: 2.3.1 + - rvm: 2.3.3 gemfile: gemfiles/master.gemfile allow_failures: - gemfile: gemfiles/master.gemfile gemfile: - gemfiles/2.7.gemfile - - gemfiles/2.11.gemfile + - gemfiles/2.12.gemfile before_install: - gem install bundler install: bundle diff --git a/Appraisals b/Appraisals index ad81039..731e804 100644 --- a/Appraisals +++ b/Appraisals @@ -1,11 +1,12 @@ appraise "2.7" do gem "capybara", "~> 2.7.0" + gem "rspec", "~> 2.14.0" gem 'addressable', '< 2.5.0', :platforms=>[:ruby_19, :jruby_19] # 2.5 requires public_suffix which requires ruby 2.0 gem 'nokogiri', '< 1.7.0', :platforms=>[:ruby_19, :jruby_19] # 1.7.0 requires ruby 2.1+ end -appraise "2.11" do - gem "capybara", "~> 2.11.0" +appraise "2.12" do + gem "capybara", "~> 2.12.0" gem 'addressable', '< 2.5.0', :platforms=>[:ruby_19, :jruby_19] # 2.5 requires public_suffix which requires ruby 2.0 gem 'nokogiri', '< 1.7.0', :platforms=>[:ruby_19, :jruby_19] # 1.7.0 requires ruby 2.1+ end diff --git a/Gemfile.lock b/Gemfile.lock index 40e38c3..f2724da 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -13,17 +13,17 @@ GEM appraisal (0.4.1) bundler rake - capybara (2.11.0) + capybara (2.12.0) addressable mime-types (>= 1.16) nokogiri (>= 1.3.3) rack (>= 1.0.0) rack-test (>= 0.5.4) xpath (~> 2.0) - diff-lcs (1.2.5) - ffi (1.9.14-java) - json (1.8.3) - json (1.8.3-java) + diff-lcs (1.3) + ffi (1.9.17-java) + json (1.8.6) + json (1.8.6-java) launchy (2.4.3) addressable (~> 2.3) launchy (2.4.3-java) @@ -34,6 +34,9 @@ GEM mini_portile2 (2.1.0) nokogiri (1.7.0.1) mini_portile2 (~> 2.1.0) + nokogiri (1.7.0.1-java) + nokogiri (1.7.0.1-x86-mingw32) + mini_portile2 (~> 2.1.0) public_suffix (2.0.5) rack (1.6.5) rack-protection (1.5.3) @@ -41,21 +44,26 @@ GEM rack-test (0.6.3) rack (>= 1.0) rake (11.3.0) - rspec (2.99.0) - rspec-core (~> 2.99.0) - rspec-expectations (~> 2.99.0) - rspec-mocks (~> 2.99.0) - rspec-core (2.99.2) - rspec-expectations (2.99.2) - diff-lcs (>= 1.1.3, < 2.0) - rspec-mocks (2.99.4) - sinatra (1.4.7) + rspec (3.5.0) + rspec-core (~> 3.5.0) + rspec-expectations (~> 3.5.0) + rspec-mocks (~> 3.5.0) + rspec-core (3.5.4) + rspec-support (~> 3.5.0) + rspec-expectations (3.5.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.5.0) + rspec-mocks (3.5.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.5.0) + rspec-support (3.5.0) + sinatra (1.4.8) rack (~> 1.5) rack-protection (~> 1.4) tilt (>= 1.3, < 3) spoon (0.0.6) ffi - tilt (2.0.5) + tilt (2.0.6) xpath (2.0.0) nokogiri (~> 1.3) @@ -72,8 +80,8 @@ DEPENDENCIES mime-types (< 3.0) mini_magick rake (< 12.0.0) - rspec (~> 2.14) + rspec (~> 3.5) sinatra BUNDLED WITH - 1.13.6 + 1.14.3 diff --git a/capybara-webkit.gemspec b/capybara-webkit.gemspec index 45e5720..6cc687a 100644 --- a/capybara-webkit.gemspec +++ b/capybara-webkit.gemspec @@ -24,7 +24,7 @@ Gem::Specification.new do |s| s.add_runtime_dependency("capybara", ">= 2.3.0", "< 2.13.0") s.add_runtime_dependency("json") - s.add_development_dependency("rspec", "~> 2.14") + s.add_development_dependency("rspec", "~> 3.5") # Sinatra is used by Capybara's TestApp s.add_development_dependency("sinatra") s.add_development_dependency("mini_magick") diff --git a/gemfiles/2.11.gemfile b/gemfiles/2.12.gemfile similarity index 86% rename from gemfiles/2.11.gemfile rename to gemfiles/2.12.gemfile index 625fb3f..557bb16 100644 --- a/gemfiles/2.11.gemfile +++ b/gemfiles/2.12.gemfile @@ -4,7 +4,7 @@ source "https://rubygems.org" gem "mime-types", "< 3.0", :platforms=>[:ruby_19, :jruby_19] gem "json", "< 2.0", :platforms=>[:ruby_19, :jruby_19] -gem "capybara", "~> 2.11.0" +gem "capybara", "~> 2.12.0" gem "addressable", "< 2.5.0", :platforms=>[:ruby_19, :jruby_19] gem "nokogiri", "< 1.7.0", :platforms=>[:ruby_19, :jruby_19] diff --git a/gemfiles/2.7.gemfile b/gemfiles/2.7.gemfile index 12bcf40..e96644a 100644 --- a/gemfiles/2.7.gemfile +++ b/gemfiles/2.7.gemfile @@ -5,6 +5,7 @@ source "https://rubygems.org" gem "mime-types", "< 3.0", :platforms=>[:ruby_19, :jruby_19] gem "json", "< 2.0", :platforms=>[:ruby_19, :jruby_19] gem "capybara", "~> 2.7.0" +gem "rspec", "~> 2.14.0" gem "addressable", "< 2.5.0", :platforms=>[:ruby_19, :jruby_19] gem "nokogiri", "< 1.7.0", :platforms=>[:ruby_19, :jruby_19] diff --git a/lib/capybara/webkit/matchers.rb b/lib/capybara/webkit/matchers.rb index 715d605..4a0cdb5 100644 --- a/lib/capybara/webkit/matchers.rb +++ b/lib/capybara/webkit/matchers.rb @@ -7,11 +7,13 @@ module Capybara actual.error_messages.any? end - failure_message_for_should do |actual| + #RSpec 2 compatability + send(respond_to?(:failure_message) ? :failure_message : :failure_message_for_should) do |_actual| "Expected Javascript errors, but there were none." end - - failure_message_for_should_not do |actual| + + #RSpec 2 compatability + send(respond_to?(:failure_message_when_negated) ? :failure_message_when_negated : :failure_message_for_should_not) do |actual| actual = resolve(actual) "Expected no Javascript errors, got:\n#{error_messages_for(actual)}" end diff --git a/lib/capybara/webkit/node.rb b/lib/capybara/webkit/node.rb index 11619bc..c519515 100644 --- a/lib/capybara/webkit/node.rb +++ b/lib/capybara/webkit/node.rb @@ -59,7 +59,7 @@ module Capybara::Webkit when String key.to_s else - raise Capybara::NotSupportedByDriverError.new + raise Capybara::NotSupportedByDriverError.new, "Unrecognized key(s) in #{key}" end }.join) end diff --git a/spec/browser_spec.rb b/spec/browser_spec.rb index 8f8dd08..a74096b 100644 --- a/spec/browser_spec.rb +++ b/spec/browser_spec.rb @@ -21,11 +21,9 @@ describe Capybara::Webkit::Browser do end it "doesn't try to read an empty response" do - connection = double("connection") - connection.stub(:puts) - connection.stub(:print) - connection.stub(:gets).and_return("ok\n", "0\n") - connection.stub(:read).and_raise(StandardError.new("tried to read empty response")) + connection = double("connection", puts: nil, print: nil) + allow(connection).to receive(:gets).and_return("ok\n", "0\n") + allow(connection).to receive(:read).and_raise(StandardError.new("tried to read empty response")) browser = Capybara::Webkit::Browser.new(connection) @@ -37,9 +35,9 @@ describe Capybara::Webkit::Browser do it 'raises an error of given class' do error_json = '{"class": "ClickFailed"}' - connection.should_receive(:gets).ordered.and_return 'error' - connection.should_receive(:gets).ordered.and_return error_json.bytesize - connection.stub read: error_json + expect(connection).to receive(:gets).ordered.and_return 'error' + expect(connection).to receive(:gets).ordered.and_return error_json.bytesize + allow(connection).to receive(:read).and_return(error_json) expect { browser.command 'blah', 'meh' }.to raise_error(Capybara::Webkit::ClickFailed) end diff --git a/spec/capybara_webkit_builder_spec.rb b/spec/capybara_webkit_builder_spec.rb index 1b7a37c..474fc19 100644 --- a/spec/capybara_webkit_builder_spec.rb +++ b/spec/capybara_webkit_builder_spec.rb @@ -6,25 +6,25 @@ describe CapybaraWebkitBuilder do it "will use the env variable for #make_bin" do with_env_vars("MAKE" => "fake_make") do - builder.make_bin.should == "fake_make" + expect(builder.make_bin).to eq "fake_make" end end it "will use the env variable for #qmake_bin" do with_env_vars("QMAKE" => "fake_qmake") do - builder.qmake_bin.should == "fake_qmake" + expect(builder.qmake_bin).to eq "fake_qmake" end end it "defaults the #make_bin" do with_env_vars("MAKE_BIN" => nil) do - builder.make_bin.should == 'make' + expect(builder.make_bin).to eq 'make' end end it "defaults the #qmake_bin" do with_env_vars("QMAKE" => nil) do - builder.qmake_bin.should == 'qmake' + expect(builder.qmake_bin).to eq 'qmake' end end end diff --git a/spec/connection_spec.rb b/spec/connection_spec.rb index 6aa3601..c027829 100644 --- a/spec/connection_spec.rb +++ b/spec/connection_spec.rb @@ -5,13 +5,12 @@ describe Capybara::Webkit::Connection do it "sets appropriate options on its socket" do socket = double("socket") server = double(:Server, start: nil, port: 123) - TCPSocket.stub(:open).and_return(socket) + allow(TCPSocket).to receive(:open).and_return(socket) if defined?(Socket::TCP_NODELAY) - socket. - should_receive(:setsockopt). + expect(socket).to receive(:setsockopt). with(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, true) else - socket.should_not_receive(:setsockopt) + expect(socket).not_to receive(:setsockopt) end Capybara::Webkit::Connection.new(server: server) diff --git a/spec/cookie_jar_spec.rb b/spec/cookie_jar_spec.rb index ae74198..df8602d 100644 --- a/spec/cookie_jar_spec.rb +++ b/spec/cookie_jar_spec.rb @@ -4,7 +4,7 @@ require 'capybara/webkit/cookie_jar' describe Capybara::Webkit::CookieJar do let(:browser) { browser = double("Browser") - browser.stub(:get_cookies) { [ + allow(browser).to receive(:get_cookies) { [ "cookie1=1; domain=.example.org; path=/", "cookie1=2; domain=.example.org; path=/dir1/", "cookie1=3; domain=.facebook.com; path=/", @@ -17,32 +17,32 @@ describe Capybara::Webkit::CookieJar do describe "#find" do it "returns a cookie object" do - subject.find("cookie1", "www.facebook.com").domain.should eq ".facebook.com" + expect(subject.find("cookie1", "www.facebook.com").domain).to eq ".facebook.com" end it "returns the right cookie for every given domain/path" do - subject.find("cookie1", "example.org").value.should eq "1" - subject.find("cookie1", "www.facebook.com").value.should eq "3" - subject.find("cookie2", "sub1.example.org").value.should eq "4" + expect(subject.find("cookie1", "example.org").value).to eq "1" + expect(subject.find("cookie1", "www.facebook.com").value).to eq "3" + expect(subject.find("cookie2", "sub1.example.org").value).to eq "4" end it "does not return a cookie from other domain" do - subject.find("cookie2", "www.example.org").should eq nil + expect(subject.find("cookie2", "www.example.org")).to eq nil end it "respects path precedence rules" do - subject.find("cookie1", "www.example.org").value.should eq "1" - subject.find("cookie1", "www.example.org", "/dir1/123").value.should eq "2" + expect(subject.find("cookie1", "www.example.org").value).to eq "1" + expect(subject.find("cookie1", "www.example.org", "/dir1/123").value).to eq "2" end end describe "#[]" do it "returns the first matching cookie's value" do - subject["cookie1", "example.org"].should eq "1" + expect(subject["cookie1", "example.org"]).to eq "1" end it "returns nil if no cookie is found" do - subject["notexisting"].should eq nil + expect(subject["notexisting"]).to eq nil end end end diff --git a/spec/driver_rendering_spec.rb b/spec/driver_rendering_spec.rb index 8ebded2..c478eaf 100644 --- a/spec/driver_rendering_spec.rb +++ b/spec/driver_rendering_spec.rb @@ -34,16 +34,16 @@ describe Capybara::Webkit::Driver, "rendering an image" do before { render({}) } it "should be a PNG" do - @image[:format].should eq "PNG" + expect(@image[:format]).to eq "PNG" end it "width default to 1000px (with 15px less for the scrollbar)" do - @image[:width].should be < 1001 - @image[:width].should be > 1000-17 + expect(@image[:width]).to be < 1001 + expect(@image[:width]).to be > 1000-17 end it "height should be at least 10px" do - @image[:height].should be >= 10 + expect(@image[:height]).to be >= 10 end end @@ -51,16 +51,16 @@ describe Capybara::Webkit::Driver, "rendering an image" do before { render(:width => 500, :height => 400) } it "width should match the width given" do - @image[:width].should eq 500 + expect(@image[:width]).to eq 500 end it "height should match the height given" do - @image[:height].should eq 400 + expect(@image[:height]).to eq 400 end it "should reset window dimensions to their default value" do - driver.evaluate_script('window.innerWidth').should eq 1680 - driver.evaluate_script('window.innerHeight').should eq 1050 + expect(driver.evaluate_script('window.innerWidth')).to eq 1680 + expect(driver.evaluate_script('window.innerHeight')).to eq 1050 end end @@ -68,16 +68,16 @@ describe Capybara::Webkit::Driver, "rendering an image" do before { render(:width => 50, :height => 10) } it "width should be greater than the width given" do - @image[:width].should be > 50 + expect(@image[:width]).to be > 50 end it "height should be greater than the height given" do - @image[:height].should be > 10 + expect(@image[:height]).to be > 10 end it "should restore viewport dimensions after rendering" do - driver.evaluate_script('window.innerWidth').should eq 1680 - driver.evaluate_script('window.innerHeight').should eq 1050 + expect(driver.evaluate_script('window.innerWidth')).to eq 1680 + expect(driver.evaluate_script('window.innerHeight')).to eq 1050 end end @@ -86,8 +86,8 @@ describe Capybara::Webkit::Driver, "rendering an image" do it "should restore viewport dimensions after rendering" do render({}) - driver.evaluate_script('window.innerWidth').should eq 800 - driver.evaluate_script('window.innerHeight').should eq 600 + expect(driver.evaluate_script('window.innerWidth')).to eq 800 + expect(driver.evaluate_script('window.innerHeight')).to eq 600 end end diff --git a/spec/driver_resize_window_spec.rb b/spec/driver_resize_window_spec.rb index 88168c5..3018ab7 100644 --- a/spec/driver_resize_window_spec.rb +++ b/spec/driver_resize_window_spec.rb @@ -27,23 +27,23 @@ describe Capybara::Webkit::Driver, "#resize_window(width, height)" do driver.visit("#{AppRunner.app_host}/") driver.resize_window(800, 600) - driver.html.should include("[800x600]") + expect(driver.html).to include("[800x600]") driver.resize_window(300, 100) - driver.html.should include("[300x100]") + expect(driver.html).to include("[300x100]") end it "resizes the window to the specified size even before the document has loaded" do driver.resize_window(800, 600) driver.visit("#{AppRunner.app_host}/") - driver.html.should include("[800x600]") + expect(driver.html).to include("[800x600]") end it "resets the window to the default size when the driver is reset" do driver.resize_window(800, 600) driver.reset! driver.visit("#{AppRunner.app_host}/") - driver.html.should include(DEFAULT_DIMENTIONS) + expect(driver.html).to include(DEFAULT_DIMENTIONS) end it "resizes windows by handle" do @@ -54,8 +54,8 @@ describe Capybara::Webkit::Driver, "#resize_window(width, height)" do driver.resize_window_to(driver.window_handles.first, 800, 600) driver.resize_window_to(driver.window_handles.last, 400, 300) - driver.window_size(driver.window_handles.first).should eq [800, 600] - driver.window_size(driver.window_handles.last).should eq [400, 300] + expect(driver.window_size(driver.window_handles.first)).to eq [800, 600] + expect(driver.window_size(driver.window_handles.last)).to eq [400, 300] end it "maximizes a window" do @@ -64,7 +64,7 @@ describe Capybara::Webkit::Driver, "#resize_window(width, height)" do driver.maximize_window(driver.current_window_handle) width, height = *driver.window_size(driver.current_window_handle) - width.should be > 400 - height.should be > 300 + expect(width).to be > 400 + expect(height).to be > 300 end end diff --git a/spec/driver_spec.rb b/spec/driver_spec.rb index 1ac9462..00917c4 100644 --- a/spec/driver_spec.rb +++ b/spec/driver_spec.rb @@ -90,13 +90,13 @@ describe Capybara::Webkit::Driver do it "finds frames by index" do driver.within_frame(0) do - driver.find_xpath("//*[contains(., 'goodbye')]").should_not be_empty + expect(driver.find_xpath("//*[contains(., 'goodbye')]")).not_to be_empty end end it "finds frames by id" do driver.within_frame("f") do - driver.find_xpath("//*[contains(., 'goodbye')]").should_not be_empty + expect(driver.find_xpath("//*[contains(., 'goodbye')]")).not_to be_empty end end @@ -104,7 +104,7 @@ describe Capybara::Webkit::Driver do frame = driver.find_xpath('//iframe').first element = double(Capybara::Node::Base, base: frame) driver.within_frame(element) do - driver.find_xpath("//*[contains(., 'goodbye')]").should_not be_empty + expect(driver.find_xpath("//*[contains(., 'goodbye')]")).not_to be_empty end end @@ -112,7 +112,7 @@ describe Capybara::Webkit::Driver do frame = driver.find_xpath('//iframe').first element = double(Capybara::Node::Base, base: frame) driver.switch_to_frame(element) - driver.find_xpath("//*[contains(., 'goodbye')]").should_not be_empty + expect(driver.find_xpath("//*[contains(., 'goodbye')]")).not_to be_empty driver.switch_to_frame(:parent) end @@ -121,8 +121,8 @@ describe Capybara::Webkit::Driver do element = double(Capybara::Node::Base, base: frame) driver.switch_to_frame(element) driver.switch_to_frame(:parent) - driver.find_xpath("//*[contains(., 'greeting')]").should_not be_empty - driver.find_xpath("//*[contains(., 'goodbye')]").should be_empty + expect(driver.find_xpath("//*[contains(., 'greeting')]")).not_to be_empty + expect(driver.find_xpath("//*[contains(., 'goodbye')]")).to be_empty end it "can switch to the top frame" do @@ -132,11 +132,11 @@ describe Capybara::Webkit::Driver do frame2 = driver.find_xpath('//iframe[@id="g"]').first element2 = double(Capybara::Node::Base, base: frame2) driver.switch_to_frame(element2) - driver.find_xpath("//div[contains(., 'In frame 2')]").should_not be_empty + expect(driver.find_xpath("//div[contains(., 'In frame 2')]")).not_to be_empty driver.switch_to_frame(:top) - driver.find_xpath("//*[contains(., 'greeting')]").should_not be_empty - driver.find_xpath("//*[contains(., 'goodbye')]").should be_empty - driver.find_xpath("//div[contains(., 'In frame 2')]").should be_empty + expect(driver.find_xpath("//*[contains(., 'greeting')]")).not_to be_empty + expect(driver.find_xpath("//*[contains(., 'goodbye')]")).to be_empty + expect(driver.find_xpath("//div[contains(., 'In frame 2')]")).to be_empty end it "raises error for missing frame by index" do @@ -151,42 +151,42 @@ describe Capybara::Webkit::Driver do it "returns an attribute's value" do driver.within_frame("f") do - driver.find_xpath("//p").first["id"].should eq "farewell" + expect(driver.find_xpath("//p").first["id"]).to eq "farewell" end end it "returns an attribute's innerHTML" do - driver.find_xpath('//body').first.inner_html.should =~ %r{.*.*}m + expect(driver.find_xpath('//body').first.inner_html).to match %r{.*.*}m end it "receive an attribute's innerHTML" do driver.find_xpath('//body').first.inner_html = 'foobar' - driver.find_xpath("//body[contains(., 'foobar')]").should_not be_empty + expect(driver.find_xpath("//body[contains(., 'foobar')]")).not_to be_empty end it "returns a node's text" do driver.within_frame("f") do - driver.find_xpath("//p").first.visible_text.should eq "goodbye" + expect(driver.find_xpath("//p").first.visible_text).to eq "goodbye" end end it "returns the current URL" do driver.within_frame("f") do - driver.current_url.should eq driver_url(driver, "/iframe") + expect(driver.current_url).to eq driver_url(driver, "/iframe") end end it "evaluates Javascript" do driver.within_frame("f") do result = driver.evaluate_script(%) - result.should eq "goodbye" + expect(result).to eq "goodbye" end end it "executes Javascript" do driver.within_frame("f") do driver.execute_script(%) - driver.find_xpath("//p[contains(., 'yo')]").should_not be_empty + expect(driver.find_xpath("//p[contains(., 'yo')]")).not_to be_empty end end @@ -195,24 +195,24 @@ describe Capybara::Webkit::Driver do driver.within_frame("f") {} - driver.current_url.should eq original_url + expect(driver.current_url).to eq original_url end it "returns the headers for the page" do driver.within_frame("f") do - driver.response_headers['X-Redirected'].should eq "true" + expect(driver.response_headers['X-Redirected']).to eq "true" end end it "returns the status code for the page" do driver.within_frame("f") do - driver.status_code.should eq 200 + expect(driver.status_code).to eq 200 end end it "returns the document title" do driver.within_frame("f") do - driver.title.should eq "Title" + expect(driver.title).to eq "Title" end end end @@ -281,35 +281,35 @@ describe Capybara::Webkit::Driver do it "should redirect without content type" do visit("/form") driver.find_xpath("//input").first.click - driver.find_xpath("//p").first.visible_text.should eq "" + expect(driver.find_xpath("//p").first.visible_text).to eq "" end it "returns the current URL when changed by pushState after a redirect" do visit("/redirect-me") - driver.current_url.should eq driver_url(driver, "/target") + expect(driver.current_url).to eq driver_url(driver, "/target") driver.execute_script("window.history.pushState({}, '', '/pushed-after-redirect')") - driver.current_url.should eq driver_url(driver, "/pushed-after-redirect") + expect(driver.current_url).to eq driver_url(driver, "/pushed-after-redirect") end it "returns the current URL when changed by replaceState after a redirect" do visit("/redirect-me") - driver.current_url.should eq driver_url(driver, "/target") + expect(driver.current_url).to eq driver_url(driver, "/target") driver.execute_script("window.history.replaceState({}, '', '/replaced-after-redirect')") - driver.current_url.should eq driver_url(driver, "/replaced-after-redirect") + expect(driver.current_url).to eq driver_url(driver, "/replaced-after-redirect") end it "should make headers available through response_headers" do visit('/redirect-me') - driver.response_headers['X-Redirected'].should eq "true" + expect(driver.response_headers['X-Redirected']).to eq "true" visit('/target') - driver.response_headers['X-Redirected'].should eq "false" + expect(driver.response_headers['X-Redirected']).to eq "false" end it "should make the status code available through status_code" do visit('/redirect-me') - driver.status_code.should eq 200 + expect(driver.status_code).to eq 200 visit('/target') - driver.status_code.should eq 200 + expect(driver.status_code).to eq 200 end end @@ -326,15 +326,15 @@ describe Capybara::Webkit::Driver do before { visit("/") } it "renders unsupported content types gracefully" do - driver.html.should =~ /css/ + expect(driver.html).to match /css/ end it "sets the response headers with respect to the unsupported request" do - driver.response_headers["Content-Type"].should eq "text/css" + expect(driver.response_headers["Content-Type"]).to eq "text/css" end it "does not wrap the content in HTML tags" do - driver.html.should_not =~ // + expect(driver.html).not_to match // end end @@ -355,7 +355,7 @@ describe Capybara::Webkit::Driver do before { visit("/") } it "does not strip HTML tags" do - driver.html.should =~ // + expect(driver.html).to match // end end @@ -373,7 +373,7 @@ describe Capybara::Webkit::Driver do it "should return the binary content" do src = driver.html.force_encoding('binary') - src.should eq "Hello\xFF\xFF\xFF\xFFWorld".force_encoding('binary') + expect(src).to eq "Hello\xFF\xFF\xFF\xFFWorld".force_encoding('binary') end end @@ -417,28 +417,28 @@ describe Capybara::Webkit::Driver do it "doesn't return text if the ancestor is hidden" do visit("/") - driver.find_css("#hidden-ancestor div").first.text.should eq '' + expect(driver.find_css("#hidden-ancestor div").first.text).to eq '' end it "handles anchor tags" do visit("#test") - driver.find_xpath("//*[contains(., 'hello')]").should_not be_empty + expect(driver.find_xpath("//*[contains(., 'hello')]")).not_to be_empty visit("#test") - driver.find_xpath("//*[contains(., 'hello')]").should_not be_empty + expect(driver.find_xpath("//*[contains(., 'hello')]")).not_to be_empty end it "finds content after loading a URL" do - driver.find_xpath("//*[contains(., 'hello')]").should_not be_empty + expect(driver.find_xpath("//*[contains(., 'hello')]")).not_to be_empty end it "has an empty page after reseting" do driver.reset! - driver.find_xpath("//*[contains(., 'hello')]").should be_empty + expect(driver.find_xpath("//*[contains(., 'hello')]")).to be_empty end it "has a blank location after reseting" do driver.reset! - driver.current_url.should eq "about:blank" + expect(driver.current_url).to eq "about:blank" end it "raises an error for an invalid xpath query" do @@ -452,119 +452,119 @@ describe Capybara::Webkit::Driver do end it "returns an attribute's value" do - driver.find_xpath("//p").first["id"].should eq "greeting" + expect(driver.find_xpath("//p").first["id"]).to eq "greeting" end it "parses xpath with quotes" do - driver.find_xpath('//*[contains(., "hello")]').should_not be_empty + expect(driver.find_xpath('//*[contains(., "hello")]')).not_to be_empty end it "returns a node's visible text" do - driver.find_xpath("//*[@id='hidden-text']").first.visible_text.should eq "Some of this text is" + expect(driver.find_xpath("//*[@id='hidden-text']").first.visible_text).to eq "Some of this text is" end it "normalizes a node's text" do - driver.find_xpath("//div[contains(@class, 'normalize')]").first.visible_text.should eq "Spaces not normalized" + expect(driver.find_xpath("//div[contains(@class, 'normalize')]").first.visible_text).to eq "Spaces not normalized" end it "returns all of a node's text" do - driver.find_xpath("//*[@id='hidden-text']").first.all_text.should eq "Some of this text is hidden!" + expect(driver.find_xpath("//*[@id='hidden-text']").first.all_text).to eq "Some of this text is hidden!" end it "returns the current URL" do visit "/hello/world?success=true" - driver.current_url.should eq driver_url(driver, "/hello/world?success=true") + expect(driver.current_url).to eq driver_url(driver, "/hello/world?success=true") end it "returns the current URL when changed by pushState" do driver.execute_script("window.history.pushState({}, '', '/pushed')") - driver.current_url.should eq driver_url(driver, "/pushed") + expect(driver.current_url).to eq driver_url(driver, "/pushed") end it "returns the current URL when changed by replaceState" do driver.execute_script("window.history.replaceState({}, '', '/replaced')") - driver.current_url.should eq driver_url(driver, "/replaced") + expect(driver.current_url).to eq driver_url(driver, "/replaced") end it "does not double-encode URLs" do visit("/hello/world?success=%25true") - driver.current_url.should =~ /success=\%25true/ + expect(driver.current_url).to match /success=\%25true/ end it "returns the current URL with encoded characters" do visit("/hello/world?success[value]=true") current_url = Rack::Utils.unescape(driver.current_url) - current_url.should include('success[value]=true') + expect(current_url).to include('success[value]=true') end it "visits a page with an anchor" do visit("/hello#display_none") - driver.current_url.should =~ /hello#display_none/ + expect(driver.current_url).to match /hello#display_none/ end it "evaluates Javascript and returns a string" do result = driver.evaluate_script(%) - result.should eq "hello" + expect(result).to eq "hello" end it "evaluates Javascript and returns an array" do result = driver.evaluate_script(%<["hello", "world"]>) - result.should eq %w(hello world) + expect(result).to eq %w(hello world) end it "evaluates Javascript and returns an int" do result = driver.evaluate_script(%<123>) - result.should eq 123 + expect(result).to eq 123 end it "evaluates Javascript and returns a float" do result = driver.evaluate_script(%<1.5>) - result.should eq 1.5 + expect(result).to eq 1.5 end it "evaluates Javascript and returns null" do result = driver.evaluate_script(%<(function () {})()>) - result.should eq nil + expect(result).to eq nil end it "evaluates Infinity and returns null" do result = driver.evaluate_script(%) - result.should eq nil + expect(result).to eq nil end it "evaluates Javascript and returns a date" do result = driver.evaluate_script(%) - result.should eq "2016-04-01T00:00:00Z" + expect(result).to eq "2016-04-01T00:00:00Z" end it "evaluates Javascript and returns an object" do result = driver.evaluate_script(%<({ 'one' : 1 })>) - result.should eq 'one' => 1 + expect(result).to eq 'one' => 1 end it "evaluates Javascript and returns true" do result = driver.evaluate_script(%) - result.should === true + expect(result).to be true end it "evaluates Javascript and returns false" do result = driver.evaluate_script(%) - result.should === false + expect(result).to be false end it "evaluates Javascript and returns an escaped string" do result = driver.evaluate_script(%<'"'>) - result.should === "\"" + expect(result).to eq "\"" end it "evaluates Javascript with multiple lines" do result = driver.evaluate_script("[1,\n2]") - result.should eq [1, 2] + expect(result).to eq [1, 2] end it "executes Javascript" do driver.execute_script(%) - driver.find_xpath("//p[contains(., 'yo')]").should_not be_empty + expect(driver.find_xpath("//p[contains(., 'yo')]")).not_to be_empty end it "raises an error for failing Javascript" do @@ -574,65 +574,64 @@ describe Capybara::Webkit::Driver do it "passes arguments to executed Javascript" do driver.execute_script(%, "My argument") - driver.find_xpath("//p[contains(., 'My argument')]").should_not be_empty + expect(driver.find_xpath("//p[contains(., 'My argument')]")).not_to be_empty end it "passes multiple arguments to executed Javascript" do driver.execute_script( %, "random", 4, {color: 'red'}) - driver.find_xpath("//p[contains(., 'random4red')]").should_not be_empty + expect(driver.find_xpath("//p[contains(., 'random4red')]")).not_to be_empty end it "passes page elements to executed Javascript" do greeting = driver.find_xpath("//p[@id='greeting']").first driver.execute_script(%, greeting, "new content") - driver.find_xpath("//p[@id='greeting'][contains(., 'new content')]").should_not be_empty + expect(driver.find_xpath("//p[@id='greeting'][contains(., 'new content')]")).not_to be_empty end it "passes arguments to evaaluated Javascript" do - driver.evaluate_script(%, 3).should eq 3 + expect(driver.evaluate_script(%, 3)).to eq 3 end it "passes multiple arguments to evaluated Javascript" do - driver.evaluate_script(%, 3, 4, {num: 5}).should eq 12 + expect(driver.evaluate_script(%, 3, 4, {num: 5})).to eq 12 end it "passes page elements to evaluated Javascript" do greeting = driver.find_xpath("//p[@id='greeting']").first - driver.evaluate_script(%, "newer content", greeting, 7).should eq 7 - driver.find_xpath("//p[@id='greeting'][contains(., 'newer content')]").should_not be_empty + expect(driver.evaluate_script(%, "newer content", greeting, 7)).to eq 7 + expect(driver.find_xpath("//p[@id='greeting'][contains(., 'newer content')]")).not_to be_empty end it "doesn't raise an error for Javascript that doesn't return anything" do - lambda { driver.execute_script(%<(function () { "returns nothing" })()>) }. - should_not raise_error + expect { driver.execute_script(%<(function () { "returns nothing" })()>) }.not_to raise_error end it "returns a node's tag name" do - driver.find_xpath("//p").first.tag_name.should eq "p" + expect(driver.find_xpath("//p").first.tag_name).to eq "p" end it "reads disabled property" do - driver.find_xpath("//input").first.should be_disabled + expect(driver.find_xpath("//input").first).to be_disabled end it "reads checked property" do - driver.find_xpath("//input[@id='checktest']").first.should be_checked + expect(driver.find_xpath("//input[@id='checktest']").first).to be_checked end it "finds visible elements" do - driver.find_xpath("//p").first.should be_visible - driver.find_xpath("//*[@id='invisible']").first.should_not be_visible - driver.find_xpath("//*[@id='invisible_with_visibility']").first.should_not be_visible + expect(driver.find_xpath("//p").first).to be_visible + expect(driver.find_xpath("//*[@id='invisible']").first).not_to be_visible + expect(driver.find_xpath("//*[@id='invisible_with_visibility']").first).not_to be_visible end it "returns the document title" do - driver.title.should eq "Title" + expect(driver.title).to eq "Title" end it "finds elements by CSS" do - driver.find_css("p").first.visible_text.should eq "hello" + expect(driver.find_css("p").first.visible_text).to eq "hello" end end @@ -652,7 +651,7 @@ describe Capybara::Webkit::Driver do before { visit("/") } it "should handle text for svg elements" do - driver.find_xpath("//*[@id='navy_text']").first.visible_text.should eq "In the navy!" + expect(driver.find_xpath("//*[@id='navy_text']").first.visible_text).to eq "In the navy!" end end @@ -670,7 +669,7 @@ describe Capybara::Webkit::Driver do before { visit("/") } it "has no visible text" do - driver.find_xpath("/html").first.text.should be_empty + expect(driver.find_xpath("/html").first.text).to be_empty end end @@ -699,34 +698,34 @@ describe Capybara::Webkit::Driver do it "collects messages logged to the console" do url = driver_url(driver, "/") message = driver.console_messages.first - message.should include :source => url, :message => "hello" - [6, 7].should include message[:line_number] - driver.console_messages.length.should eq 5 + expect(message).to include :source => url, :message => "hello" + expect([6, 7]).to include message[:line_number] + expect(driver.console_messages.length).to eq 5 end it "logs errors to the console" do - driver.error_messages.length.should eq 1 + expect(driver.error_messages.length).to eq 1 end it "supports multi-line console messages" do message = driver.console_messages[2] - message[:message].should eq "hello\nnewline" + expect(message[:message]).to eq "hello\nnewline" end it "empties the array when reset" do driver.reset! - driver.console_messages.should be_empty + expect(driver.console_messages).to be_empty end it "supports console messages from an unknown source" do driver.execute_script("console.log('hello')") - driver.console_messages.last[:message].should eq 'hello' - driver.console_messages.last[:source].should be_nil - driver.console_messages.last[:line_number].should be_nil + expect(driver.console_messages.last[:message]).to eq 'hello' + expect(driver.console_messages.last[:source]).to be_nil + expect(driver.console_messages.last[:line_number]).to be_nil end it "escapes unicode console messages" do - driver.console_messages[3][:message].should eq '𝄞' + expect(driver.console_messages[3][:message]).to eq '𝄞' end end @@ -821,14 +820,14 @@ describe Capybara::Webkit::Driver do alert_message = driver.accept_modal(:alert) do visit("/") end - alert_message.should eq "Alert Text\nGoes Here" + expect(alert_message).to eq "Alert Text\nGoes Here" end it 'accepts an alert modal if it matches' do alert_message = driver.accept_modal(:alert, text: "Alert Text\nGoes Here") do visit("/") end - alert_message.should eq "Alert Text\nGoes Here" + expect(alert_message).to eq "Alert Text\nGoes Here" end it 'raises an error when accepting an alert modal that does not match' do @@ -856,7 +855,7 @@ describe Capybara::Webkit::Driver do alert_message = driver.accept_modal(:alert) do driver.find_xpath("//input").first.click end - alert_message.should eq "Alert Text\nGoes Here" + expect(alert_message).to eq "Alert Text\nGoes Here" end it 'times out waiting for an async alert modal' do @@ -878,13 +877,13 @@ describe Capybara::Webkit::Driver do it "should let me read my alert messages" do visit("/") - driver.alert_messages.first.should eq "Alert Text\nGoes Here" + expect(driver.alert_messages.first).to eq "Alert Text\nGoes Here" end it "empties the array when reset" do visit("/") driver.reset! - driver.alert_messages.should be_empty + expect(driver.alert_messages).to be_empty end it "clears alerts from ajax requests in between sessions" do @@ -892,7 +891,7 @@ describe Capybara::Webkit::Driver do driver.find("//input").first.click driver.reset! sleep 0.5 - driver.alert_messages.should eq([]) + expect(driver.alert_messages).to eq([]) expect { visit("/") }.not_to raise_error end end @@ -941,14 +940,14 @@ describe Capybara::Webkit::Driver do driver.accept_modal(:confirm) do driver.find_xpath("//input").first.click end - driver.console_messages.first[:message].should eq "hello" + expect(driver.console_messages.first[:message]).to eq "hello" end it 'dismisses a confirm modal that does not match' do begin driver.accept_modal(:confirm, text: 'No?') do driver.find_xpath("//input").first.click - driver.console_messages.first[:message].should eq "goodbye" + expect(driver.console_messages.first[:message]).to eq "goodbye" end rescue Capybara::ModalNotFound end @@ -966,7 +965,7 @@ describe Capybara::Webkit::Driver do driver.dismiss_modal(:confirm) do driver.find_xpath("//input").first.click end - driver.console_messages.first[:message].should eq "goodbye" + expect(driver.console_messages.first[:message]).to eq "goodbye" end it 'raises an error when dismissing a confirm modal that does not match' do @@ -982,7 +981,7 @@ describe Capybara::Webkit::Driver do confirm_message = driver.accept_modal(:confirm) do driver.find_css("input[name=test_async]").first.click end - confirm_message.should eq "Yes?" + expect(confirm_message).to eq "Yes?" end it 'allows the nesting of dismiss and accept' do @@ -991,7 +990,7 @@ describe Capybara::Webkit::Driver do driver.find_css("input[name=test_complex]").first.click end end - driver.console_messages.first[:message].should eq "goodbye" + expect(driver.console_messages.first[:message]).to eq "goodbye" end it 'raises an error when an unexpected modal is displayed' do @@ -1006,7 +1005,7 @@ describe Capybara::Webkit::Driver do begin driver.accept_modal(:prompt) do driver.find_xpath("//input").first.click - driver.console_messages.first[:message].should eq "goodbye" + expect(driver.console_messages.first[:message]).to eq "goodbye" end rescue Capybara::ModalNotFound end @@ -1014,31 +1013,31 @@ describe Capybara::Webkit::Driver do it "should default to accept the confirm" do driver.find_xpath("//input").first.click - driver.console_messages.first[:message].should eq "hello" + expect(driver.console_messages.first[:message]).to eq "hello" end it "can dismiss the confirm" do driver.dismiss_js_confirms! driver.find_xpath("//input").first.click - driver.console_messages.first[:message].should eq "goodbye" + expect(driver.console_messages.first[:message]).to eq "goodbye" end it "can accept the confirm explicitly" do driver.dismiss_js_confirms! driver.accept_js_confirms! driver.find_xpath("//input").first.click - driver.console_messages.first[:message].should eq "hello" + expect(driver.console_messages.first[:message]).to eq "hello" end it "should collect the javascript confirm dialog contents" do driver.find_xpath("//input").first.click - driver.confirm_messages.first.should eq "Yes?" + expect(driver.confirm_messages.first).to eq "Yes?" end it "empties the array when reset" do driver.find_xpath("//input").first.click driver.reset! - driver.confirm_messages.should be_empty + expect(driver.confirm_messages).to be_empty end it "resets to the default of accepting confirms" do @@ -1046,12 +1045,12 @@ describe Capybara::Webkit::Driver do driver.reset! visit("/") driver.find_xpath("//input").first.click - driver.console_messages.first[:message].should eq "hello" + expect(driver.console_messages.first[:message]).to eq "hello" end it "supports multi-line confirmation messages" do driver.execute_script("confirm('Hello\\nnewline')") - driver.confirm_messages.first.should eq "Hello\nnewline" + expect(driver.confirm_messages.first).to eq "Hello\nnewline" end end @@ -1099,14 +1098,14 @@ describe Capybara::Webkit::Driver do driver.accept_modal(:prompt) do driver.find_xpath("//input").first.click end - driver.console_messages.first[:message].should eq "hello John Smith" + expect(driver.console_messages.first[:message]).to eq "hello John Smith" end it 'accepts any prompt modal with the provided response' do driver.accept_modal(:prompt, with: 'Capy') do driver.find_xpath("//input").first.click end - driver.console_messages.first[:message].should eq "hello Capy" + expect(driver.console_messages.first[:message]).to eq "hello Capy" end it 'raises an error when accepting a prompt modal that does not match' do @@ -1121,14 +1120,14 @@ describe Capybara::Webkit::Driver do driver.dismiss_modal(:prompt) do driver.find_xpath("//input").first.click end - driver.console_messages.first[:message].should eq "goodbye" + expect(driver.console_messages.first[:message]).to eq "goodbye" end it 'dismisses a prompt modal that does not match' do begin driver.accept_modal(:prompt, text: 'Your age?') do driver.find_xpath("//input").first.click - driver.console_messages.first[:message].should eq "goodbye" + expect(driver.console_messages.first[:message]).to eq "goodbye" end rescue Capybara::ModalNotFound end @@ -1147,7 +1146,7 @@ describe Capybara::Webkit::Driver do prompt_message = driver.accept_modal(:prompt) do driver.find_css("input[name=test_async]").first.click end - prompt_message.should eq "Your name?" + expect(prompt_message).to eq "Your name?" end it 'allows the nesting of dismiss and accept' do @@ -1156,7 +1155,7 @@ describe Capybara::Webkit::Driver do driver.find_css("input[name=test_complex]").first.click end end - driver.console_messages.first[:message].should eq "goodbye" + expect(driver.console_messages.first[:message]).to eq "goodbye" end it 'raises an error when an unexpected modal is displayed' do @@ -1171,7 +1170,7 @@ describe Capybara::Webkit::Driver do begin driver.accept_modal(:confirm) do driver.find_xpath("//input").first.click - driver.console_messages.first[:message].should eq "goodbye" + expect(driver.console_messages.first[:message]).to eq "goodbye" end rescue Capybara::ModalNotFound end @@ -1179,48 +1178,48 @@ describe Capybara::Webkit::Driver do it "should default to dismiss the prompt" do driver.find_xpath("//input").first.click - driver.console_messages.first[:message].should eq "goodbye" + expect(driver.console_messages.first[:message]).to eq "goodbye" end it "can accept the prompt without providing text" do driver.accept_js_prompts! driver.find_xpath("//input").first.click - driver.console_messages.first[:message].should eq "hello John Smith" + expect(driver.console_messages.first[:message]).to eq "hello John Smith" end it "can accept the prompt with input" do driver.js_prompt_input = "Capy" driver.accept_js_prompts! driver.find_xpath("//input").first.click - driver.console_messages.first[:message].should eq "hello Capy" + expect(driver.console_messages.first[:message]).to eq "hello Capy" end it "can return to dismiss the prompt after accepting prompts" do driver.accept_js_prompts! driver.dismiss_js_prompts! driver.find_xpath("//input").first.click - driver.console_messages.first[:message].should eq "goodbye" + expect(driver.console_messages.first[:message]).to eq "goodbye" end it "should let me remove the prompt input text" do driver.js_prompt_input = "Capy" driver.accept_js_prompts! driver.find_xpath("//input").first.click - driver.console_messages.first[:message].should eq "hello Capy" + expect(driver.console_messages.first[:message]).to eq "hello Capy" driver.js_prompt_input = nil driver.find_xpath("//input").first.click - driver.console_messages.last[:message].should eq "hello John Smith" + expect(driver.console_messages.last[:message]).to eq "hello John Smith" end it "should collect the javascript prompt dialog contents" do driver.find_xpath("//input").first.click - driver.prompt_messages.first.should eq "Your name?" + expect(driver.prompt_messages.first).to eq "Your name?" end it "empties the array when reset" do driver.find_xpath("//input").first.click driver.reset! - driver.prompt_messages.should be_empty + expect(driver.prompt_messages).to be_empty end it "returns the prompt action to dismiss on reset" do @@ -1228,12 +1227,12 @@ describe Capybara::Webkit::Driver do driver.reset! visit("/") driver.find_xpath("//input").first.click - driver.console_messages.first[:message].should eq "goodbye" + expect(driver.console_messages.first[:message]).to eq "goodbye" end it "supports multi-line prompt messages" do driver.execute_script("prompt('Hello\\nnewline')") - driver.prompt_messages.first.should eq "Hello\nnewline" + expect(driver.prompt_messages.first).to eq "Hello\nnewline" end end @@ -1281,66 +1280,66 @@ describe Capybara::Webkit::Driver do before { visit("/") } it "returns a textarea's value" do - driver.find_xpath("//textarea").first.value.should eq "what a wonderful area for text" + expect(driver.find_xpath("//textarea").first.value).to eq "what a wonderful area for text" end it "returns a text input's value" do - driver.find_xpath("//input").first.value.should eq "bar" + expect(driver.find_xpath("//input").first.value).to eq "bar" end it "returns a select's value" do - driver.find_xpath("//select").first.value.should eq "Capybara" + expect(driver.find_xpath("//select").first.value).to eq "Capybara" end it "sets an input's value" do input = driver.find_xpath("//input").first input.set("newvalue") - input.value.should eq "newvalue" + expect(input.value).to eq "newvalue" end it "sets an input's value greater than the max length" do input = driver.find_xpath("//input[@name='maxlength_foo']").first input.set("allegories (poems)") - input.value.should eq "allegories" + expect(input.value).to eq "allegories" end it "sets an input's value equal to the max length" do input = driver.find_xpath("//input[@name='maxlength_foo']").first input.set("allegories") - input.value.should eq "allegories" + expect(input.value).to eq "allegories" end it "sets an input's value less than the max length" do input = driver.find_xpath("//input[@name='maxlength_foo']").first input.set("poems") - input.value.should eq "poems" + expect(input.value).to eq "poems" end it "sets an input's nil value" do input = driver.find_xpath("//input").first input.set(nil) - input.value.should eq "" + expect(input.value).to eq "" end it "sets a select's value" do select = driver.find_xpath("//select").first select.set("Monkey") - select.value.should eq "Monkey" + expect(select.value).to eq "Monkey" end it "sets a textarea's value" do textarea = driver.find_xpath("//textarea").first textarea.set("newvalue") - textarea.value.should eq "newvalue" + expect(textarea.value).to eq "newvalue" end context "#send_keys" do it "should support :backspace" do input = driver.find_xpath("//input").first input.set("dog") - input.value.should eq "dog" + expect(input.value).to eq "dog" input.send_keys(*[:backspace]) - input.value.should eq "do" + expect(input.value).to eq "do" end end @@ -1357,52 +1356,52 @@ describe Capybara::Webkit::Driver do context "a select element's selection has been changed" do before do - animal_select.value.should eq "Capybara" + expect(animal_select.value).to eq "Capybara" monkey_option.select_option end it "returns the new selection" do - animal_select.value.should eq "Monkey" + expect(animal_select.value).to eq "Monkey" end it "does not modify the selected attribute of a new selection" do - monkey_option['selected'].should be_nil + expect(monkey_option['selected']).to be_nil end it "returns the old value when a reset button is clicked" do reset_button.click - animal_select.value.should eq "Capybara" + expect(animal_select.value).to eq "Capybara" end end context "a multi-select element's option has been unselected" do before do - toppings_select.value.should include("Apple", "Banana", "Cherry") + expect(toppings_select.value).to include("Apple", "Banana", "Cherry") apple_option.unselect_option end it "does not return the deselected option" do - toppings_select.value.should_not include("Apple") + expect(toppings_select.value).not_to include("Apple") end it "returns the deselected option when a reset button is clicked" do reset_button.click - toppings_select.value.should include("Apple", "Banana", "Cherry") + expect(toppings_select.value).to include("Apple", "Banana", "Cherry") end end context "a multi-select (with empty multiple attribute) element's option has been unselected" do before do - guitars_select.value.should include("Fender", "Gibson") + expect(guitars_select.value).to include("Fender", "Gibson") fender_option.unselect_option end it "does not return the deselected option" do - guitars_select.value.should_not include("Fender") + expect(guitars_select.value).not_to include("Fender") end end @@ -1411,73 +1410,73 @@ describe Capybara::Webkit::Driver do banana_option.unselect_option cherry_option.unselect_option - toppings_select.value.should eq [] + expect(toppings_select.value).to eq [] apple_option.select_option banana_option.select_option cherry_option.select_option - toppings_select.value.should include("Apple", "Banana", "Cherry") + expect(toppings_select.value).to include("Apple", "Banana", "Cherry") end let(:checked_box) { driver.find_xpath("//input[@name='checkedbox']").first } let(:unchecked_box) { driver.find_xpath("//input[@name='uncheckedbox']").first } it "knows a checked box is checked" do - checked_box['checked'].should be_true + expect(checked_box['checked']).to be true end it "knows a checked box is checked using checked?" do - checked_box.should be_checked + expect(checked_box).to be_checked end it "knows an unchecked box is unchecked" do - unchecked_box['checked'].should_not be_true + expect(unchecked_box['checked']).not_to be_truthy end it "knows an unchecked box is unchecked using checked?" do - unchecked_box.should_not be_checked + expect(unchecked_box).not_to be_checked end it "checks an unchecked box" do unchecked_box.set(true) - unchecked_box.should be_checked + expect(unchecked_box).to be_checked end it "unchecks a checked box" do checked_box.set(false) - checked_box.should_not be_checked + expect(checked_box).not_to be_checked end it "leaves a checked box checked" do checked_box.set(true) - checked_box.should be_checked + expect(checked_box).to be_checked end it "leaves an unchecked box unchecked" do unchecked_box.set(false) - unchecked_box.should_not be_checked + expect(unchecked_box).not_to be_checked end let(:enabled_input) { driver.find_xpath("//input[@name='foo']").first } let(:disabled_input) { driver.find_xpath("//input[@id='disabled_input']").first } it "knows a disabled input is disabled" do - disabled_input['disabled'].should be_true + expect(disabled_input['disabled']).to be true end it "knows a not disabled input is not disabled" do - enabled_input['disabled'].should_not be_true + expect(enabled_input['disabled']).not_to be_truthy end it "does not modify a readonly input" do readonly_input = driver.find_css("#readonly_input").first readonly_input.set('enabled') - readonly_input.value.should eq 'readonly' + expect(readonly_input.value).to eq 'readonly' end it "should see enabled options in disabled select as disabled" do - driver.find_css("#select-option-disabled").first.should be_disabled + expect(driver.find_css("#select-option-disabled").first).to be_disabled end end @@ -1516,18 +1515,18 @@ describe Capybara::Webkit::Driver do it "triggers mouse events" do watch.click - fired_events.should eq %w(mousedown mouseup click) + expect(fired_events).to eq %w(mousedown mouseup click) end it "triggers double click" do # check event order at http://www.quirksmode.org/dom/events/click.html watch.double_click - fired_events.should eq %w(mousedown mouseup click mousedown mouseup click dblclick) + expect(fired_events).to eq %w(mousedown mouseup click mousedown mouseup click dblclick) end it "triggers right click" do watch.right_click - fired_events.should eq %w(mousedown contextmenu mouseup) + expect(fired_events).to eq %w(mousedown contextmenu mouseup) end end @@ -1591,29 +1590,29 @@ describe Capybara::Webkit::Driver do it "triggers text input events on inputs of type #{field_type}" do driver.find_xpath("//input[@type='#{field_type}']").first.set(newtext) driver.find_xpath("//body").first.click - driver.find_xpath("//li").map(&:visible_text).should eq textevents + expect(driver.find_xpath("//li").map(&:visible_text)).to eq textevents end end it "triggers events for cleared inputs" do driver.find_xpath("//input[@type='text']").first.set('') driver.find_xpath("//body").first.click - driver.find_xpath("//li").map(&:visible_text).should include('change') + expect(driver.find_xpath("//li").map(&:visible_text)).to include('change') end it "triggers textarea input events" do driver.find_xpath("//textarea").first.set(newtext) - driver.find_xpath("//li").map(&:visible_text).should eq keyevents + expect(driver.find_xpath("//li").map(&:visible_text)).to eq keyevents end it "triggers radio input events" do driver.find_xpath("//input[@type='radio']").first.set(true) - driver.find_xpath("//li").map(&:visible_text).should eq %w(mousedown focus mouseup change click) + expect(driver.find_xpath("//li").map(&:visible_text)).to eq %w(mousedown focus mouseup change click) end it "triggers checkbox events" do driver.find_xpath("//input[@type='checkbox']").first.set(true) - driver.find_xpath("//li").map(&:visible_text).should eq %w(mousedown focus mouseup change click) + expect(driver.find_xpath("//li").map(&:visible_text)).to eq %w(mousedown focus mouseup change click) end end @@ -1674,16 +1673,16 @@ describe Capybara::Webkit::Driver do before { visit("/") } it "hovers an element" do - driver.find_css("#hover").first.visible_text.should_not =~ /Text that only shows on hover/ + expect(driver.find_css("#hover").first.visible_text).not_to match /Text that only shows on hover/ driver.find_css("#hover span").first.hover - driver.find_css("#hover").first.visible_text.should =~ /Text that only shows on hover/ + expect(driver.find_css("#hover").first.visible_text).to match /Text that only shows on hover/ end it "hovers an svg element" do # visible_text does not work for SVG elements. It returns all the text. - driver.find_css("text").first.should_not be_visible + expect(driver.find_css("text").first).not_to be_visible driver.find_css("#circle_hover").first.hover - driver.find_css("text").first.should be_visible + expect(driver.find_css("text").first).to be_visible end it "hovers an element off the screen" do @@ -1693,33 +1692,33 @@ describe Capybara::Webkit::Driver do element.style.position = 'absolute'; element.style.left = '200px'; JS - driver.find_css("#hover").first.visible_text.should_not =~ /Text that only shows on hover/ + expect(driver.find_css("#hover").first.visible_text).not_to match /Text that only shows on hover/ driver.find_css("#hover span").first.hover - driver.find_css("#hover").first.visible_text.should =~ /Text that only shows on hover/ + expect(driver.find_css("#hover").first.visible_text).to match /Text that only shows on hover/ end it "clicks an element" do driver.find_xpath("//a").first.click - driver.current_url =~ %r{/next$} + expect(driver.current_url).to match %r{/next$} end it "fires a mouse event" do driver.find_xpath("//*[@id='mouseup']").first.trigger("mouseup") - driver.find_xpath("//*[@class='triggered']").should_not be_empty + expect(driver.find_xpath("//*[@class='triggered']")).not_to be_empty end it "fires a non-mouse event" do driver.find_xpath("//*[@id='change']").first.trigger("change") - driver.find_xpath("//*[@class='triggered']").should_not be_empty + expect(driver.find_xpath("//*[@class='triggered']")).not_to be_empty end it "fires a change on select" do select = driver.find_xpath("//select").first - select.value.should eq "1" + expect(select.value).to eq "1" option = driver.find_xpath("//option[@id='option-2']").first option.select_option - select.value.should eq "2" - driver.find_xpath("//select[@class='triggered']").should_not be_empty + expect(select.value).to eq "2" + expect(driver.find_xpath("//select[@class='triggered']")).not_to be_empty end it "fires drag events" do @@ -1728,7 +1727,7 @@ describe Capybara::Webkit::Driver do draggable.drag_to(container) - driver.find_xpath("//*[@class='triggered']").size.should eq 1 + expect(driver.find_xpath("//*[@class='triggered']").size).to eq 1 end end @@ -1748,12 +1747,12 @@ describe Capybara::Webkit::Driver do it "evaluates nested xpath expressions" do parent = driver.find_xpath("//*[@id='parent']").first - parent.find_xpath("./*[@class='find']").map(&:visible_text).should eq %w(Expected) + expect(parent.find_xpath("./*[@class='find']").map(&:visible_text)).to eq %w(Expected) end it "finds elements by CSS" do parent = driver.find_css("#parent").first - parent.find_css(".find").first.visible_text.should eq "Expected" + expect(parent.find_css(".find").first.visible_text).to eq "Expected" end end @@ -1773,7 +1772,7 @@ describe Capybara::Webkit::Driver do end visit("/", driver) driver.find_xpath("//a").first.click - result.should eq "finished" + expect(result).to eq "finished" end end @@ -1801,8 +1800,7 @@ describe Capybara::Webkit::Driver do driver.find_xpath("//input").first.click wait_for_error_to_complete driver.find_xpath("//body") - }. - to raise_error(Capybara::Webkit::InvalidResponseError, %r{/error}) + }.to raise_error(Capybara::Webkit::InvalidResponseError, %r{/error}) end def wait_for_error_to_complete @@ -1835,7 +1833,7 @@ describe Capybara::Webkit::Driver do driver.find_xpath("//input").first.click expect { driver.find_xpath("//p") }.to raise_error(Capybara::Webkit::InvalidResponseError) visit("/") - driver.find_xpath("//p").first.visible_text.should eq "hello" + expect(driver.find_xpath("//p").first.visible_text).to eq "hello" end end @@ -1861,7 +1859,7 @@ describe Capybara::Webkit::Driver do before { visit("/") } it "doesn't crash from alerts" do - driver.find_xpath("//p").first.visible_text.should eq "success" + expect(driver.find_xpath("//p").first.visible_text).to eq "success" end end @@ -1891,31 +1889,31 @@ describe Capybara::Webkit::Driver do end it "can set user_agent" do - driver.find_xpath('id("user-agent")').first.visible_text.should eq 'capybara-webkit/custom-user-agent' - driver.evaluate_script('navigator.userAgent').should eq 'capybara-webkit/custom-user-agent' + expect(driver.find_xpath('id("user-agent")').first.visible_text).to eq 'capybara-webkit/custom-user-agent' + expect(driver.evaluate_script('navigator.userAgent')).to eq 'capybara-webkit/custom-user-agent' end it "keep user_agent in next page" do driver.find_xpath("//a").first.click - driver.find_xpath('id("user-agent")').first.visible_text.should eq 'capybara-webkit/custom-user-agent' - driver.evaluate_script('navigator.userAgent').should eq 'capybara-webkit/custom-user-agent' + expect(driver.find_xpath('id("user-agent")').first.visible_text).to eq 'capybara-webkit/custom-user-agent' + expect(driver.evaluate_script('navigator.userAgent')).to eq 'capybara-webkit/custom-user-agent' end it "can set custom header" do - driver.find_xpath('id("x-capybara-webkit-header")').first.visible_text.should eq 'x-capybara-webkit-header' + expect(driver.find_xpath('id("x-capybara-webkit-header")').first.visible_text).to eq 'x-capybara-webkit-header' end it "can set Accept header" do - driver.find_xpath('id("accept")').first.visible_text.should eq 'text/html' + expect(driver.find_xpath('id("accept")').first.visible_text).to eq 'text/html' end it "can reset all custom header" do driver.reset! visit('/') - driver.find_xpath('id("user-agent")').first.visible_text.should_not eq 'capybara-webkit/custom-user-agent' - driver.evaluate_script('navigator.userAgent').should_not eq 'capybara-webkit/custom-user-agent' - driver.find_xpath('id("x-capybara-webkit-header")').first.visible_text.should be_empty - driver.find_xpath('id("accept")').first.visible_text.should_not eq 'text/html' + expect(driver.find_xpath('id("user-agent")').first.visible_text).not_to eq 'capybara-webkit/custom-user-agent' + expect(driver.evaluate_script('navigator.userAgent')).not_to eq 'capybara-webkit/custom-user-agent' + expect(driver.find_xpath('id("x-capybara-webkit-header")').first.visible_text).to be_empty + expect(driver.find_xpath('id("accept")').first.visible_text).not_to eq 'text/html' end end @@ -1935,21 +1933,18 @@ describe Capybara::Webkit::Driver do make_the_server_go_away expect { driver.find_xpath("//body") - }. - to raise_error(Capybara::Webkit::NoResponseError, %r{response}) + }.to raise_error(Capybara::Webkit::NoResponseError, %r{response}) make_the_server_come_back end def make_the_server_come_back - connection.unstub(:gets) - connection.unstub(:puts) - connection.unstub(:print) + [:gets, :puts, :print].each { |msg| allow(connection).to receive(msg).and_call_original } end def make_the_server_go_away - connection.stub(:gets).and_return(nil) - connection.stub(:puts) - connection.stub(:print) + allow(connection).to receive(:gets).and_return(nil) + allow(connection).to receive(:puts).and_return(nil) + allow(connection).to receive(:print).and_return(nil) end end @@ -1981,15 +1976,15 @@ describe Capybara::Webkit::Driver do end it "ignores custom fonts" do - font_family.should eq "Arial" + expect(font_family).to eq "Arial" end it "ignores custom fonts before an element" do - font_family.should eq "Arial" + expect(font_family).to eq "Arial" end it "ignores custom fonts after an element" do - font_family.should eq "Arial" + expect(font_family).to eq "Arial" end end @@ -2014,27 +2009,27 @@ describe Capybara::Webkit::Driver do end it "remembers the cookie on second visit" do - echoed_cookie.should eq "" + expect(echoed_cookie).to eq "" visit "/" - echoed_cookie.should eq "abc" + expect(echoed_cookie).to eq "abc" end it "uses a custom cookie" do driver.set_cookie 'cookie=abc; domain=127.0.0.1; path=/' visit "/" - echoed_cookie.should eq "abc" + expect(echoed_cookie).to eq "abc" end it "clears cookies" do driver.clear_cookies visit "/" - echoed_cookie.should eq "" + expect(echoed_cookie).to eq "" end it "allows reading cookies" do - driver.cookies["cookie"].should eq "abc" - driver.cookies.find("cookie").path.should eq "/" - driver.cookies.find("cookie").domain.should include "127.0.0.1" + expect(driver.cookies["cookie"]).to eq "abc" + expect(driver.cookies.find("cookie").path).to eq "/" + expect(driver.cookies.find("cookie").domain).to include "127.0.0.1" end end @@ -2063,7 +2058,7 @@ describe Capybara::Webkit::Driver do it "allows removed nodes when reloading is disabled" do node = driver.find_xpath("//p[@id='removeMe']").first driver.evaluate_script("document.getElementById('parent').innerHTML = 'Magic'") - node.visible_text.should eq 'Hello' + expect(node.visible_text).to eq 'Hello' end end @@ -2124,8 +2119,8 @@ describe Capybara::Webkit::Driver do cases.each do |xpath, path| nodes = driver.find_xpath(xpath) - nodes.size.should eq 1 - nodes[0].path.should eq path + expect(nodes.size).to eq 1 + expect(nodes[0].path).to eq path end end end @@ -2149,7 +2144,7 @@ describe Capybara::Webkit::Driver do before { visit("/") } it "handles overflow hidden" do - driver.find_xpath("//div[@id='overflow']").first.visible_text.should eq "Overflow" + expect(driver.find_xpath("//div[@id='overflow']").first.visible_text).to eq "Overflow" end end @@ -2175,7 +2170,7 @@ describe Capybara::Webkit::Driver do it "loads a page without error" do 10.times do visit("/redirect") - driver.find_xpath("//p").first.visible_text.should eq "finished" + expect(driver.find_xpath("//p").first.visible_text).to eq "finished" end end end @@ -2204,17 +2199,17 @@ describe Capybara::Webkit::Driver do before { visit("/") } it "displays the message on subsequent page loads" do - driver.find_xpath("//span[contains(.,'localStorage is enabled')]").should be_empty + expect(driver.find_xpath("//span[contains(.,'localStorage is enabled')]")).to be_empty visit "/" - driver.find_xpath("//span[contains(.,'localStorage is enabled')]").should_not be_empty + expect(driver.find_xpath("//span[contains(.,'localStorage is enabled')]")).not_to be_empty end it "clears the message after a driver reset!" do visit "/" - driver.find_xpath("//span[contains(.,'localStorage is enabled')]").should_not be_empty + expect(driver.find_xpath("//span[contains(.,'localStorage is enabled')]")).not_to be_empty driver.reset! visit "/" - driver.find_xpath("//span[contains(.,'localStorage is enabled')]").should be_empty + expect(driver.find_xpath("//span[contains(.,'localStorage is enabled')]")).to be_empty end end @@ -2297,20 +2292,20 @@ CACHE MANIFEST before { visit("/f8742c39-8bef-4196-b1c3-80f8a3d65f3e") } it "has proper state available" do - driver.find_xpath("//*[@id='state']").first.visible_text.should == '0' + expect(driver.find_xpath("//*[@id='state']").first.visible_text).to eq '0' sleep 1 - @visited.should eq(['complex', 'manifest', 'simple']), 'files were not downloaded in expected order' - driver.find_xpath("//*[@id='finished']").first.visible_text.should == 'cached' + expect(@visited).to eq(['complex', 'manifest', 'simple']), 'files were not downloaded in expected order' + expect(driver.find_xpath("//*[@id='finished']").first.visible_text).to eq 'cached' end it "is cleared on driver reset!" do sleep 1 - @visited.should eq(['complex', 'manifest', 'simple']), 'files were not downloaded in expected order' + expect(@visited).to eq(['complex', 'manifest', 'simple']), 'files were not downloaded in expected order' driver.reset! @visited.clear visit '/4aaffa31-f42d-403e-a19e-6b248d608087' sleep 1 - @visited.should eq(['simple', 'manifest', 'simple']), 'simple action was used from cache instead of server' + expect(@visited).to eq(['simple', 'manifest', 'simple']), 'simple action was used from cache instead of server' end end @@ -2341,7 +2336,7 @@ CACHE MANIFEST it "submits a form without clicking" do driver.find_xpath("//form")[0].submit - driver.html.should include "Congrats" + expect(driver.html).to include "Congrats" end end @@ -2396,59 +2391,59 @@ CACHE MANIFEST before { visit("/") } it "returns the charCode for the keypressed" do - charCode_for("a").should eq "97" - charCode_for("A").should eq "65" - charCode_for("\r").should eq "13" - charCode_for(",").should eq "44" - charCode_for("<").should eq "60" - charCode_for("0").should eq "48" + expect(charCode_for("a")).to eq "97" + expect(charCode_for("A")).to eq "65" + expect(charCode_for("\r")).to eq "13" + expect(charCode_for(",")).to eq "44" + expect(charCode_for("<")).to eq "60" + expect(charCode_for("0")).to eq "48" end it "returns the keyCode for the keypressed" do - keyCode_for("a").should eq "97" - keyCode_for("A").should eq "65" - keyCode_for("\r").should eq "13" - keyCode_for(",").should eq "44" - keyCode_for("<").should eq "60" - keyCode_for("0").should eq "48" + expect(keyCode_for("a")).to eq "97" + expect(keyCode_for("A")).to eq "65" + expect(keyCode_for("\r")).to eq "13" + expect(keyCode_for(",")).to eq "44" + expect(keyCode_for("<")).to eq "60" + expect(keyCode_for("0")).to eq "48" end it "returns the which for the keypressed" do - which_for("a").should eq "97" - which_for("A").should eq "65" - which_for("\r").should eq "13" - which_for(",").should eq "44" - which_for("<").should eq "60" - which_for("0").should eq "48" + expect(which_for("a")).to eq "97" + expect(which_for("A")).to eq "65" + expect(which_for("\r")).to eq "13" + expect(which_for(",")).to eq "44" + expect(which_for("<")).to eq "60" + expect(which_for("0")).to eq "48" end end shared_examples "a keyupdown app" do it "returns a 0 charCode for the event" do - charCode_for("a").should eq "0" - charCode_for("A").should eq "0" - charCode_for("\b").should eq "0" - charCode_for(",").should eq "0" - charCode_for("<").should eq "0" - charCode_for("0").should eq "0" + expect(charCode_for("a")).to eq "0" + expect(charCode_for("A")).to eq "0" + expect(charCode_for("\b")).to eq "0" + expect(charCode_for(",")).to eq "0" + expect(charCode_for("<")).to eq "0" + expect(charCode_for("0")).to eq "0" end it "returns the keyCode for the event" do - keyCode_for("a").should eq "65" - keyCode_for("A").should eq "65" - keyCode_for("\b").should eq "8" - keyCode_for(",").should eq "188" - keyCode_for("<").should eq "188" - keyCode_for("0").should eq "48" + expect(keyCode_for("a")).to eq "65" + expect(keyCode_for("A")).to eq "65" + expect(keyCode_for("\b")).to eq "8" + expect(keyCode_for(",")).to eq "188" + expect(keyCode_for("<")).to eq "188" + expect( keyCode_for("0")).to eq "48" end it "returns the which for the event" do - which_for("a").should eq "65" - which_for("A").should eq "65" - which_for("\b").should eq "8" - which_for(",").should eq "188" - which_for("<").should eq "188" - which_for("0").should eq "48" + expect(which_for("a")).to eq "65" + expect(which_for("A")).to eq "65" + expect(which_for("\b")).to eq "8" + expect(which_for(",")).to eq "188" + expect(which_for("<")).to eq "188" + expect(which_for("0")).to eq "48" end end @@ -2490,20 +2485,20 @@ CACHE MANIFEST it "has the expected text in the new window" do visit("/new_window") driver.within_window(driver.window_handles.last) do - driver.find_xpath("//p").first.visible_text.should eq "finished" + expect(driver.find_xpath("//p").first.visible_text).to eq "finished" end end it "can switch to another window" do visit("/new_window") driver.switch_to_window(driver.window_handles.last) - driver.find_xpath("//p").first.visible_text.should eq "finished" + expect(driver.find_xpath("//p").first.visible_text).to eq "finished" end it "knows the current window handle" do visit("/new_window") driver.within_window(driver.window_handles.last) do - driver.current_window_handle.should eq driver.window_handles.last + expect(driver.current_window_handle).to eq driver.window_handles.last end end @@ -2513,27 +2508,27 @@ CACHE MANIFEST driver.switch_to_window(driver.window_handles.last) driver.close_window(driver.current_window_handle) - driver.current_window_handle.should eq(original_handle) + expect(driver.current_window_handle).to eq(original_handle) end it "can close an unfocused window" do visit("/new_window") driver.close_window(driver.window_handles.last) - driver.window_handles.size.should eq(1) + expect(driver.window_handles.size).to eq(1) end it "can close the last window" do visit("/new_window") handles = driver.window_handles handles.each { |handle| driver.close_window(handle) } - driver.html.should be_empty - handles.should_not include(driver.current_window_handle) + expect(driver.html).to be_empty + expect(handles).not_to include(driver.current_window_handle) end it "waits for the new window to load" do visit("/new_window?sleep=1") driver.within_window(driver.window_handles.last) do - driver.find_xpath("//p").first.visible_text.should eq "finished" + expect(driver.find_xpath("//p").first.visible_text).to eq "finished" end end @@ -2541,60 +2536,59 @@ CACHE MANIFEST visit("/new_window?sleep=2") driver.execute_script("setTimeout(function() { window.location = 'about:blank' }, 1000)") driver.within_window(driver.window_handles.last) do - driver.find_xpath("//p").first.visible_text.should eq "finished" + expect(driver.find_xpath("//p").first.visible_text).to eq "finished" end end it "switches back to the original window" do visit("/new_window") driver.within_window(driver.window_handles.last) { } - driver.find_xpath("//p").first.visible_text.should eq "bananas" + expect(driver.find_xpath("//p").first.visible_text).to eq "bananas" end it "supports finding a window by name" do visit("/new_window") driver.within_window('myWindow') do - driver.find_xpath("//p").first.visible_text.should eq "finished" + expect(driver.find_xpath("//p").first.visible_text).to eq "finished" end end it "supports finding a window by title" do visit("/new_window?sleep=5") driver.within_window('My New Window') do - driver.find_xpath("//p").first.visible_text.should eq "finished" + expect(driver.find_xpath("//p").first.visible_text).to eq "finished" end end it "supports finding a window by url" do visit("/new_window?test") driver.within_window(driver_url(driver, "/?test")) do - driver.find_xpath("//p").first.visible_text.should eq "finished" + expect(driver.find_xpath("//p").first.visible_text).to eq "finished" end end it "raises an error if the window is not found" do - expect { driver.within_window('myWindowDoesNotExist') }. - to raise_error(Capybara::Webkit::NoSuchWindowError) + expect { driver.within_window('myWindowDoesNotExist') }.to raise_error(Capybara::Webkit::NoSuchWindowError) end it "has a number of window handles equal to the number of open windows" do - driver.window_handles.size.should eq 1 + expect(driver.window_handles.size).to eq 1 visit("/new_window") - driver.window_handles.size.should eq 2 + expect(driver.window_handles.size).to eq 2 end it "removes windows when closed via JavaScript" do visit("/new_window") driver.execute_script('console.log(window.document.title); window.close()') sleep 2 - driver.window_handles.size.should eq 1 + expect(driver.window_handles.size).to eq 1 end it "closes new windows on reset" do visit("/new_window") last_handle = driver.window_handles.last driver.reset! - driver.window_handles.should_not include(last_handle) + expect(driver.window_handles).not_to include(last_handle) end it "leaves the old window focused when opening a new window" do @@ -2602,15 +2596,15 @@ CACHE MANIFEST current_window = driver.current_window_handle driver.open_new_window - driver.current_window_handle.should eq current_window - driver.window_handles.size.should eq 3 + expect(driver.current_window_handle).to eq current_window + expect(driver.window_handles.size).to eq 3 end it "opens blank windows" do visit("/new_window") driver.open_new_window driver.switch_to_window(driver.window_handles.last) - driver.html.should be_empty + expect(driver.html).to be_empty end end @@ -2633,7 +2627,7 @@ CACHE MANIFEST end visit("/new_window", driver) - driver.cookies['session_id'].should eq session_id + expect(driver.cookies['session_id']).to eq session_id end context "timers app" do @@ -2708,27 +2702,27 @@ CACHE MANIFEST it "can authenticate a request" do driver.authenticate('user', 'password') visit("/") - driver.html.should include("Basic "+Base64.encode64("user:password").strip) + expect(driver.html).to include("Basic "+Base64.encode64("user:password").strip) end it "returns 401 for incorrectly authenticated request" do driver.authenticate('user1', 'password1') - lambda { visit("/") }.should_not raise_error - driver.status_code.should eq 401 + expect { visit("/") }.not_to raise_error + expect(driver.status_code).to eq 401 end it "returns 401 for unauthenticated request" do - lambda { visit("/") }.should_not raise_error - driver.status_code.should eq 401 + expect { visit("/") }.not_to raise_error + expect(driver.status_code).to eq 401 end it "can be reset with subsequent authenticate call", skip_on_qt4: true do driver.authenticate('user', 'password') visit("/") - driver.html.should include("Basic "+Base64.encode64("user:password").strip) + expect(driver.html).to include("Basic "+Base64.encode64("user:password").strip) driver.authenticate('user1', 'password1') - lambda { visit("/") }.should_not raise_error - driver.status_code.should eq 401 + expect{ visit("/") }.not_to raise_error + expect(driver.status_code).to eq 401 end end @@ -2779,40 +2773,40 @@ CACHE MANIFEST it "should not fetch urls blocked by host" do visit("/") driver.within_frame('frame1') do - driver.find_xpath("//body").first.visible_text.should be_empty + expect(driver.find_xpath("//body").first.visible_text).to be_empty end end it "should not fetch urls blocked by path" do visit('/') driver.within_frame('frame2') do - driver.find_xpath("//body").first.visible_text.should be_empty + expect(driver.find_xpath("//body").first.visible_text).to be_empty end end it "should not fetch blocked scripts" do visit("/") - driver.html.should_not include("Script Run") + expect(driver.html).not_to include("Script Run") end it "should fetch unblocked urls" do visit('/') driver.within_frame('frame3') do - driver.find_xpath("//p").first.visible_text.should eq "Inner" + expect(driver.find_xpath("//p").first.visible_text).to eq "Inner" end end it "should not fetch urls blocked by wildcard match" do visit('/') driver.within_frame('frame4') do - driver.find("//body").first.text.should be_empty + expect(driver.find("//body").first.text).to be_empty end end it "returns a status code for blocked urls" do visit("/") driver.within_frame('frame1') do - driver.status_code.should eq 200 + expect(driver.status_code).to eq 200 end end end @@ -2937,46 +2931,46 @@ CACHE MANIFEST it "should not raise a timeout error when zero" do configure { |config| config.timeout = 0 } - lambda { visit("/") }.should_not raise_error + expect{ visit("/") }.not_to raise_error end it "should raise a timeout error" do configure { |config| config.timeout = 1 } - lambda { visit("/") }.should raise_error(Timeout::Error, "Request timed out after 1 second(s)") + expect{ visit("/") }.to raise_error(Timeout::Error, "Request timed out after 1 second(s)") end it "should not raise an error when the timeout is high enough" do configure { |config| config.timeout = 10 } - lambda { visit("/") }.should_not raise_error + expect { visit("/") }.not_to raise_error end it "should set the timeout for each request" do configure { |config| config.timeout = 10 } - lambda { visit("/") }.should_not raise_error + expect{ visit("/") }.not_to raise_error driver.timeout = 1 - lambda { visit("/") }.should raise_error(Timeout::Error) + expect{ visit("/") }.to raise_error(Timeout::Error) end it "should set the timeout for each request" do configure { |config| config.timeout = 1 } - lambda { visit("/") }.should raise_error(Timeout::Error) + expect { visit("/") }.to raise_error(Timeout::Error) driver.reset! driver.timeout = 10 - lambda { visit("/") }.should_not raise_error + expect{ visit("/") }.not_to raise_error end it "should raise a timeout on a slow form" do configure { |config| config.timeout = 3 } visit("/") - driver.status_code.should eq 200 + expect(driver.status_code).to eq 200 driver.timeout = 1 driver.find_xpath("//input").first.click - lambda { driver.status_code }.should raise_error(Timeout::Error) + expect { driver.status_code }.to raise_error(Timeout::Error) end it "get timeout" do configure { |config| config.timeout = 10 } - driver.browser.timeout.should eq 10 + expect(driver.browser.timeout).to eq 10 end end @@ -2989,13 +2983,13 @@ CACHE MANIFEST it "logs nothing in normal mode" do configure { |config| config.debug = false } visit("/") - stderr.should_not include logging_message + expect(stderr).not_to include logging_message end it "logs its commands in debug mode" do configure { |config| config.debug = true } visit("/") - stderr.should include logging_message + expect(stderr).to include logging_message end let(:logging_message) { 'Wrote response true' } @@ -3036,7 +3030,7 @@ CACHE MANIFEST it 'should not hang the server' do visit('/') driver.find_xpath('//input').first.click - driver.console_messages.first[:message].should eq "hello" + expect(driver.console_messages.first[:message]).to eq "hello" end end @@ -3055,7 +3049,7 @@ CACHE MANIFEST it 'returns an xpath for the current node' do visit('/') path = driver.find_xpath('//span').first.path - driver.find_xpath(path).first.text.should eq 'hello' + expect(driver.find_xpath(path).first.text).to eq 'hello' end end @@ -3106,11 +3100,11 @@ CACHE MANIFEST it "includes Capybara, capybara-webkit, Qt, and WebKit versions" do result = driver.version - result.should include("Capybara: #{Capybara::VERSION}") - result.should include("capybara-webkit: #{Capybara::Driver::Webkit::VERSION}") - result.should =~ /Qt: \d+\.\d+\.\d+/ - result.should =~ /WebKit: \d+\.\d+/ - result.should =~ /QtWebKit: \d+\.\d+/ + expect(result).to include("Capybara: #{Capybara::VERSION}") + expect(result).to include("capybara-webkit: #{Capybara::Driver::Webkit::VERSION}") + expect(result).to match /Qt: \d+\.\d+\.\d+/ + expect(result).to match /WebKit: \d+\.\d+/ + expect(result).to match /QtWebKit: \d+\.\d+/ end end @@ -3132,13 +3126,13 @@ CACHE MANIFEST it "can navigate in history" do visit("/first") - driver.find_xpath("//p").first.text.should eq('first') + expect(driver.find_xpath("//p").first.text).to eq('first') driver.find_xpath("//a").first.click - driver.find_xpath("//p").first.text.should eq('navigated') + expect(driver.find_xpath("//p").first.text).to eq('navigated') driver.go_back - driver.find_xpath("//p").first.text.should eq('first') + expect(driver.find_xpath("//p").first.text).to eq('first') driver.go_forward - driver.find_xpath("//p").first.text.should eq('navigated') + expect(driver.find_xpath("//p").first.text).to eq('navigated') end end @@ -3197,8 +3191,8 @@ CACHE MANIFEST visit "/" sleep 0.5 driver.reset! - stderr.should abort_request_to("/async?2") - stderr.should_not abort_request_to("/async?1") + expect(stderr).to abort_request_to("/async?2") + expect(stderr).not_to abort_request_to("/async?1") end def abort_request_to(path) @@ -3264,13 +3258,13 @@ CACHE MANIFEST context "with default settings" do it "doesn't accept a self-signed certificate" do - lambda { driver.visit "https://#{@host}:#{@port}/" }.should raise_error + expect { driver.visit "https://#{@host}:#{@port}/" }.to raise_error(Capybara::Webkit::InvalidResponseError) end it "doesn't accept a self-signed certificate in a new window" do driver.execute_script("window.open('about:blank')") driver.switch_to_window(driver.window_handles.last) - lambda { driver.visit "https://#{@host}:#{@port}/" }.should raise_error + expect { driver.visit "https://#{@host}:#{@port}/" }.to raise_error(Capybara::Webkit::InvalidResponseError) end end @@ -3331,13 +3325,13 @@ CACHE MANIFEST it "should load images by default" do visit("/") - requests.should match_array %w(image bgimage) + expect(requests).to match_array %w(image bgimage) end it "should not load images when disabled" do configure(&:skip_image_loading) visit("/") - requests.should eq [] + expect(requests).to eq [] end let(:requests) do @@ -3394,7 +3388,7 @@ CACHE MANIFEST fork_connection driver.visit @url - @proxy_requests.size.should eq 2 + expect(@proxy_requests.size).to eq 2 @request = @proxy_requests[-1] end @@ -3408,39 +3402,38 @@ CACHE MANIFEST end it "uses the HTTP proxy correctly" do - @request[0].should match(/^GET\s+http:\/\/example.org\/\s+HTTP/i) - @request.find { |header| - header =~ /^Host:\s+example.org$/i }.should_not be nil + expect(@request[0]).to match(/^GET\s+http:\/\/example.org\/\s+HTTP/i) + expect(@request.find { |header| header =~ /^Host:\s+example.org$/i }).not_to be nil end it "sends correct proxy authentication" do auth_header = @request.find { |header| header =~ /^Proxy-Authorization:\s+/i } - auth_header.should_not be nil + expect(auth_header).not_to be nil user, pass = Base64.decode64(auth_header.split(/\s+/)[-1]).split(":") - user.should eq @user - pass.should eq @pass + expect(user).to eq @user + expect(pass).to eq @pass end it "uses the proxy's response" do - driver.html.should include "D'oh!" + expect(driver.html).to include "D'oh!" end it "uses original URL" do - driver.current_url.should eq @url + expect(driver.current_url).to eq @url end it "uses URLs changed by javascript" do driver.execute_script %{window.history.pushState("", "", "/blah")} - driver.current_url.should eq "http://example.org/blah" + expect(driver.current_url).to eq "http://example.org/blah" end it "is possible to disable proxy again" do @proxy_requests.clear driver.browser.clear_proxy driver.visit "http://#{@host}:#{@port}/" - @proxy_requests.size.should eq 0 + expect(@proxy_requests.size).to eq 0 end end diff --git a/spec/errors_spec.rb b/spec/errors_spec.rb index c090e09..f21984f 100644 --- a/spec/errors_spec.rb +++ b/spec/errors_spec.rb @@ -7,5 +7,5 @@ describe Capybara::Webkit::JsonError do it { should be_an_instance_of Capybara::Webkit::ClickFailed } - its(:message) { should == 'Error clicking this element' } + it { expect(subject.message).to eq 'Error clicking this element' } end diff --git a/spec/integration/session_spec.rb b/spec/integration/session_spec.rb index 7d0f849..5014970 100644 --- a/spec/integration/session_spec.rb +++ b/spec/integration/session_spec.rb @@ -50,7 +50,7 @@ describe Capybara::Session do it "waits for a request to load" do subject.visit("/") subject.find_button("Submit").click - subject.should have_content("Goodbye"); + expect(subject).to have_content("Goodbye"); end end @@ -76,12 +76,12 @@ describe Capybara::Session do end it "inspects nodes" do - subject.all(:xpath, "//strong").first.inspect.should include("strong") + expect(subject.all(:xpath, "//strong").first.inspect).to include("strong") end it "can read utf8 string" do utf8str = subject.all(:xpath, "//span").first.text - utf8str.should eq('UTF8文字列') + expect(utf8str).to eq('UTF8文字列') end it "can click utf8 string" do @@ -91,7 +91,7 @@ describe Capybara::Session do it "raises an ElementNotFound error when the selector scope is no longer valid" do subject.within('//body') do subject.click_link 'Link' - lambda { subject.find('//strong') }.should raise_error(Capybara::ElementNotFound) + expect { subject.find('//strong') }.to raise_error(Capybara::ElementNotFound) end end end @@ -119,26 +119,26 @@ describe Capybara::Session do it "should get status code" do subject.visit '/' - subject.status_code.should eq 200 + expect(subject.status_code).to eq 200 end it "should reset status code" do subject.visit '/' - subject.status_code.should eq 200 + expect(subject.status_code).to eq 200 subject.reset! - subject.status_code.should eq 0 + expect(subject.status_code).to eq 0 end it "should get response headers" do subject.visit '/' - subject.response_headers['X-Capybara'].should eq 'WebKit' + expect(subject.response_headers['X-Capybara']).to eq 'WebKit' end it "should reset response headers" do subject.visit '/' - subject.response_headers['X-Capybara'].should eq 'WebKit' + expect(subject.response_headers['X-Capybara']).to eq 'WebKit' subject.reset! - subject.response_headers['X-Capybara'].should eq nil + expect(subject.response_headers['X-Capybara']).to eq nil end end @@ -188,7 +188,7 @@ describe Capybara::Session do subject.visit("/") subject.click_link('Click Me!') Capybara.using_wait_time(5) do - subject.should have_content("finished") + expect(subject).to have_content("finished") end end end @@ -235,7 +235,7 @@ describe Capybara::Session do subject.fill_in('password', with: 'temp4now') subject.click_button('Submit') subject.visit('/other') - subject.should have_content('admin') + expect(subject).to have_content('admin') end end @@ -299,7 +299,7 @@ describe Capybara::Session do subject.within_frame 'a_frame' do subject.within_frame 'b_frame' do subject.click_button 'B Button' - subject.should have_content('Page C') + expect(subject).to have_content('Page C') end end end @@ -319,9 +319,9 @@ describe Capybara::Session do subject.within_frame('a_frame') do subject.within_frame('b_frame') do - lambda { + expect { subject.click_button 'B Button' - }.should raise_error(Capybara::Webkit::ClickFailed) + }.to raise_error(Capybara::Webkit::ClickFailed) end end end @@ -379,29 +379,29 @@ describe Capybara::Session do it 'clicks in the center of an element' do subject.visit('/') subject.find(:css, '#one').click - subject.find(:css, '#one')['data-click-x'].should eq '199' - subject.find(:css, '#one')['data-click-y'].should eq '199' + expect(subject.find(:css, '#one')['data-click-x']).to eq '199' + expect(subject.find(:css, '#one')['data-click-y']).to eq '199' end it 'clicks in the center of the viewable area of an element' do subject.visit('/') subject.driver.resize_window(200, 200) subject.find(:css, '#one').click - subject.find(:css, '#one')['data-click-x'].should eq '149' - subject.find(:css, '#one')['data-click-y'].should eq '99' + expect(subject.find(:css, '#one')['data-click-x']).to eq '149' + expect(subject.find(:css, '#one')['data-click-y']).to eq '99' end it 'does not raise an error when an anchor contains empty nodes' do subject.visit('/') - lambda { subject.click_link('Some link') }.should_not raise_error + expect { subject.click_link('Some link') }.not_to raise_error end it 'scrolls an element into view when clicked' do subject.visit('/') subject.driver.resize_window(200, 200) subject.find(:css, '#two').click - subject.find(:css, '#two')['data-click-x'].should_not be_nil - subject.find(:css, '#two')['data-click-y'].should_not be_nil + expect(subject.find(:css, '#two')['data-click-x']).not_to be_nil + expect(subject.find(:css, '#two')['data-click-y']).not_to be_nil end it 'raises an error if an element is obscured when clicked' do @@ -417,11 +417,11 @@ describe Capybara::Session do expect { subject.find(:css, '#one').click }.to raise_error(Capybara::Webkit::ClickFailed) { |exception| - exception.message.should =~ %r{Failed.*\[@id='one'\].*overlapping.*\[@id='two'\].*at position} + expect(exception.message).to match %r{Failed.*\[@id='one'\].*overlapping.*\[@id='two'\].*at position} screenshot_pattern = %r{A screenshot of the page at the time of the failure has been written to (.*)} - exception.message.should =~ screenshot_pattern + expect(exception.message).to match screenshot_pattern file = exception.message.match(screenshot_pattern)[1] - File.exist?(file).should be_true + expect(File.exist?(file)).to be true } end @@ -438,9 +438,9 @@ describe Capybara::Session do document.body.appendChild(div); JS - lambda { + expect { subject.check('bar') - }.should raise_error(Capybara::Webkit::ClickFailed) + }.to raise_error(Capybara::Webkit::ClickFailed) end it 'raises an error if an element is not visible when clicked' do @@ -449,7 +449,7 @@ describe Capybara::Session do begin subject.visit('/') subject.execute_script "document.getElementById('foo').style.display = 'none'" - lambda { subject.click_link "Click Me" }.should raise_error( + expect { subject.click_link "Click Me" }.to raise_error( Capybara::Webkit::ClickFailed, /\[@id='foo'\].*visible/ ) @@ -460,7 +460,7 @@ describe Capybara::Session do it 'raises an error if an element is not in the viewport when clicked' do subject.visit('/') - lambda { subject.click_link "Click Me" }.should raise_error(Capybara::Webkit::ClickFailed) + expect { subject.click_link "Click Me" }.to raise_error(Capybara::Webkit::ClickFailed) end context "with wait time of 1 second" do @@ -479,7 +479,7 @@ describe Capybara::Session do }, 400); JS - lambda { subject.click_link "Click Me" }.should_not raise_error + expect { subject.click_link "Click Me" }.not_to raise_error end end end @@ -538,7 +538,7 @@ describe Capybara::Session do session.attach_file 'File', file.path session.click_on 'Go' - session.should have_text('Hello') + expect(session).to have_text('Hello') end end end diff --git a/spec/selenium_compatibility_spec.rb b/spec/selenium_compatibility_spec.rb index 46f2281..42b2d03 100644 --- a/spec/selenium_compatibility_spec.rb +++ b/spec/selenium_compatibility_spec.rb @@ -107,7 +107,7 @@ describe Capybara::Webkit, 'compatibility with selenium' do end def compare_for_drivers(first, second, &block) - for_driver(first, &block).should == for_driver(second, &block) + expect(for_driver(first, &block)).to eq for_driver(second, &block) end def for_driver(name, &block) diff --git a/spec/server_spec.rb b/spec/server_spec.rb index 619a910..29f6574 100644 --- a/spec/server_spec.rb +++ b/spec/server_spec.rb @@ -16,7 +16,7 @@ describe Capybara::Webkit::Connection do write_io.close webkit_pid = read_io.read.to_i - webkit_pid.should be > 1 + expect(webkit_pid).to be > 1 read_io.close Process.kill(9, fork_pid) @@ -59,14 +59,14 @@ describe Capybara::Webkit::Connection do socket.puts 1 socket.puts url.to_s.bytesize socket.print url - socket.gets.should eq "ok\n" - socket.gets.should eq "0\n" + expect(socket.gets).to eq "ok\n" + expect(socket.gets).to eq "0\n" socket.puts "Body" socket.puts 0 - socket.gets.should eq "ok\n" + expect(socket.gets).to eq "ok\n" response_length = socket.gets.to_i response = socket.read(response_length) - response.should include("Hey there") + expect(response).to include("Hey there") end it "forwards stderr to the given IO object" do @@ -86,27 +86,27 @@ describe Capybara::Webkit::Connection do end it "does not forward stderr to nil" do - IO.should_not_receive(:copy_stream) + expect(IO).not_to receive(:copy_stream) start_server(stderr: nil) end it "prints a deprecation warning if the stdout option is used" do - Capybara::Webkit::Server.any_instance.should_receive(:warn) + expect_any_instance_of(Capybara::Webkit::Server).to receive(:warn) start_server(stdout: nil) end it "does not forward stdout to nil if the stdout option is used" do - Capybara::Webkit::Server.any_instance.stub(:warn) - IO.should_not_receive(:copy_stream) + allow_any_instance_of(Capybara::Webkit::Server).to receive(:warn) + expect(IO).not_to receive(:copy_stream) start_server(stdout: nil) end it "returns the server port" do - start_server.port.should be_between 0x400, 0xffff + expect(start_server.port).to be_between 0x400, 0xffff end it "chooses a new port number for a new connection" do - start_server.port.should_not == start_server.port + expect(start_server.port).not_to eq start_server.port end before(:all) do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b76c00f..80d2a00 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,4 @@ require 'rspec' -require 'rspec/autorun' require 'rbconfig' require 'capybara' @@ -48,12 +47,20 @@ RSpec.configure do |c| require 'capybara_webkit_builder' c.filter_run_excluding :skip_on_qt4 => !(%x(#{CapybaraWebkitBuilder.qmake_bin} -v).match(/Using Qt version 4/)).nil? - # We can't support outerWidth and outerHeight without a visible window. + # We can't support outerWidth and outerHeight without a visible window. Only affects Capybara < 2.12.0 # We focus the next window instead of failing when closing windows. + # Accessing unattached nodes is allowed when reload is disabled - Legacy behavior + # Node#send_keys does not support modifiers and only supports a subset of special keys c.filter_run_excluding :full_description => lambda { |description, metadata| (description !~ /Capybara::Session webkit node #send_keys should send a string of keys to an element/) && ( - description =~ /Capybara::Session webkit Capybara::Window #(size|resize_to|maximize|close.*no_such_window_error|send_keys)/ || - description =~ /Capybara::Session webkit node #send_keys/ + description =~ /Capybara::Session webkit node #send_keys/ || + description =~ /Capybara::Session webkit node #reload without automatic reload should not automatically reload/ || + if Gem::Version.new(Capybara::VERSION) < Gem::Version.new("2.12.0") + description =~ /Capybara::Session webkit Capybara::Window\s*#(size|resize_to|maximize|close.*no_such_window_error|send_keys)/ || + description =~ /Capybara::Session webkit node\s*#set should allow me to change the contents of a contenteditable elements child/ + else + description =~ /Capybara::Session webkit Capybara::Window\s*#close.*no_such_window_error/ + end ) } end diff --git a/spec/support/matchers/include_response.rb b/spec/support/matchers/include_response.rb index 59d02ba..9966af5 100644 --- a/spec/support/matchers/include_response.rb +++ b/spec/support/matchers/include_response.rb @@ -14,11 +14,11 @@ RSpec::Matchers.define :include_response do |expected_response| found_response end - failure_message_for_should do |actual| + send(respond_to?(:failure_message) ? :failure_message : :failure_message_for_should) do |actual| "expected #{response} to include #{expected_response}" end - failure_message_for_should_not do |actual| + send(respond_to?(:failure_message_when_negated) ? :failure_message_when_negated : :failure_message_for_should_not) do |actual| "expected #{response} to not include #{expected_response}" end end