2012-10-30 09:18:48 -04:00
|
|
|
require 'capybara/rspec' # Required here instead of in rspec_spec to avoid RSpec deprecation warning
|
|
|
|
require 'capybara/spec/test_app'
|
|
|
|
require 'capybara/spec/spec_helper'
|
|
|
|
require 'nokogiri'
|
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
module Capybara
|
|
|
|
module SpecHelper
|
|
|
|
class << self
|
|
|
|
def configure(config)
|
|
|
|
filter = lambda do |requires, metadata|
|
|
|
|
if requires and metadata[:skip]
|
2012-07-23 22:40:53 -04:00
|
|
|
requires.any? do |require|
|
2012-07-21 16:44:10 -04:00
|
|
|
metadata[:skip].include?(require)
|
|
|
|
end
|
|
|
|
else
|
2012-07-23 22:40:53 -04:00
|
|
|
false
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
|
|
|
end
|
2012-07-23 22:40:53 -04:00
|
|
|
config.filter_run_excluding :requires => filter
|
2012-10-30 09:10:22 -04:00
|
|
|
config.before do
|
|
|
|
Capybara.app = TestApp
|
|
|
|
|
|
|
|
Capybara.configure do |config|
|
|
|
|
config.default_selector = :xpath
|
|
|
|
end
|
|
|
|
|
|
|
|
# set up a fast wait time so that most tests are faster
|
|
|
|
# but, if we require JS, increase it a bit.
|
|
|
|
if example.metadata[:requires] and example.metadata[:requires].include?(:js)
|
|
|
|
Capybara.default_wait_time = 1
|
|
|
|
else
|
|
|
|
Capybara.default_wait_time = 0
|
|
|
|
end
|
|
|
|
end
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def spec(name, options={}, &block)
|
|
|
|
@specs ||= []
|
|
|
|
@specs << [name, options, block]
|
|
|
|
end
|
|
|
|
|
|
|
|
def run_specs(session, name, options={})
|
|
|
|
specs = @specs
|
|
|
|
describe Capybara::Session, name, options do
|
|
|
|
include Capybara::SpecHelper
|
|
|
|
before do
|
|
|
|
@session = session
|
|
|
|
end
|
|
|
|
after do
|
|
|
|
@session.reset_session!
|
|
|
|
end
|
|
|
|
specs.each do |name, options, block|
|
|
|
|
describe name, options do
|
|
|
|
class_eval(&block)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end # class << self
|
|
|
|
|
|
|
|
def silence_stream(stream)
|
|
|
|
old_stream = stream.dup
|
|
|
|
stream.reopen(RbConfig::CONFIG['host_os'] =~ /rmswin|mingw/ ? 'NUL:' : '/dev/null')
|
|
|
|
stream.sync = true
|
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
stream.reopen(old_stream)
|
|
|
|
end
|
|
|
|
|
|
|
|
def quietly
|
|
|
|
silence_stream(STDOUT) do
|
|
|
|
silence_stream(STDERR) do
|
|
|
|
yield
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def extract_results(session)
|
|
|
|
YAML.load Nokogiri::HTML(session.body).xpath("//pre[@id='results']").first.text.lstrip
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
RSpec.configure do |config|
|
|
|
|
Capybara::SpecHelper.configure(config)
|
|
|
|
end
|
2012-10-30 09:18:48 -04:00
|
|
|
|
|
|
|
Dir[File.dirname(__FILE__)+'/session/*'].each { |group| require group }
|