spec/ferver_spec.rb in ferver-1.0.0 vs spec/ferver_spec.rb in ferver-1.1.0
- old
+ new
@@ -1,15 +1,15 @@
-require 'spec_helper'
+require "spec_helper"
-describe 'ferver' do
+describe "ferver" do
include Webrat::Matchers # allow cool html matching
context "given a request to the server root" do
before(:each) do
- get '/'
+ get "/"
end
it "should return redirect" do
expect(last_response).to be_redirect
end
@@ -33,43 +33,63 @@
context "when no directory is specified" do
it "will use default directory" do
- Ferver::FileList.expects(:new).with('./').returns(@file_list)
+ Ferver::FileList.expects(:new).with("./").returns(@file_list)
- get '/files'
+ get "/files"
end
end
context "when the directory passed via configuration" do
- before { Ferver::App.set :ferver_path, '/foo' }
+ before { Ferver::App.set :ferver_path, "/foo" }
it "will use directory specified" do
- Ferver::FileList.expects(:new).with('/foo').returns(@file_list)
+ Ferver::FileList.expects(:new).with("/foo").returns(@file_list)
- get '/files'
+ get "/files"
end
end
+ context "when directory does not exist" do
+
+ before(:each) { Ferver::App.set :ferver_path, "/foo" }
+
+ it "will attempt to create FileList with path" do
+ Ferver::FileList.expects(:new).with("/foo").raises(Ferver::DirectoryNotFoundError)
+
+ get "/files"
+ end
+
+ it "will return server error status" do
+ Ferver::FileList.stubs(:new).with("/foo").raises(Ferver::DirectoryNotFoundError)
+
+ get "/files"
+
+ last_response.status.should eql 500
+ end
+
+ end
+
end
- context 'given an empty list of files' do
+ context "given an empty list of files" do
before {
file_list = mock()
file_list.stubs(:files).returns(EMPTY_FILE_LIST)
file_list.stubs(:file_count).returns(0)
Ferver::FileList.stubs(:new).returns(file_list)
}
context "when no content-type is requested" do
- before { get '/files' }
+ before { get "/files" }
it "should return valid response" do
expect(last_response).to be_ok
#todo test html
end
@@ -82,16 +102,16 @@
end
context "when json content-type is requested" do
before {
- get '/files', {}, {"HTTP_ACCEPT" => "application/json" }
+ get "/files", {}, {"HTTP_ACCEPT" => "application/json" }
}
it "should return valid response" do
expect(last_response).to be_ok
- expect(last_response.content_type).to include('application/json')
+ expect(last_response.content_type).to include("application/json")
end
it "should contain no file list in response content" do
list = JSON.parse last_response.body
expect(list).to eq(EMPTY_FILE_LIST)
@@ -99,22 +119,22 @@
end
end
- context 'given a list of files' do
+ context "given a list of files" do
before {
file_list = mock()
file_list.stubs(:files).returns(["file1", "file2"])
file_list.stubs(:file_count).returns(2)
Ferver::FileList.stubs(:new).returns(file_list)
}
context "when no content-type is requested" do
- before { get '/files' }
+ before { get "/files" }
it "should return valid response" do
expect(last_response).to be_ok
#todo test html
end
@@ -136,16 +156,16 @@
end
context "when json content-type is requested" do
before {
- get '/files', {}, {"HTTP_ACCEPT" => "application/json" }
+ get "/files", {}, {"HTTP_ACCEPT" => "application/json" }
}
it "should return valid response" do
expect(last_response).to be_ok
- expect(last_response.content_type).to include('application/json')
+ expect(last_response.content_type).to include("application/json")
end
it "should contain no file list in response content" do
list = JSON.parse last_response.body
expect(list.count).to eq(2)
@@ -168,11 +188,11 @@
context "when requesting a file out of range" do
before {
@file_list.expects(:file_id_is_valid?).with(3).returns(false)
- get '/files/3'
+ get "/files/3"
}
it "should return not_found" do
expect(last_response).to be_not_found
end
@@ -181,21 +201,21 @@
context "when requesting invalid file id" do
before {
@file_list.expects(:file_id_is_valid?).never
- get '/files/foo'
+ get "/files/foo"
}
it "should return not_found" do
expect(last_response).to be_bad_request
end
end
context "when requesting a valid file id" do
- before { get '/files/0' }
+ before { get "/files/0" }
xit "should return ok response" do
expect(last_response).to be_ok
end
\ No newline at end of file