spec/unit/server_spec.rb in js_spec-0.0.1 vs spec/unit/server_spec.rb in js_spec-0.1.0
- old
+ new
@@ -27,10 +27,21 @@
specify "'/core/JSSpec.js', returns the contents of the file" do
result = get("/core/JSSpec.js").body
result.should == ::File.read("#{Server.core_path}/JSSpec.js")
end
+
+ specify "'/stylesheets/example.css', returns the contents of the file" do
+ result = get("/stylesheets/example.css").body
+ result.should == ::File.read("#{Server.public_path}/stylesheets/example.css")
+ end
+
+ specify "'/invalid/path', shows the full invalid path in the error message" do
+ lambda do
+ get("/invalid/path")
+ end.should raise_error(Exception, Regexp.new("/invalid/path"))
+ end
end
describe ".run" do
attr_reader :server_instance
before do
@@ -40,61 +51,73 @@
it "instantiates an instance of Server and starts a Rack Mongrel handler" do
host = Server::DEFAULT_HOST
port = Server::DEFAULT_PORT
- mock.proxy(Server).new(spec_root_path, implementation_root_path, host, port) do
+ mock.proxy(Server).new(spec_root_path, implementation_root_path, public_path, host, port) do
server_instance
end
mock(Rack::Handler::Mongrel).run(server_instance, {:Host => host, :Port => port})
- Server.run(spec_root_path, implementation_root_path)
+ Server.run(spec_root_path, implementation_root_path, public_path)
end
it "when passed a custom host and port, sets the host and port to the passed in value" do
host = 'foobar.com'
port = 80
- mock.proxy(Server).new(spec_root_path, implementation_root_path, host, port) do
+ mock.proxy(Server).new(spec_root_path, implementation_root_path, public_path, host, port) do
server_instance
end
mock(Rack::Handler::Mongrel).run(server_instance, {:Host => host, :Port => port})
- Server.run(spec_root_path, implementation_root_path, {:Host => host, :Port => port})
+ Server.run(spec_root_path, implementation_root_path, public_path, {:Host => host, :Port => port})
end
end
+ describe ".default_url" do
+ it "returns the default host and port" do
+ Server.default_url.should == "http://#{Server::DEFAULT_HOST}:#{Server::DEFAULT_PORT}"
+ end
+ end
+
describe ".spec_root" do
it "returns the Dir " do
- Server.spec_root_path.should == ::File.expand_path(spec_root_path)
+ Server.spec_root_path.should == spec_root_path
end
end
describe ".spec_root_path" do
it "returns the absolute path of the specs root directory" do
- Server.spec_root_path.should == ::File.expand_path(spec_root_path)
+ Server.spec_root_path.should == spec_root_path
end
end
+ describe ".public_path" do
+ it "returns the expanded path of the public path" do
+ Server.public_path.should == public_path
+ end
+ end
+
describe ".core_path" do
it "returns the expanded path to the JsSpec core directory" do
dir = ::File.dirname(__FILE__)
Server.core_path.should == ::File.expand_path("#{dir}/../../core")
end
end
describe ".implementation_root_path" do
it "returns the expanded path to the JsSpec implementations directory" do
dir = ::File.dirname(__FILE__)
- Server.implementation_root_path.should == ::File.expand_path(implementation_root_path)
+ Server.implementation_root_path.should == implementation_root_path
end
end
describe ".request" do
it "returns request in progress for the thread" do
the_request = nil
- stub.instance_of(WebRoot).locate('somedir') do
+ stub.instance_of(Resources::WebRoot).locate('somedir') do
the_request = JsSpec::Server.request
Thread.current[:request].should == the_request
thread2 = Thread.new do
Thread.current[:request].should be_nil
end
@@ -118,11 +141,11 @@
end
describe ".response" do
it "returns response in progress" do
the_response = nil
- stub.instance_of(WebRoot).locate('somedir') do
+ stub.instance_of(Resources::WebRoot).locate('somedir') do
the_response = JsSpec::Server.response
Thread.current[:response].should == the_response
thread2 = Thread.new do
Thread.current[:response].should be_nil
end
@@ -143,14 +166,52 @@
JsSpec::Server.response.should be_nil
end
end
- describe "#initialize" do
- it "expands relative paths for #spec_root_path and #implementation_root_path" do
- server = Server.new("foo", "bar")
- server.spec_root_path.should == ::File.expand_path("foo")
- server.implementation_root_path.should == ::File.expand_path("bar")
+ describe "#call" do
+ it "when resource responds with a string, sets the string as the response.body" do
+ somedir_resource = Object.new
+ stub.instance_of(Resources::WebRoot).locate('somedir') do
+ somedir_resource
+ end
+
+ def somedir_resource.get
+ "Somedir String"
+ end
+ response = get('/somedir')
+ response.body.should == "Somedir String"
+ end
+
+ describe "when there is an error" do
+ attr_reader :top_line_of_backtrace
+ before do
+ @top_line_of_backtrace = __LINE__ + 2
+ stub.instance_of(Resources::WebRoot).locate('somedir') do
+ raise "Foobar"
+ end
+ end
+
+ it "shows the full request path in the error message" do
+ lambda do
+ get('/somedir')
+ end.should raise_error(Exception, Regexp.new("/somedir"))
+ end
+
+ it "uses the backtrace from where the original error was raised" do
+ no_error = true
+ begin
+ get('/somedir')
+ rescue Exception => e
+ no_error = false
+ top_of_backtrace = e.backtrace.first.split(":")
+ backtrace_file = ::File.expand_path(top_of_backtrace[0])
+ backtrace_line = Integer(top_of_backtrace[1])
+ backtrace_file.should == __FILE__
+ backtrace_line.should == top_line_of_backtrace
+ end
+ raise "There should have been an error" if no_error
+ end
end
end
end
end
\ No newline at end of file