ferver 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -9
- data/Rakefile +18 -1
- data/bin/ferver +2 -0
- data/lib/ferver.rb +2 -0
- data/lib/ferver/app.rb +17 -28
- data/lib/ferver/file_id_request.rb +28 -0
- data/lib/ferver/file_list.rb +2 -17
- data/lib/ferver/version.rb +1 -1
- data/spec/ferver_spec.rb +39 -19
- data/spec/file_id_request_spec.rb +86 -0
- data/spec/file_list_spec.rb +27 -7
- data/spec/spec_helper.rb +2 -1
- metadata +5 -3
- data/run.rb +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88fa261cbca7d3076a07ff0531243891902f7b13
|
4
|
+
data.tar.gz: 2ba5cbe2dd11de73bcc3076e878529fed5c1e685
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66bb027b877ae36dbdcc68a53f75558480dafd2af82382ab53b47a6bdd856189b1b93ae48d95608defcf94beb289270b2094c54d3f78b1b975a78df91570d3c0
|
7
|
+
data.tar.gz: a1c85bf0783ffd26e95b69a5b40b038f34aa705f2b1432f86acc15b5688479c34f671121e26e4948ba6e64da686b7ff760bacb4d77099acc9dd353b8dc6eb516
|
data/README.md
CHANGED
@@ -1,12 +1,16 @@
|
|
1
1
|
## Ferver = File-Server
|
2
2
|
|
3
|
-
#### Ferver: A simple web app to
|
3
|
+
#### Ferver: A simple web app to serve files over HTTP packaged as a Ruby gem.
|
4
4
|
|
5
|
-
[![Build Status](https://travis-ci.org/rob-murray/ferver.png?branch=master)](https://travis-ci.org/rob-murray/ferver)
|
5
|
+
[![Build Status](https://travis-ci.org/rob-murray/ferver.png?branch=master)](https://travis-ci.org/rob-murray/ferver)
|
6
|
+
[![Code Climate](https://codeclimate.com/github/rob-murray/ferver.png)](https://codeclimate.com/github/rob-murray/ferver)
|
7
|
+
[![Coverage Status](https://coveralls.io/repos/rob-murray/ferver/badge.png)](https://coveralls.io/r/rob-murray/ferver)
|
8
|
+
[![Dependency Status](https://gemnasium.com/rob-murray/ferver.png)](https://gemnasium.com/rob-murray/ferver)
|
9
|
+
[![Gem Version](https://badge.fury.io/rb/ferver.png)](http://badge.fury.io/rb/ferver)
|
6
10
|
|
7
11
|
### Description
|
8
12
|
|
9
|
-
This is super, simple ruby gem to serve files over **http**, useful as a basic file server to quickly share files on your local network or something. Just install the gem and go!
|
13
|
+
This is super, simple ruby gem to serve files over **http**, useful as a basic file server to quickly share files on your local network or something over the web. Just install the gem and go!
|
10
14
|
|
11
15
|
Here's the spec for **ferver**:
|
12
16
|
|
@@ -19,9 +23,7 @@ Here's the spec for **ferver**:
|
|
19
23
|
|
20
24
|
### Getting started
|
21
25
|
|
22
|
-
Using **ferver** could not be simpler
|
23
|
-
|
24
|
-
Install the **ferver** gem
|
26
|
+
Using **ferver** could not be simpler - just install the **ferver** gem.
|
25
27
|
|
26
28
|
```bash
|
27
29
|
$ gem install ferver
|
@@ -42,7 +44,6 @@ $ ferver
|
|
42
44
|
For exmple, to serve files from **/Users/rob/Projects/ferver/** directory pass the path in as below;
|
43
45
|
|
44
46
|
```bash
|
45
|
-
# Serve files from a specific directory
|
46
47
|
$ ferver /Users/rob/Projects/ferver/
|
47
48
|
````
|
48
49
|
|
@@ -52,11 +53,13 @@ The **ferver** gem uses [Sinatra](http://www.sinatrarb.com/) and runs on default
|
|
52
53
|
|
53
54
|
#### HTML
|
54
55
|
|
55
|
-
|
56
|
+
List available files in your browser.
|
57
|
+
|
58
|
+
`http://localhost:4567/files`
|
56
59
|
|
57
60
|
#### JSON
|
58
61
|
|
59
|
-
|
62
|
+
Requesting content-type `json`, for exampled passing the header `Accept: application/json` will return the list of files as json.
|
60
63
|
|
61
64
|
```bash
|
62
65
|
curl -i -H "Accept: application/json" http://localhost:4567/files
|
@@ -72,6 +75,16 @@ For example to download file appearing third in the list displayed earlier, requ
|
|
72
75
|
|
73
76
|
Please use the GitHub pull-request mechanism to submit contributions.
|
74
77
|
|
78
|
+
After cloning the repo, you can test the application without having to install the gem package by running the `server` Rake task;
|
79
|
+
|
80
|
+
```bash
|
81
|
+
$ rake server
|
82
|
+
|
83
|
+
# or
|
84
|
+
|
85
|
+
$ rake server /path/to/dir
|
86
|
+
```
|
87
|
+
|
75
88
|
### License
|
76
89
|
|
77
90
|
This project is available for use under the MIT software license.
|
data/Rakefile
CHANGED
@@ -5,4 +5,21 @@ require 'rspec/core/rake_task'
|
|
5
5
|
task :default => :spec
|
6
6
|
|
7
7
|
desc "Run all specs in spec directory (excluding plugin specs)"
|
8
|
-
RSpec::Core::RakeTask.new(:spec)
|
8
|
+
RSpec::Core::RakeTask.new(:spec)
|
9
|
+
|
10
|
+
desc "Run ferver locally from source"
|
11
|
+
task :server do |t, args|
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler'
|
15
|
+
Bundler.setup
|
16
|
+
require 'ferver'
|
17
|
+
|
18
|
+
# use the last argument (first is the rake task) as the file path to serve from
|
19
|
+
ferver_path = (ARGV.length == 2 && ARGV.last) || nil
|
20
|
+
Ferver::App.set :ferver_path, ferver_path
|
21
|
+
|
22
|
+
# run!
|
23
|
+
Ferver::App.run!
|
24
|
+
|
25
|
+
end
|
data/bin/ferver
CHANGED
@@ -3,9 +3,11 @@
|
|
3
3
|
require 'sinatra'
|
4
4
|
require 'ferver'
|
5
5
|
|
6
|
+
|
6
7
|
# use the first argument as the file path to serve from
|
7
8
|
ferver_path = (ARGV.length == 1 && ARGV[0]) || nil
|
8
9
|
Ferver::App.set :ferver_path, ferver_path
|
10
|
+
Ferver::App.set :environment, :production
|
9
11
|
|
10
12
|
# run!
|
11
13
|
Ferver::App.run!
|
data/lib/ferver.rb
CHANGED
data/lib/ferver/app.rb
CHANGED
@@ -2,6 +2,7 @@ require "sinatra"
|
|
2
2
|
require "json"
|
3
3
|
require "sinatra/base"
|
4
4
|
require "ferver/file_list"
|
5
|
+
require "ferver/file_id_request"
|
5
6
|
|
6
7
|
module Ferver
|
7
8
|
class App < Sinatra::Base
|
@@ -12,61 +13,48 @@ module Ferver
|
|
12
13
|
|
13
14
|
# By default, serve files from current location when the gem
|
14
15
|
# binary is called.
|
15
|
-
DEFAULT_FILE_SERVER_DIR_PATH =
|
16
|
+
DEFAULT_FILE_SERVER_DIR_PATH = "./"
|
16
17
|
|
17
18
|
# redirect to file list
|
18
19
|
# /
|
19
|
-
get
|
20
|
-
|
21
|
-
redirect to('/files')
|
22
|
-
|
20
|
+
get "/" do
|
21
|
+
redirect to("/files")
|
23
22
|
end
|
24
23
|
|
25
|
-
|
26
24
|
# list files; repond as html or json
|
27
25
|
# /files
|
28
|
-
get
|
29
|
-
|
26
|
+
get "/files" do
|
30
27
|
file_list = @ferver_list.files
|
31
28
|
|
32
29
|
if request.preferred_type.to_s == "application/json"
|
33
|
-
|
34
30
|
content_type :json
|
35
|
-
file_list.to_json
|
36
31
|
|
32
|
+
file_list.to_json
|
37
33
|
else
|
38
|
-
|
39
34
|
@file_count = @ferver_list.file_count
|
40
35
|
@ferver_path = File.expand_path(get_current_ferver_path)
|
41
36
|
@file_list = file_list
|
42
37
|
|
43
38
|
erb :file_list_view
|
44
|
-
|
45
39
|
end
|
46
40
|
|
47
41
|
end
|
48
42
|
|
49
|
-
|
50
43
|
# download file
|
51
44
|
# /files/:id
|
52
|
-
get
|
45
|
+
get "/files/:id" do
|
46
|
+
id_request = Ferver::FileIdRequest.new(params[:id])
|
53
47
|
|
54
|
-
|
48
|
+
halt(400, "Bad request") unless id_request.valid?
|
55
49
|
|
56
|
-
if @ferver_list.file_id_is_valid?(
|
57
|
-
|
58
|
-
file_name = @ferver_list.file_by_id(id)
|
59
|
-
|
50
|
+
if @ferver_list.file_id_is_valid?(id_request.value)
|
51
|
+
file_name = @ferver_list.file_by_id(id_request.value)
|
60
52
|
file = FileList.path_for_file(get_current_ferver_path, file_name)
|
61
53
|
|
62
54
|
send_file(file, :disposition => 'attachment', :filename => File.basename(file))
|
63
|
-
|
64
55
|
else
|
65
|
-
|
66
56
|
status 404
|
67
|
-
|
68
57
|
end
|
69
|
-
|
70
58
|
end
|
71
59
|
|
72
60
|
|
@@ -74,9 +62,12 @@ module Ferver
|
|
74
62
|
# !Called before each request
|
75
63
|
#
|
76
64
|
before do
|
65
|
+
begin
|
66
|
+
@ferver_list = FileList.new(get_current_ferver_path)
|
67
|
+
rescue DirectoryNotFoundError
|
68
|
+
halt(500, "Ferver: Directory '#{get_current_ferver_path}' not found.")
|
69
|
+
end
|
77
70
|
|
78
|
-
@ferver_list = FileList.new(get_current_ferver_path)
|
79
|
-
|
80
71
|
end
|
81
72
|
|
82
73
|
private
|
@@ -86,7 +77,6 @@ module Ferver
|
|
86
77
|
# i.e. `Ferver::App.set :ferver_path, ferver_path` or the default if nil
|
87
78
|
#
|
88
79
|
def get_current_ferver_path
|
89
|
-
|
90
80
|
@current_ferver_path ||= begin
|
91
81
|
path = nil
|
92
82
|
|
@@ -95,8 +85,7 @@ module Ferver
|
|
95
85
|
else
|
96
86
|
path = DEFAULT_FILE_SERVER_DIR_PATH
|
97
87
|
end
|
98
|
-
end
|
99
|
-
|
88
|
+
end
|
100
89
|
end
|
101
90
|
|
102
91
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
module Ferver
|
3
|
+
class FileIdRequest
|
4
|
+
|
5
|
+
attr_reader :value
|
6
|
+
|
7
|
+
def initialize(value = nil)
|
8
|
+
@is_valid = false
|
9
|
+
|
10
|
+
self.value = value
|
11
|
+
end
|
12
|
+
|
13
|
+
def value=(value)
|
14
|
+
id = Integer(value) rescue nil
|
15
|
+
|
16
|
+
if id.nil?
|
17
|
+
@is_valid = false
|
18
|
+
else
|
19
|
+
@value = id
|
20
|
+
@is_valid = true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def valid?
|
25
|
+
@is_valid
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/ferver/file_list.rb
CHANGED
@@ -9,45 +9,35 @@ module Ferver
|
|
9
9
|
# create a new instance with a path
|
10
10
|
#
|
11
11
|
def initialize(path)
|
12
|
-
|
13
12
|
raise ArgumentError, "No path is specified" if path.empty?
|
13
|
+
raise DirectoryNotFoundError unless Dir.exists?(path)
|
14
14
|
|
15
15
|
@file_path = File.expand_path(path)
|
16
|
-
|
17
16
|
find_files
|
18
|
-
|
19
17
|
end
|
20
18
|
|
21
19
|
# Return an absolute path to a `file_name` in the `directory`
|
22
20
|
#
|
23
21
|
def self.path_for_file(directory, file_name)
|
24
|
-
|
25
22
|
File.join(directory, file_name)
|
26
|
-
|
27
23
|
end
|
28
24
|
|
29
25
|
# Is the file id a valid id for Ferver to serve
|
30
26
|
#
|
31
27
|
def file_id_is_valid?(file_id)
|
32
|
-
|
33
28
|
file_id < @files.size
|
34
|
-
|
35
29
|
end
|
36
30
|
|
37
31
|
# Filename by its index
|
38
32
|
#
|
39
33
|
def file_by_id(id)
|
40
|
-
|
41
34
|
@files.fetch(id)
|
42
|
-
|
43
35
|
end
|
44
36
|
|
45
37
|
# Number of files in list
|
46
38
|
#
|
47
39
|
def file_count
|
48
|
-
|
49
40
|
@files.size
|
50
|
-
|
51
41
|
end
|
52
42
|
|
53
43
|
private
|
@@ -55,20 +45,15 @@ module Ferver
|
|
55
45
|
# Iterate through files in specified dir for files
|
56
46
|
#
|
57
47
|
def find_files
|
58
|
-
|
59
48
|
@files = []
|
60
49
|
|
61
50
|
Dir.foreach(@file_path) do |file|
|
62
|
-
|
63
51
|
next if file == '.' or file == '..'
|
64
52
|
|
65
53
|
file_path = FileList.path_for_file(@file_path, file)
|
66
|
-
|
67
54
|
@files << file if File.file?(file_path)
|
68
|
-
|
69
55
|
end
|
70
|
-
|
71
56
|
end
|
72
|
-
|
57
|
+
|
73
58
|
end
|
74
59
|
end
|
data/lib/ferver/version.rb
CHANGED
data/spec/ferver_spec.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe "ferver" do
|
4
4
|
include Webrat::Matchers # allow cool html matching
|
5
5
|
|
6
6
|
|
7
7
|
context "given a request to the server root" do
|
8
8
|
|
9
9
|
before(:each) do
|
10
|
-
get
|
10
|
+
get "/"
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should return redirect" do
|
@@ -35,28 +35,48 @@ describe 'ferver' do
|
|
35
35
|
|
36
36
|
it "will use default directory" do
|
37
37
|
|
38
|
-
Ferver::FileList.expects(:new).with(
|
38
|
+
Ferver::FileList.expects(:new).with("./").returns(@file_list)
|
39
39
|
|
40
|
-
get
|
40
|
+
get "/files"
|
41
41
|
end
|
42
42
|
|
43
43
|
end
|
44
44
|
|
45
45
|
context "when the directory passed via configuration" do
|
46
46
|
|
47
|
-
before { Ferver::App.set :ferver_path,
|
47
|
+
before { Ferver::App.set :ferver_path, "/foo" }
|
48
48
|
|
49
49
|
it "will use directory specified" do
|
50
|
-
Ferver::FileList.expects(:new).with(
|
50
|
+
Ferver::FileList.expects(:new).with("/foo").returns(@file_list)
|
51
51
|
|
52
|
-
get
|
52
|
+
get "/files"
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
context "when directory does not exist" do
|
58
|
+
|
59
|
+
before(:each) { Ferver::App.set :ferver_path, "/foo" }
|
60
|
+
|
61
|
+
it "will attempt to create FileList with path" do
|
62
|
+
Ferver::FileList.expects(:new).with("/foo").raises(Ferver::DirectoryNotFoundError)
|
63
|
+
|
64
|
+
get "/files"
|
65
|
+
end
|
66
|
+
|
67
|
+
it "will return server error status" do
|
68
|
+
Ferver::FileList.stubs(:new).with("/foo").raises(Ferver::DirectoryNotFoundError)
|
69
|
+
|
70
|
+
get "/files"
|
71
|
+
|
72
|
+
last_response.status.should eql 500
|
53
73
|
end
|
54
74
|
|
55
75
|
end
|
56
76
|
|
57
77
|
end
|
58
78
|
|
59
|
-
context
|
79
|
+
context "given an empty list of files" do
|
60
80
|
|
61
81
|
before {
|
62
82
|
file_list = mock()
|
@@ -67,7 +87,7 @@ describe 'ferver' do
|
|
67
87
|
|
68
88
|
context "when no content-type is requested" do
|
69
89
|
|
70
|
-
before { get
|
90
|
+
before { get "/files" }
|
71
91
|
|
72
92
|
it "should return valid response" do
|
73
93
|
expect(last_response).to be_ok
|
@@ -84,12 +104,12 @@ describe 'ferver' do
|
|
84
104
|
context "when json content-type is requested" do
|
85
105
|
|
86
106
|
before {
|
87
|
-
get
|
107
|
+
get "/files", {}, {"HTTP_ACCEPT" => "application/json" }
|
88
108
|
}
|
89
109
|
|
90
110
|
it "should return valid response" do
|
91
111
|
expect(last_response).to be_ok
|
92
|
-
expect(last_response.content_type).to include(
|
112
|
+
expect(last_response.content_type).to include("application/json")
|
93
113
|
end
|
94
114
|
|
95
115
|
it "should contain no file list in response content" do
|
@@ -101,7 +121,7 @@ describe 'ferver' do
|
|
101
121
|
|
102
122
|
end
|
103
123
|
|
104
|
-
context
|
124
|
+
context "given a list of files" do
|
105
125
|
|
106
126
|
before {
|
107
127
|
file_list = mock()
|
@@ -112,7 +132,7 @@ describe 'ferver' do
|
|
112
132
|
|
113
133
|
context "when no content-type is requested" do
|
114
134
|
|
115
|
-
before { get
|
135
|
+
before { get "/files" }
|
116
136
|
|
117
137
|
it "should return valid response" do
|
118
138
|
expect(last_response).to be_ok
|
@@ -138,12 +158,12 @@ describe 'ferver' do
|
|
138
158
|
context "when json content-type is requested" do
|
139
159
|
|
140
160
|
before {
|
141
|
-
get
|
161
|
+
get "/files", {}, {"HTTP_ACCEPT" => "application/json" }
|
142
162
|
}
|
143
163
|
|
144
164
|
it "should return valid response" do
|
145
165
|
expect(last_response).to be_ok
|
146
|
-
expect(last_response.content_type).to include(
|
166
|
+
expect(last_response.content_type).to include("application/json")
|
147
167
|
end
|
148
168
|
|
149
169
|
it "should contain no file list in response content" do
|
@@ -170,7 +190,7 @@ describe 'ferver' do
|
|
170
190
|
|
171
191
|
before {
|
172
192
|
@file_list.expects(:file_id_is_valid?).with(3).returns(false)
|
173
|
-
get
|
193
|
+
get "/files/3"
|
174
194
|
}
|
175
195
|
|
176
196
|
it "should return not_found" do
|
@@ -183,7 +203,7 @@ describe 'ferver' do
|
|
183
203
|
|
184
204
|
before {
|
185
205
|
@file_list.expects(:file_id_is_valid?).never
|
186
|
-
get
|
206
|
+
get "/files/foo"
|
187
207
|
}
|
188
208
|
|
189
209
|
it "should return not_found" do
|
@@ -194,7 +214,7 @@ describe 'ferver' do
|
|
194
214
|
|
195
215
|
context "when requesting a valid file id" do
|
196
216
|
|
197
|
-
before { get
|
217
|
+
before { get "/files/0" }
|
198
218
|
|
199
219
|
xit "should return ok response" do
|
200
220
|
expect(last_response).to be_ok
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ferver::FileIdRequest do
|
4
|
+
|
5
|
+
describe "creating new instance" do
|
6
|
+
|
7
|
+
context "when valid Integer is passed" do
|
8
|
+
|
9
|
+
let(:id_request) { Ferver::FileIdRequest.new(1) }
|
10
|
+
|
11
|
+
it "should create instance" do
|
12
|
+
expect(id_request).not_to be_nil
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should return expected value" do
|
16
|
+
expect(id_request.value).to eq(1)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
context "when nil argument is passed" do
|
22
|
+
|
23
|
+
it "should be invalid" do
|
24
|
+
id_request = Ferver::FileIdRequest.new(nil)
|
25
|
+
expect(id_request.valid?).to be_false
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#value= method" do
|
33
|
+
|
34
|
+
let(:id_request) { Ferver::FileIdRequest.new }
|
35
|
+
|
36
|
+
context "when valid Integer is passed" do
|
37
|
+
|
38
|
+
before { id_request.value = 1 }
|
39
|
+
|
40
|
+
it "should be valid" do
|
41
|
+
expect(id_request.valid?).to be_true
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should return expected value" do
|
45
|
+
expect(id_request.value).to eq(1)
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
context "when valid String as Integer is passed" do
|
51
|
+
|
52
|
+
before { id_request.value = "1" }
|
53
|
+
|
54
|
+
it "should be valid" do
|
55
|
+
expect(id_request.valid?).to be_true
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should return expected value" do
|
59
|
+
expect(id_request.value).to eq(1)
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
context "when a string is passed" do
|
65
|
+
|
66
|
+
before { id_request.value = "foo" }
|
67
|
+
|
68
|
+
it "should be invalid" do
|
69
|
+
expect(id_request.valid?).to be_false
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
context "when an empty string is passed" do
|
75
|
+
|
76
|
+
it "should be invalid" do
|
77
|
+
id_request.value = ""
|
78
|
+
expect(id_request.valid?).to be_false
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
end
|
data/spec/file_list_spec.rb
CHANGED
@@ -2,6 +2,8 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Ferver::FileList do
|
4
4
|
|
5
|
+
before { Dir.stubs(:exists?).returns(true) }
|
6
|
+
|
5
7
|
describe "creating instance" do
|
6
8
|
|
7
9
|
context "when empty path argument is passed" do
|
@@ -12,9 +14,9 @@ describe Ferver::FileList do
|
|
12
14
|
|
13
15
|
end
|
14
16
|
|
15
|
-
context "when path argument is passed" do
|
17
|
+
context "when valid path argument is passed" do
|
16
18
|
|
17
|
-
let(:path) {
|
19
|
+
let(:path) { "/foo" }
|
18
20
|
|
19
21
|
it "should find files in path argument" do
|
20
22
|
Dir.expects(:foreach).with(path).returns(EMPTY_FILE_LIST)
|
@@ -23,11 +25,29 @@ describe Ferver::FileList do
|
|
23
25
|
|
24
26
|
end
|
25
27
|
|
28
|
+
context "when path argument passed does not exist" do
|
29
|
+
|
30
|
+
let(:path) { "/foo" }
|
31
|
+
|
32
|
+
it "should test if directory exists" do
|
33
|
+
Dir.expects(:exists?).with(path).returns(true)
|
34
|
+
Dir.stubs(:foreach).returns(EMPTY_FILE_LIST)
|
35
|
+
|
36
|
+
Ferver::FileList.new(path)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should raise exception" do
|
40
|
+
Dir.stubs(:exists?).returns(false)
|
41
|
+
expect { Ferver::FileList.new(path) }.to raise_error(Ferver::DirectoryNotFoundError)
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
26
46
|
end
|
27
47
|
|
28
48
|
context "when path directory is empty" do
|
29
49
|
|
30
|
-
let(:file_list) { Ferver::FileList.new(
|
50
|
+
let(:file_list) { Ferver::FileList.new("/foo") }
|
31
51
|
|
32
52
|
before { Dir.stubs(:foreach).returns(EMPTY_FILE_LIST) }
|
33
53
|
|
@@ -43,7 +63,7 @@ describe Ferver::FileList do
|
|
43
63
|
|
44
64
|
context "when path directory contains current working dir and parent" do
|
45
65
|
|
46
|
-
let(:file_list) { Ferver::FileList.new(
|
66
|
+
let(:file_list) { Ferver::FileList.new("/foo") }
|
47
67
|
|
48
68
|
before(:each) do
|
49
69
|
Dir.stubs(:foreach).multiple_yields(".", "..", "file1")
|
@@ -62,7 +82,7 @@ describe Ferver::FileList do
|
|
62
82
|
|
63
83
|
context "when path directory contains file and directory" do
|
64
84
|
|
65
|
-
let(:file_list) { Ferver::FileList.new(
|
85
|
+
let(:file_list) { Ferver::FileList.new("/foo") }
|
66
86
|
|
67
87
|
before(:each) do
|
68
88
|
Dir.stubs(:foreach).multiple_yields("file1", "a_directory")
|
@@ -81,7 +101,7 @@ describe Ferver::FileList do
|
|
81
101
|
|
82
102
|
context "when path directory contains valid files" do
|
83
103
|
|
84
|
-
let(:file_list) { Ferver::FileList.new(
|
104
|
+
let(:file_list) { Ferver::FileList.new("/foo") }
|
85
105
|
|
86
106
|
before {
|
87
107
|
Dir.stubs(:foreach).multiple_yields("file1", "file2")
|
@@ -100,7 +120,7 @@ describe Ferver::FileList do
|
|
100
120
|
|
101
121
|
describe "requesting files" do
|
102
122
|
|
103
|
-
let(:file_list) { Ferver::FileList.new(
|
123
|
+
let(:file_list) { Ferver::FileList.new("/foo") }
|
104
124
|
|
105
125
|
before {
|
106
126
|
Dir.stubs(:foreach).multiple_yields("file1", "file2")
|
data/spec/spec_helper.rb
CHANGED
@@ -9,6 +9,7 @@ Coveralls.wear! # this uses SimpleCov under its bonnet
|
|
9
9
|
|
10
10
|
Spork.prefork do
|
11
11
|
require File.join(File.dirname(__FILE__), '..', '/lib/', 'ferver', 'file_list')
|
12
|
+
require File.join(File.dirname(__FILE__), '..', '/lib/', 'ferver', 'file_id_request')
|
12
13
|
require 'ferver'
|
13
14
|
|
14
15
|
require 'rubygems'
|
@@ -18,7 +19,7 @@ Spork.prefork do
|
|
18
19
|
require 'webrat'
|
19
20
|
|
20
21
|
# test environment stuff
|
21
|
-
set :environment, :
|
22
|
+
set :environment, :test
|
22
23
|
set :run, false
|
23
24
|
set :raise_errors, true
|
24
25
|
set :logging, false
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ferver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Murray
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -157,10 +157,11 @@ files:
|
|
157
157
|
- ferver.gemspec
|
158
158
|
- lib/ferver.rb
|
159
159
|
- lib/ferver/app.rb
|
160
|
+
- lib/ferver/file_id_request.rb
|
160
161
|
- lib/ferver/file_list.rb
|
161
162
|
- lib/ferver/version.rb
|
162
|
-
- run.rb
|
163
163
|
- spec/ferver_spec.rb
|
164
|
+
- spec/file_id_request_spec.rb
|
164
165
|
- spec/file_list_spec.rb
|
165
166
|
- spec/spec_helper.rb
|
166
167
|
homepage: https://github.com/rob-murray/ferver
|
@@ -189,5 +190,6 @@ specification_version: 4
|
|
189
190
|
summary: A simple web app to serve files over HTTP.
|
190
191
|
test_files:
|
191
192
|
- spec/ferver_spec.rb
|
193
|
+
- spec/file_id_request_spec.rb
|
192
194
|
- spec/file_list_spec.rb
|
193
195
|
- spec/spec_helper.rb
|
data/run.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler'
|
3
|
-
Bundler.setup
|
4
|
-
require 'ferver'
|
5
|
-
|
6
|
-
def main
|
7
|
-
|
8
|
-
# use the first argument as the file path to serve from
|
9
|
-
ferver_path = (ARGV.length == 1 && ARGV[0]) || nil
|
10
|
-
Ferver::App.set :ferver_path, ferver_path
|
11
|
-
|
12
|
-
# run!
|
13
|
-
Ferver::App.run!
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
|
18
|
-
if __FILE__ == $0
|
19
|
-
main()
|
20
|
-
end
|
21
|
-
|