ferver 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +6 -1
- data/README.md +18 -10
- data/Rakefile +19 -17
- data/bin/ferver +19 -4
- data/ferver.gemspec +19 -19
- data/lib/ferver.rb +24 -2
- data/lib/ferver/app.rb +38 -97
- data/lib/ferver/configuration.rb +11 -0
- data/lib/ferver/directory_not_found_error.rb +4 -0
- data/lib/ferver/file_id_request.rb +28 -19
- data/lib/ferver/file_list.rb +48 -46
- data/lib/ferver/version.rb +1 -1
- data/lib/ferver/views/index.erb +28 -0
- data/spec/configuration_spec.rb +24 -0
- data/spec/ferver_spec.rb +132 -180
- data/spec/file_id_request_spec.rb +46 -67
- data/spec/file_list_spec.rb +107 -128
- data/spec/spec_helper.rb +10 -10
- metadata +49 -44
@@ -1,86 +1,65 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Ferver::FileIdRequest do
|
4
|
+
describe 'creating new instance' do
|
5
|
+
context 'when valid Integer is passed' do
|
6
|
+
subject { Ferver::FileIdRequest.new(1) }
|
4
7
|
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
-
|
8
|
+
it 'should return expected value' do
|
9
|
+
expect(subject.value).to eq(1)
|
10
|
+
end
|
30
11
|
end
|
31
12
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
context "when valid Integer is passed" do
|
13
|
+
context 'when nil argument is passed' do
|
14
|
+
it 'should be invalid' do
|
15
|
+
id_request = Ferver::FileIdRequest.new(nil)
|
37
16
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
17
|
+
expect(id_request.valid?).to be_falsey
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
61
21
|
|
62
|
-
|
22
|
+
describe '#value= method' do
|
23
|
+
subject { Ferver::FileIdRequest.new }
|
63
24
|
|
64
|
-
|
25
|
+
context 'when valid Integer is passed' do
|
26
|
+
before { subject.value = 1 }
|
65
27
|
|
66
|
-
|
28
|
+
it 'should be valid' do
|
29
|
+
expect(subject.valid?).to be_truthy
|
30
|
+
end
|
67
31
|
|
68
|
-
|
69
|
-
|
70
|
-
|
32
|
+
it 'should return expected value' do
|
33
|
+
expect(subject.value).to eq(1)
|
34
|
+
end
|
35
|
+
end
|
71
36
|
|
72
|
-
|
37
|
+
context 'when valid String as Integer is passed' do
|
38
|
+
before { subject.value = '1' }
|
73
39
|
|
74
|
-
|
40
|
+
it 'should be valid' do
|
41
|
+
expect(subject.valid?).to be_truthy
|
42
|
+
end
|
75
43
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
44
|
+
it 'should return expected value' do
|
45
|
+
expect(subject.value).to eq(1)
|
46
|
+
end
|
47
|
+
end
|
80
48
|
|
81
|
-
|
49
|
+
context 'when a string is passed' do
|
50
|
+
before { subject.value = 'foo' }
|
82
51
|
|
52
|
+
it 'should be invalid' do
|
53
|
+
expect(subject.valid?).to be_falsey
|
54
|
+
end
|
83
55
|
end
|
84
56
|
|
57
|
+
context 'when an empty string is passed' do
|
58
|
+
it 'should be invalid' do
|
59
|
+
subject.value = ''
|
85
60
|
|
86
|
-
|
61
|
+
expect(subject.valid?).to be_falsey
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/spec/file_list_spec.rb
CHANGED
@@ -1,167 +1,146 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Ferver::FileList do
|
4
|
+
before { allow(Dir).to receive(:exist?).and_return(true) }
|
5
|
+
subject { Ferver::FileList.new('/foo') }
|
6
|
+
|
7
|
+
describe 'creating instance' do
|
8
|
+
context 'when empty path argument is passed' do
|
9
|
+
it 'should raise exception if no argument passed' do
|
10
|
+
expect { Ferver::FileList.new }.to raise_error(ArgumentError)
|
11
|
+
end
|
12
|
+
end
|
4
13
|
|
5
|
-
|
6
|
-
|
7
|
-
describe "creating instance" do
|
8
|
-
|
9
|
-
context "when empty path argument is passed" do
|
10
|
-
|
11
|
-
it "should raise exception if no argument passed" do
|
12
|
-
expect { Ferver::FileList.new }.to raise_error(ArgumentError)
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
context "when valid path argument is passed" do
|
18
|
-
|
19
|
-
let(:path) { "/foo" }
|
20
|
-
|
21
|
-
it "should find files in path argument" do
|
22
|
-
Dir.expects(:foreach).with(path).returns(EMPTY_FILE_LIST)
|
23
|
-
Ferver::FileList.new(path)
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
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
|
14
|
+
context 'when valid path argument is passed' do
|
15
|
+
let(:path) { '/foo' }
|
43
16
|
|
44
|
-
|
17
|
+
it 'should find files in path argument' do
|
18
|
+
expect(Dir).to receive(:foreach).with(path).and_return(EMPTY_FILE_LIST)
|
45
19
|
|
20
|
+
Ferver::FileList.new(path)
|
21
|
+
end
|
46
22
|
end
|
47
23
|
|
48
|
-
context
|
24
|
+
context 'when path argument passed does not exist' do
|
25
|
+
let(:path) { '/foo' }
|
49
26
|
|
50
|
-
|
27
|
+
it 'should test if directory exists' do
|
28
|
+
expect(Dir).to receive(:exist?).with(path).and_return(true)
|
29
|
+
allow(Dir).to receive(:foreach).with(path).and_return(EMPTY_FILE_LIST)
|
51
30
|
|
52
|
-
|
31
|
+
Ferver::FileList.new(path)
|
32
|
+
end
|
53
33
|
|
54
|
-
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should return empty array of files" do
|
59
|
-
expect(file_list.files).to eq(EMPTY_FILE_LIST)
|
60
|
-
end
|
34
|
+
it 'should raise exception' do
|
35
|
+
allow(Dir).to receive(:exist?).with(path).and_return(false)
|
61
36
|
|
37
|
+
expect { Ferver::FileList.new(path) }.to raise_error(Ferver::DirectoryNotFoundError)
|
38
|
+
end
|
62
39
|
end
|
40
|
+
end
|
63
41
|
|
64
|
-
|
65
|
-
|
66
|
-
let(:file_list) { Ferver::FileList.new("/foo") }
|
67
|
-
|
68
|
-
before(:each) do
|
69
|
-
Dir.stubs(:foreach).multiple_yields(".", "..", "file1")
|
70
|
-
File.stubs(:file?).returns(true)
|
71
|
-
end
|
72
|
-
|
73
|
-
it "should not count current working dir and parent" do
|
74
|
-
expect(file_list.file_count).to eq(1)
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should not include current working dir and parent" do
|
78
|
-
expect(file_list.files).to eq(["file1"])
|
79
|
-
end
|
42
|
+
context 'when path directory is empty' do
|
43
|
+
before { allow(Dir).to receive(:foreach).and_return(EMPTY_FILE_LIST) }
|
80
44
|
|
45
|
+
it 'should have zero #file_count' do
|
46
|
+
expect(subject.size).to eq(0)
|
81
47
|
end
|
82
48
|
|
83
|
-
|
49
|
+
it 'should return empty array of files' do
|
50
|
+
expect(subject.all).to eq(EMPTY_FILE_LIST)
|
51
|
+
end
|
52
|
+
end
|
84
53
|
|
85
|
-
|
54
|
+
context 'when path directory contains current working dir and parent' do
|
55
|
+
before(:each) do
|
56
|
+
allow(Dir).to receive(:foreach).and_yield('.').and_yield('.').and_yield('file1')
|
57
|
+
allow(File).to receive(:file?).and_return(true)
|
58
|
+
end
|
86
59
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
end
|
60
|
+
it 'should not count current working dir and parent' do
|
61
|
+
expect(subject.size).to eq(1)
|
62
|
+
end
|
91
63
|
|
92
|
-
|
93
|
-
|
94
|
-
|
64
|
+
it 'should not include current working dir and parent' do
|
65
|
+
expect(subject.all).to eq(['file1'])
|
66
|
+
end
|
67
|
+
end
|
95
68
|
|
96
|
-
|
97
|
-
|
98
|
-
|
69
|
+
context 'when path directory contains file and directory' do
|
70
|
+
before(:each) do
|
71
|
+
allow(Dir).to receive(:foreach).and_yield('file1').and_yield('a_directory')
|
72
|
+
allow(File).to receive(:file?).twice.and_return(true, false)
|
73
|
+
end
|
99
74
|
|
75
|
+
it 'should not count the directory' do
|
76
|
+
expect(subject.size).to eq(1)
|
100
77
|
end
|
101
78
|
|
102
|
-
|
79
|
+
it 'should not include the directory' do
|
80
|
+
expect(subject.all).to eq(['file1'])
|
81
|
+
end
|
82
|
+
end
|
103
83
|
|
104
|
-
|
84
|
+
context 'when path directory contains valid files' do
|
85
|
+
let(:files) { %w(file1 file2) }
|
86
|
+
before do
|
87
|
+
allow(Dir).to receive(:foreach).and_yield(files[0]).and_yield(files[1])
|
88
|
+
allow(File).to receive(:file?).twice.and_return(true)
|
89
|
+
end
|
105
90
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
}
|
91
|
+
it 'should count all files' do
|
92
|
+
expect(subject.size).to eq(2)
|
93
|
+
end
|
110
94
|
|
111
|
-
|
112
|
-
|
113
|
-
|
95
|
+
it 'should list all files' do
|
96
|
+
expect(subject.all).to eq(files)
|
97
|
+
end
|
114
98
|
|
115
|
-
|
116
|
-
|
99
|
+
describe 'iterating over files list' do
|
100
|
+
it 'should yield files in order' do
|
101
|
+
i = 0
|
102
|
+
subject.each do | file |
|
103
|
+
expect(file).to eq(files[i])
|
104
|
+
i += 1
|
117
105
|
end
|
118
|
-
|
106
|
+
end
|
119
107
|
end
|
108
|
+
end
|
120
109
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
Dir.stubs(:foreach).multiple_yields("file1", "file2")
|
127
|
-
File.stubs(:file?).returns(true)
|
128
|
-
}
|
129
|
-
|
130
|
-
context "when requesting valid file_id" do
|
131
|
-
|
132
|
-
#todo: poss to redesign this
|
133
|
-
|
134
|
-
it "#file_id_is_valid? should return true for first file" do
|
135
|
-
file_list.file_id_is_valid?(0).should be_true
|
136
|
-
end
|
137
|
-
|
138
|
-
it "#file_id_is_valid? should return true for second file" do
|
139
|
-
file_list.file_id_is_valid?(1).should be_true
|
140
|
-
end
|
141
|
-
|
142
|
-
it "#file_by_id should return the correct file for the first file" do
|
143
|
-
expect(file_list.file_by_id(0)).to eq("file1")
|
144
|
-
end
|
145
|
-
|
146
|
-
it "#file_by_id should return the correct file for the second file" do
|
147
|
-
expect(file_list.file_by_id(1)).to eq("file2")
|
148
|
-
end
|
149
|
-
|
150
|
-
end
|
110
|
+
describe 'requesting files' do
|
111
|
+
before(:each) do
|
112
|
+
allow(Dir).to receive(:foreach).and_yield('file1').and_yield('file2')
|
113
|
+
allow(File).to receive(:file?).and_return(true)
|
114
|
+
end
|
151
115
|
|
152
|
-
|
116
|
+
context 'when requesting valid file_id' do
|
117
|
+
# TODO: possible to redesign this
|
153
118
|
|
154
|
-
|
155
|
-
|
156
|
-
|
119
|
+
it '#file_id_is_valid? should return true for first file' do
|
120
|
+
expect(subject.file_id_is_valid?(0)).to be_truthy
|
121
|
+
end
|
157
122
|
|
158
|
-
|
159
|
-
|
160
|
-
|
123
|
+
it '#file_id_is_valid? should return true for second file' do
|
124
|
+
expect(subject.file_id_is_valid?(1)).to be_truthy
|
125
|
+
end
|
161
126
|
|
162
|
-
|
127
|
+
it '#file_by_id should return the correct file for the first file' do
|
128
|
+
expect(subject.file_by_id(0)).to eq('file1')
|
129
|
+
end
|
163
130
|
|
131
|
+
it '#file_by_id should return the correct file for the second file' do
|
132
|
+
expect(subject.file_by_id(1)).to eq('file2')
|
133
|
+
end
|
164
134
|
end
|
165
135
|
|
136
|
+
context 'when requesting invalid file_id' do
|
137
|
+
it 'should return false for invalid file_id' do
|
138
|
+
expect(subject.file_id_is_valid?(2)).to be_falsey
|
139
|
+
end
|
166
140
|
|
167
|
-
|
141
|
+
it 'should raise_error if file_by_id is called' do
|
142
|
+
expect { subject.file_by_id(2) }.to raise_error(IndexError)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,23 +1,24 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'spork'
|
3
3
|
require 'coveralls'
|
4
|
+
require 'codeclimate-test-reporter'
|
4
5
|
|
5
6
|
# force the environment to 'test'
|
6
|
-
ENV['RACK_ENV'] = 'test'
|
7
|
+
ENV['RACK_ENV'] = 'test'
|
7
8
|
|
8
|
-
|
9
|
+
CodeClimate::TestReporter.start
|
10
|
+
Coveralls.wear!
|
9
11
|
|
10
12
|
Spork.prefork do
|
11
|
-
require File.join(File.dirname(__FILE__), '..', '/lib/', 'ferver'
|
12
|
-
require File.join(File.dirname(__FILE__), '..', '/lib/', 'ferver', 'file_id_request')
|
13
|
+
require File.join(File.dirname(__FILE__), '..', '/lib/', 'ferver')
|
13
14
|
require 'ferver'
|
14
15
|
|
15
16
|
require 'rubygems'
|
16
17
|
require 'sinatra'
|
17
18
|
require 'rspec'
|
18
19
|
require 'rack/test'
|
19
|
-
require '
|
20
|
-
|
20
|
+
require 'rspec-html-matchers'
|
21
|
+
|
21
22
|
# test environment stuff
|
22
23
|
set :environment, :test
|
23
24
|
set :run, false
|
@@ -26,9 +27,8 @@ Spork.prefork do
|
|
26
27
|
|
27
28
|
EMPTY_FILE_LIST = []
|
28
29
|
|
29
|
-
RSpec.configure do |
|
30
|
-
|
31
|
-
conf.mock_framework = :mocha
|
30
|
+
RSpec.configure do |config|
|
31
|
+
config.include Rack::Test::Methods
|
32
32
|
end
|
33
33
|
|
34
34
|
def app
|
@@ -37,4 +37,4 @@ Spork.prefork do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
Spork.each_run do
|
40
|
-
end
|
40
|
+
end
|