forked from github/developer.github.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspec_helper.rb
More file actions
103 lines (84 loc) · 2.71 KB
/
spec_helper.rb
File metadata and controls
103 lines (84 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
require 'rack'
require 'capybara'
require 'capybara/dsl'
require 'rspec/core'
require 'capybara/rspec/matchers'
require 'capybara/rspec/features'
require 'awesome_print'
require 'yaml'
require 'nanoc'
require 'selenium/webdriver'
Dir.glob('tasks/*.rake').each { |r| load r}
# All the blog posts we're interested in checking. This means we're looking at
# files that have changed on this particular branch we're on.
#
# Returns an Array of String filenames.
def posts
return @posts if defined? @posts
diffable_files = `git diff -z --name-only --diff-filter=ACRTUXB origin/master -- content/changes/`.split("\0")
@posts = diffable_files.select do |filename|
ext = File.extname(filename)
ext == ".md" || ext == ".html"
end
end
# this does the file serving
class ImplictIndex
def initialize(root)
@root = root
@file_server = ::Rack::File.new(root)
res_path = ::File.join(File.dirname(__FILE__), '..', 'output')
@res_server = ::Rack::File.new(::File.expand_path(res_path))
end
attr_reader :root, :file_server, :res_server
def call(env)
path = env['PATH_INFO']
# if we are looking at / let's try index.html
if path == '/' && exists?('index.html')
env['PATH_INFO'] = '/index.html'
elsif !exists?(path) && exists?(path + '.html')
env['PATH_INFO'] += '.html'
elsif exists?(path) && directory?(path) && exists?(File.join(path, 'index.html'))
env['PATH_INFO'] += '/index.html'
end
self.file_server.call(env)
end
def exists?(path)
File.exist?(File.join(self.root, path))
end
def directory?(path)
File.directory?(File.join(self.root, path))
end
end
# Wire up Capybara to test again static files served by Rack
# Courtesy of http://opensoul.org/blog/archives/2010/05/11/capybaras-eating-cucumbers/
Capybara.app = Rack::Builder.new do
map '/' do
# use Rack::CommonLogger, $stderr
use Rack::Lint
run ImplictIndex.new(File.join(File.dirname(__FILE__), '..', 'output'))
end
end.to_app
Capybara.register_driver :phantomjs do |app|
Capybara::Selenium::Driver.new(app, browser: :phantomjs)
end
Capybara.javascript_driver = :selenium
RSpec.configure do |config|
config.order = 'random'
config.color = true
config.formatter = :progress
config.filter_run_excluding :skip => true
config.include Capybara::DSL
config.include Capybara::RSpecMatchers
config.before do
if self.class.include?(Capybara::DSL)
example = RSpec.current_example
Capybara.current_driver = Capybara.javascript_driver if example.metadata[:js]
Capybara.current_driver = example.metadata[:driver] if example.metadata[:driver]
end
end
config.after do
if self.class.include?(Capybara::DSL)
Capybara.use_default_driver
end
end
end