Skip to content

Commit

Permalink
Revert railtie.rb to be generic again, browser driver name has to be …
Browse files Browse the repository at this point in the history
…supplied explicitly
  • Loading branch information
mackermans committed Jul 5, 2016
1 parent 1f5bc59 commit df2abd9
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 41 deletions.
31 changes: 10 additions & 21 deletions lib/billy/browsers/watir.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,12 @@ module Browsers
class Watir < ::Watir::Browser

def initialize(name, args = {})
@defaults = {
chrome: {
switches: %W[--proxy-server=#{Billy.proxy.host}:#{Billy.proxy.port}]
},
phantomjs: {
args: %W[--proxy=#{Billy.proxy.host}:#{Billy.proxy.port}]
},
firefox: {
profile: Selenium::WebDriver::Firefox::Profile.new,
proxy: Selenium::WebDriver::Proxy.new(
http: "#{Billy.proxy.host}:#{Billy.proxy.port}",
ssl: "#{Billy.proxy.host}:#{Billy.proxy.port}"
)
}
}

args = case name
when :chrome then configure_chrome(args)
when :phantomjs then configure_phantomjs(args)
else configure_firefox(args)
when :firefox then configure_firefox(args)
else
raise NameError, "Invalid browser driver specified. (Expected: :chrome, :phantomjs, :firefox)"
end
super
end
Expand All @@ -34,19 +20,22 @@ def initialize(name, args = {})

def configure_chrome(args)
args[:switches] ||= []
args[:switches] += @defaults[:chrome][:switches]
args[:switches] += %W[--proxy-server=#{Billy.proxy.host}:#{Billy.proxy.port}]
args
end

def configure_phantomjs(args)
args[:args] ||= []
args[:args] += @defaults[:phantomjs][:args]
args[:args] += %W[--proxy=#{Billy.proxy.host}:#{Billy.proxy.port}]
args
end

def configure_firefox(args)
args[:profile] ||= @defaults[:firefox][:profile]
args[:profile].proxy = @defaults[:firefox][:proxy]
args[:profile] ||= Selenium::WebDriver::Firefox::Profile.new
args[:profile].proxy = Selenium::WebDriver::Proxy.new(
http: "#{Billy.proxy.host}:#{Billy.proxy.port}",
ssl: "#{Billy.proxy.host}:#{Billy.proxy.port}"
)
args
end

Expand Down
2 changes: 0 additions & 2 deletions lib/billy/capybara/railtie.rb

This file was deleted.

9 changes: 0 additions & 9 deletions lib/billy/init/railtie.rb

This file was deleted.

14 changes: 8 additions & 6 deletions lib/billy/railtie.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Deprecated
require 'billy/browsers/capybara'
require 'billy/init/railtie'
module Billy
class Railtie < Rails::Railtie
railtie_name 'billy'

Billy::Browsers::Capybara.register_drivers

warn "[DEPRECATION] `require 'billy/railtie'` is deprecated. Please use `require 'billy/capybara/railtie'` instead."
rake_tasks do
load 'tasks/billy.rake'
end
end
end
2 changes: 0 additions & 2 deletions lib/billy/watir/railtie.rb

This file was deleted.

6 changes: 5 additions & 1 deletion spec/lib/billy/watir/watir_spec.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
require 'spec_helper'

describe 'Watir usage example', type: :feature, js: true do
describe 'Watir-specific tests', type: :feature, js: true do
before do
proxy.stub('http://www.example.com/get').and_return(
text: 'Success!'
)
end

it 'should raise a NameError if an invalid browser driver is specified' do
expect(Billy::Browsers::Watir.new :invalid).to raise_error(NameError)
end

it 'should respond to a stubbed GET request' do
@browser.goto 'http://www.example.com/get'
expect(@browser.text).to eq 'Success!'
Expand Down

0 comments on commit df2abd9

Please sign in to comment.