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-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
|