Skip to content

Instantly share code, notes, and snippets.

@frobs
Last active December 16, 2015 05:29
Show Gist options
  • Save frobs/5384976 to your computer and use it in GitHub Desktop.
Save frobs/5384976 to your computer and use it in GitHub Desktop.
Multibrowser test with capybara using Rake(if set two browser only work the last)
require 'rubygems'
require 'bundler'
Bundler.setup(:default)
desc 'Run specs multibrowser test'
task :spec, [:browser] do |t,args|
Bundler.setup(:test)
require 'rspec/core/rake_task'
ENV['TEST_BROWSER']=args.browser
RSpec::Core::RakeTask.new('spec') do |t|
t.pattern = FileList['spec/spec_base.rb']
end
end
require 'rspec'
require 'rack/test'
require 'capybara'
include Capybara::DSL
browsers=ENV["TEST_BROWSER"].to_s.split
Capybara.default_driver = :selenium #this is needed to fix a bug when browser is null
browsers.each{|browser|
puts "#{browser}"
ENV['CURRENT_BROWSER']=browser
unless browser.nil?
Capybara.register_driver :selenium do |app|
case browser
when "-p"
require 'capybara/poltergeist'
Capybara.current_driver = :poltergeist
when "-c"
Capybara::Selenium::Driver.new(app, :browser => :chrome)
when "-i"
Capybara::Selenium::Driver.new(app, :browser => :internet_explorer)
when "-s"
Capybara::Selenium::Driver.new(app, :browser => :safari)
when "-f"
Capybara::Selenium::Driver.new(app, :browser => :firefox)
end
end
end
#require all files or the file that we want test
if ENV['TEST'].nil?
Dir[ "#{File.dirname(__FILE__)}/*_spec.rb" ].sort.each do |path|
puts path
load(path)
end
else
load "spec/#{ENV['TEST']}"
end
}
RSpec.configure do |conf|
conf.include Rack::Test::Methods
end
def app
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment