/
musicindex_spec.rb
79 lines (58 loc) · 2.02 KB
/
musicindex_spec.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
70
71
72
73
74
75
76
77
78
79
# -*- coding: utf-8 -*-
%w(/../spec_helper /../test_app).each do |filename|
require File.expand_path(File.dirname(__FILE__) + filename)
end
set :environment, :test
require 'nokogiri'
require 'fileutils'
describe Rack::MusicIndex do
def app
Sinatra::Application
end
before do
@mp3 = fixture('/foo/test2.mp3')
end
after do
if File.exist?(@mp3)
FileUtils.rm(@mp3)
end
end
it 'should index mp3s as podcast' do
get '/foo'
last_response.should be_ok
xml = Nokogiri::XML(last_response.body)
channel = xml.xpath('//channel')[0]
items = xml.xpath('//item')
item = items[0]
channel.xpath('title')[0].content.should eql('/foo')
channel.xpath('description')[0].content.should eql('Generated by Rack::MusicIndex')
items.size.should eql(1)
item.xpath('title')[0].content.should eql('bar')
item.xpath('link')[0].content.should eql('http://example.org/foo/test%20foo%20%E3%81%82%E3%81%82%E3%81%82.mp3')
item.xpath('guid')[0].content.should eql('http://example.org/foo/test%20foo%20%E3%81%82%E3%81%82%E3%81%82.mp3')
item.xpath('enclosure')[0]['url'].should eql('http://example.org/foo/test%20foo%20%E3%81%82%E3%81%82%E3%81%82.mp3')
item.xpath('author')[0].content.should eql('foo')
item.xpath('itunes:author')[0].content.should eql('foo')
end
it 'should reflect file changes without restart' do
get '/foo'
xml = Nokogiri::XML(last_response.body)
xml.xpath('//item').size.should eql(1)
open(@mp3, 'w') do |f|
f.write('xxx')
end
get '/foo'
xml = Nokogiri::XML(last_response.body)
xml.xpath('//item').size.should eql(2)
FileUtils.rm(@mp3)
get '/foo'
xml = Nokogiri::XML(last_response.body)
xml.xpath('//item').size.should eql(1)
end
it 'should return mp3' do
get '/foo/test%20foo%20%E3%81%82%E3%81%82%E3%81%82.mp3'
last_response.should be_ok
last_response['Content-Type'].should eql('audio/mpeg')
last_response.body.should eql(open(fixture('/foo/test foo あああ.mp3'), 'rb').read)
end
end