-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathspec_helper.rb
68 lines (58 loc) · 1.76 KB
/
spec_helper.rb
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
# frozen_string_literal: true
# Generate coverage when run locally with rake coverage
require_relative './spec_helper_simplecov.rb' if ENV['COVERAGE']
# Load coverage when run through Travis
if ENV['TRAVIS']
require 'coveralls'
Coveralls.wear!
end
require 'jekyll'
require 'jekyll-algolia'
require 'ostruct'
RSpec.configure do |config|
config.filter_run(focus: true)
config.fail_fast = true
config.run_all_when_everything_filtered = true
config.before do
Jekyll::Algolia::Configurator.init
end
end
# We will run our tests with a real Jekyll instance, to make sure it works
# with the real beast.
def init_new_jekyll_site(user_config = {})
# We start a new Jekyll site, using our ./spec/site directory as its starting
# point
config = Jekyll.configuration(
user_config.merge(
source: File.expand_path('./spec/site')
)
)
algolia_command = Jekyll::Algolia.init(config)
# Silence the progress bars. We couldn't use a double here as it would leak
# across tests and this is not allowed by rspec.
fake_progress_bar = OpenStruct.new
fake_progress_bar.increment = nil
allow(ProgressBar)
.to receive(:create)
.and_return(fake_progress_bar)
site = algolia_command.site
# We monkey patch it to add a new method that will allow us to more easily
# access the files that are processed by Jekyll, and return an actual instance
# of Jekyll::File
def site.__find_file(needle)
each_site_file do |file|
return file if file.path =~ /#{needle}$/
end
nil
end
def site.__all_files
each_site_file do |file|
puts file.path
end
end
# We have to run the command to actually initialize the Jekyll site so
# it populates its list of internal files
allow(site).to receive(:push)
algolia_command.run
site
end