Skip to content

Commit

Permalink
Update to RSpec 3.5+ only and expect syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
twalpole committed Jul 10, 2018
1 parent bf2c631 commit 5be309e
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
@@ -1,6 +1,5 @@
language: ruby
sudo: false
bundler_args: --without development
before_install:
- gem update --system
- gem update bundler
Expand All @@ -9,6 +8,7 @@ before_install:
rvm:
- 2.3.7
- 2.4.4
- 2.5.1
- jruby
- ruby-head
gemfile:
Expand Down
8 changes: 2 additions & 6 deletions Gemfile
Expand Up @@ -2,13 +2,9 @@ source 'http://rubygems.org'

gemspec

gem 'rspec', '~> 3.0'
gem 'launchy', '>= 2.0.4'
gem 'sinatra', '~> 2.0'
gem 'rake', '~> 10.0.3'
gem 'rdoc'
gem 'puma'
gem 'sinatra', '~> 2.0'

group :development do
gem 'debugger', :platforms => :ruby_19
gem 'debugger', platforms: :ruby_19
end
4 changes: 4 additions & 0 deletions capybara-mechanize.gemspec
Expand Up @@ -19,5 +19,9 @@ Gem::Specification.new do |s|

s.add_runtime_dependency(%q<mechanize>, ["~> 2.7.0"])
s.add_runtime_dependency(%q<capybara>, [">= 2.4.4", "< 4"])
s.add_development_dependency(%q<rake>)
s.add_development_dependency(%q<rdoc>)
s.add_development_dependency(%q<rspec>, ["~>3.5"])
s.add_development_dependency(%q<launchy>, [">= 2.0.4"])
end

6 changes: 2 additions & 4 deletions gemfiles/Gemfile.capybara_2
Expand Up @@ -4,11 +4,9 @@ gemspec :path => '..'

gem 'capybara', '~> 2.18.0'

gem 'rspec', '~> 2.99.0'
gem 'launchy', '>= 2.0.4'
gem 'sinatra', '~> 1.3.3'
gem 'rake', '~> 10.0.3'
gem 'rdoc'

gem 'nokogiri', '1.8.2' # 1.8.3+ fixes CSS selector escaping which causes two pending tests to pass

group :development do
gem 'ruby-debug', :platforms => :ruby_18
Expand Down
4 changes: 0 additions & 4 deletions gemfiles/Gemfile.capybara_master
Expand Up @@ -4,11 +4,7 @@ gemspec :path => '..'

gem 'capybara', github: 'jnicklas/capybara'

gem 'rspec', '~> 3.0'
gem 'launchy', '>= 2.0.4'
gem 'sinatra', '~> 2.0'
gem 'rake', '~> 10.0', '>= 10.0.3'
gem 'rdoc'
gem 'puma'

group :development do
Expand Down
50 changes: 25 additions & 25 deletions spec/driver/mechanize_driver_spec.rb
Expand Up @@ -5,7 +5,7 @@

describe "#configure" do
it "allows extended configuration of the agent" do
::Mechanize.any_instance.should_receive(:foo=).with("test")
expect_any_instance_of(::Mechanize).to receive(:foo=).with("test")
driver.configure do |agent|
agent.foo = "test"
end
Expand All @@ -16,27 +16,27 @@
it 'should always set headers' do
driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
driver.visit('/get_header')
driver.html.should include('foobar')
expect(driver.html).to include('foobar')
end

it 'should keep headers on link clicks' do
driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
driver.visit('/header_links')
driver.find_xpath('.//a').first.click
driver.html.should include('foobar')
expect(driver.html).to include('foobar')
end

it 'should keep headers on form submit' do
driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
driver.visit('/header_links')
driver.find_xpath('.//input').first.click
driver.html.should include('foobar')
expect(driver.html).to include('foobar')
end

it 'should keep headers on redirects' do
driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
driver.visit('/get_header_via_redirect')
driver.html.should include('foobar')
expect(driver.html).to include('foobar')
end
end

Expand All @@ -45,16 +45,16 @@
driver = Capybara::RackTest::Driver.new(TestApp)

driver.visit('/redirect')
driver.response.header['Location'].should be_nil
driver.browser.current_url.should match %r{/landed$}
expect(driver.response.header['Location']).to be_nil
expect(driver.browser.current_url).to match %r{/landed$}
end

it "is possible to not follow redirects" do
driver = Capybara::RackTest::Driver.new(TestApp, :follow_redirects => false)

driver.visit('/redirect')
driver.response.header['Location'].should match %r{/redirect_again$}
driver.browser.current_url.should match %r{/redirect$}
expect(driver.response.header['Location']).to match %r{/redirect_again$}
expect(driver.browser.current_url).to match %r{/redirect$}
end
end

Expand All @@ -64,7 +64,7 @@

it "should follow 5 redirects" do
driver.visit("/redirect/5/times")
driver.html.should include('redirection complete')
expect(driver.html).to include('redirection complete')
end

it "should not follow more than 6 redirects" do
Expand All @@ -79,7 +79,7 @@

it "should follow 21 redirects" do
driver.visit("/redirect/21/times")
driver.html.should include('redirection complete')
expect(driver.html).to include('redirection complete')
end

it "should not follow more than 21 redirects" do
Expand All @@ -91,11 +91,11 @@
end

it "should default to local mode for relative paths" do
driver.should_not be_remote('/')
expect(driver).not_to be_remote('/')
end

it "should default to local mode for the default host" do
driver.should_not be_remote('http://www.example.com')
expect(driver).not_to be_remote('http://www.example.com')
end

context "with an app_host" do
Expand All @@ -108,7 +108,7 @@
end

it "should treat urls as remote" do
driver.should be_remote('http://www.remote.com')
expect(driver).to be_remote('http://www.remote.com')
end
end

Expand All @@ -131,26 +131,26 @@
end

it "should allow local hosts to be set" do
driver.should_not be_remote('http://subdomain.local.com')
expect(driver).not_to be_remote('http://subdomain.local.com')
end
end

it "should treat urls with the same host names as local" do
driver.should_not be_remote('http://www.local.com')
expect(driver).not_to be_remote('http://www.local.com')
end

it "should treat other urls as remote" do
driver.should be_remote('http://www.remote.com')
expect(driver).to be_remote('http://www.remote.com')
end

it "should treat relative paths as remote if the previous request was remote" do
driver.visit(remote_test_url)
driver.should be_remote('/some_relative_link')
expect(driver).to be_remote('/some_relative_link')
end

it "should treat relative paths as local if the previous request was local" do
driver.visit('http://www.local.com')
driver.should_not be_remote('/some_relative_link')
expect(driver).not_to be_remote('/some_relative_link')
end

it "should receive the right host" do
Expand All @@ -163,15 +163,15 @@
driver.visit('/host')

should_be_a_local_get
driver.should_not be_remote('/first_local')
expect(driver).not_to be_remote('/first_local')
end

it "should consider relative paths to be remote when the previous request was remote" do
driver.visit("#{remote_test_url}/host")
driver.get('/host')

should_be_a_remote_get
driver.should be_remote('/second_remote')
expect(driver).to be_remote('/second_remote')
end

it "should always switch to the right context" do
Expand All @@ -182,7 +182,7 @@
driver.get('http://www.local.com/host')

should_be_a_local_get
driver.should_not be_remote('/second_local')
expect(driver).not_to be_remote('/second_local')
end

it "should follow redirects from local to remote" do
Expand All @@ -199,7 +199,7 @@
quietly do
driver.visit(remote_test_url)
driver.get('/asdfafadfsdfs')
driver.response.status.should be >= 400
expect(driver.response.status).to be >= 400
end
end

Expand Down Expand Up @@ -243,11 +243,11 @@
end

def should_be_a_remote_get
driver.current_url.should include(remote_test_url)
expect(driver.current_url).to include(remote_test_url)
end

def should_be_a_local_get
driver.current_url.should include("www.local.com")
expect(driver.current_url).to include("www.local.com")
end

end
10 changes: 5 additions & 5 deletions spec/driver/remote_mechanize_driver_spec.rb
Expand Up @@ -14,32 +14,32 @@
context "in remote mode" do
it "should pass arguments through to a get request" do
driver.visit("#{remote_test_url}/form/get", {:form => {:value => "success"}})
driver.html.should include('success')
expect(driver.html).to include('success')
end

it "should pass arguments through to a post request" do
driver.post("#{remote_test_url}/form", {:form => {:value => "success"}})
driver.html.should include('success')
expect(driver.html).to include('success')
end

describe "redirect" do
it "should handle redirects with http-params" do
driver.visit "#{remote_test_url}/redirect_with_http_param"
driver.html.should include('correct redirect')
expect(driver.html).to include('correct redirect')
end
end

context "for a post request" do
it 'transforms nested map in post data' do
driver.post("#{remote_test_url}/form", {:form => {:key => 'value'}})
driver.html.should match(/:key=>"value"|key: value/)
expect(driver.html).to match(/:key=>"value"|key: value/)
end
end

context 'process remote request' do
it 'transforms nested map in post data' do
driver.submit(:post, "#{remote_test_url}/form", {:form => {:key => 'value'}})
driver.html.should match(/:key=>"value"|key: value/)
expect(driver.html).to match(/:key=>"value"|key: value/)
end
end
end
Expand Down
22 changes: 11 additions & 11 deletions spec/session/mechanize_spec.rb
Expand Up @@ -32,13 +32,13 @@ module TestSessions

describe '#driver' do
it "should be a mechanize driver" do
session.driver.should be_an_instance_of(Capybara::Mechanize::Driver)
expect(session.driver).to be_an_instance_of(Capybara::Mechanize::Driver)
end
end

describe '#mode' do
it "should remember the mode" do
session.mode.should == :mechanize
expect(session.mode).to eq(:mechanize)
end
end

Expand All @@ -47,21 +47,21 @@ module TestSessions
session.driver.options[:respect_data_method] = true
session.visit "/with_html"
session.click_link "A link with data-method"
session.html.should include('The requested object was deleted')
expect(session.html).to include('The requested object was deleted')
end

it "should not use data-method if option is false" do
session.driver.options[:respect_data_method] = false
session.visit "/with_html"
session.click_link "A link with data-method"
session.html.should include('Not deleted')
expect(session.html).to include('Not deleted')
end

it "should use data-method if available even if it's capitalized" do
session.driver.options[:respect_data_method] = true
session.visit "/with_html"
session.click_link "A link with capitalized data-method"
session.html.should include('The requested object was deleted')
expect(session.html).to include('The requested object was deleted')
end

after do
Expand All @@ -74,39 +74,39 @@ module TestSessions
it "should submit an empty form-data section if no file is submitted" do
session.visit("/form")
session.click_button("Upload Empty")
session.html.should include('Successfully ignored empty file field.')
expect(session.html).to include('Successfully ignored empty file field.')
end
end
end

it "should use the last remote url when following relative links" do
session.visit("#{remote_test_url}/relative_link_to_host")
session.click_link "host"
session.body.should include("Current host is #{remote_test_url}/request_info/host, method get")
expect(session.body).to include("Current host is #{remote_test_url}/request_info/host, method get")
end

it "should use the last remote url when submitting a form with a relative action" do
session.visit("#{remote_test_url}/form_with_relative_action_to_host")
session.click_button "submit"
session.body.should include("Current host is #{remote_test_url}/request_info/host, method post")
expect(session.body).to include("Current host is #{remote_test_url}/request_info/host, method post")
end

it "should use the last url when submitting a form with no action" do
session.visit("#{remote_test_url}/request_info/form_with_no_action")
session.click_button "submit"
session.body.should include("Current host is #{remote_test_url}/request_info/form_with_no_action, method post")
expect(session.body).to include("Current host is #{remote_test_url}/request_info/form_with_no_action, method post")
end

it "should send correct user agent" do
session.visit("#{remote_test_url}/request_info/user_agent")
session.body.should include("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_0) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.853.0 Safari/535.2")
expect(session.body).to include("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_0) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.853.0 Safari/535.2")
end

context 'form referer when switching from local to remote' do
it 'sends the referer' do
session.visit "/form_posts_to/#{remote_test_url}/get_referer"
session.click_button 'submit'
session.body.should include 'Got referer'
expect(session.body).to include 'Got referer'
end
end
end
Expand Down

0 comments on commit 5be309e

Please sign in to comment.