forked from streamio/streamio-ffmpeg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspec_helper.rb
69 lines (56 loc) · 1.81 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
69
require 'simplecov'
SimpleCov.start
require 'bundler'
Bundler.require
require 'fileutils'
require 'webmock/rspec'
WebMock.allow_net_connect!
FFMPEG.logger = Logger.new(nil)
RSpec.configure do |config|
config.filter_run focus: true
config.run_all_when_everything_filtered = true
config.before(:each) do
stub_request(:head, /redirect-example.com/).
with(:headers => {'Accept'=>'*/*', 'User-Agent' => 'Ruby'}).
to_return(status: 302, headers: {
location: 'http://127.0.0.1:8000/awesome%20movie.mov'
})
stub_request(:head, 'http://127.0.0.1:8000/deep_path/awesome%20movie.mov').
with(:headers => {'Accept'=>'*/*', 'User-Agent' => 'Ruby'}).
to_return(status: 302, headers: {
location: '/awesome%20movie.mov'
})
stub_request(:head, 'http://127.0.0.1:8000/awesome%20movie.mov?fail=1').
with(:headers => {'Accept'=>'*/*', 'User-Agent' => 'Ruby'}).
to_return(status: 404, headers: { })
stub_request(:head, /toomany-redirects-example/).
with(:headers => {'Accept'=>'*/*', 'User-Agent' => 'Ruby'}).
to_return(status: 302, headers: {
location: '/awesome%20movie.mov'
})
end
end
def fixture_path
@fixture_path ||= File.join(File.dirname(__FILE__), 'fixtures')
end
def tmp_path
@tmp_path ||= File.join(File.dirname(__FILE__), "..", "tmp")
end
def start_web_server
@server = WEBrick::HTTPServer.new(
Port: 8000,
DocumentRoot: "#{fixture_path}/movies",
Logger: WEBrick::Log.new(File.open(File::NULL, 'w')),
AccessLog: []
)
@server.mount_proc '/unauthorized.mov' do |_, response|
response.body = 'Unauthorized'
response.status = 403
end
Thread.new { @server.start }
end
def stop_web_server
@server.shutdown
end
FileUtils.rm_rf(tmp_path)
FileUtils.mkdir_p tmp_path