This repository has been archived by the owner on Jan 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 275
/
server_spec.rb
90 lines (77 loc) · 3.26 KB
/
server_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
80
81
82
83
84
85
86
87
88
89
90
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
require 'rack/test'
describe "Jasmine.app" do
LOADED_FLAG = "\n\njasmine._runner_.fileLoaded();"
include Rack::Test::Methods
def app
config = Jasmine::Config.new
@root = File.join(File.dirname(__FILE__))
config.stub!(:project_root).and_return(@root)
config.stub!(:spec_dir).and_return(File.join(@root, "fixture", "spec"))
config.stub!(:src_dir).and_return(File.join(@root, "fixture", "src"))
config.stub!(:src_files).and_return(["file1.js"])
config.stub!(:spec_files).and_return(["file2.js"])
Jasmine.app(config)
end
it "should serve static files from spec dir under __spec__ with loaded flag appended" do
get "/__spec__/example_spec.js"
last_response.status.should == 200
last_response.content_type.should == "application/javascript"
last_response.body.should == File.read(File.join(@root, "fixture/spec/example_spec.js")) + LOADED_FLAG
end
it "should serve static files from root dir under __root__ with loaded flag appended" do
get "/__root__/fixture/src/example.js"
last_response.status.should == 200
last_response.content_type.should == "application/javascript"
last_response.body.should == File.read(File.join(@root, "fixture/src/example.js")) + LOADED_FLAG
end
it "should serve static files from src dir under / with loaded flag appended" do
get "/example.js"
last_response.status.should == 200
last_response.content_type.should == "application/javascript"
last_response.body.should == File.read(File.join(@root, "fixture/src/example.js")) + LOADED_FLAG
end
it "should serve Jasmine static files under /__JASMINE_ROOT__/" do
get "/__JASMINE_ROOT__/jasmine.css"
last_response.status.should == 200
last_response.content_type.should == "text/css"
last_response.body.should == File.read(File.join(Jasmine::Core.path, "jasmine.css"))
end
it "should serve focused suites when prefixing spec files with /__suite__/" do
Dir.stub!(:glob).and_return { |glob_string| [glob_string] }
get "/__suite__/file2.js"
last_response.status.should == 200
last_response.content_type.should == "text/html"
last_response.body.should include("\"/__spec__/file2.js")
end
it "should redirect /run.html to /" do
get "/run.html"
last_response.status.should == 302
last_response.location.should == "/"
end
it "should 404 non-existent files" do
get "/some-non-existent-file"
last_response.should be_not_found
end
describe "/ page" do
it "should load each js file in order" do
get "/"
last_response.status.should == 200
last_response.body.should include("\"/file1.js")
last_response.body.should include("\"/__spec__/file2.js")
last_response.body.should satisfy {|s| s.index("/file1.js") < s.index("/__spec__/file2.js") }
end
it "should return an empty 200 for HEAD requests to /" do
head "/"
last_response.status.should == 200
last_response.headers['Content-Type'].should == 'text/html'
last_response.body.should == ''
end
it "should tell the browser not to cache any assets" do
head "/"
['Cache-Control', 'Pragma'].each do |key|
last_response.headers[key].should == 'no-cache'
end
end
end
end