ferver 1.3.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,138 +1,66 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
+ RSpec.describe Ferver::FileList do
3
+ subject { described_class.new(files) }
2
4
 
3
- describe Ferver::FileList do
4
- let(:file_1) { double('file', name: 'file1') }
5
- let(:file_2) { double('file', name: 'file2') }
5
+ let(:files) { [] }
6
6
 
7
- before { allow(Dir).to receive(:exist?).and_return(true) }
8
- subject { Ferver::FileList.new('/foo') }
9
-
10
- describe 'creating instance' do
11
- context 'when empty path argument is passed' do
12
- it 'should raise exception if no argument passed' do
13
- expect { Ferver::FileList.new }.to raise_error(ArgumentError)
14
- end
7
+ describe "#size" do
8
+ it "is the size of the files available" do
9
+ expect(subject.size).to eq 0
15
10
  end
16
11
 
17
- context 'when valid path argument is passed' do
18
- let(:path) { '/foo' }
19
-
20
- it 'should find files in path argument' do
21
- expect(Dir).to receive(:foreach).with(path).and_return(EMPTY_FILE_LIST)
22
-
23
- Ferver::FileList.new(path)
24
- end
25
- end
26
-
27
- context 'when path argument passed does not exist' do
28
- let(:path) { '/foo' }
29
-
30
- it 'should test if directory exists' do
31
- expect(Dir).to receive(:exist?).with(path).and_return(true)
32
- allow(Dir).to receive(:foreach).with(path).and_return(EMPTY_FILE_LIST)
33
-
34
- Ferver::FileList.new(path)
35
- end
36
-
37
- it 'should raise exception' do
38
- allow(Dir).to receive(:exist?).with(path).and_return(false)
12
+ context "with files" do
13
+ let(:files) { three_files }
39
14
 
40
- expect { Ferver::FileList.new(path) }.to raise_error(Ferver::DirectoryNotFoundError)
15
+ it "is the size of the files available" do
16
+ expect(subject.size).to eq 3
41
17
  end
42
18
  end
43
19
  end
44
20
 
45
- context 'when path directory is empty' do
46
- before { allow(Dir).to receive(:foreach).and_return(EMPTY_FILE_LIST) }
47
-
48
- it 'should have zero #file_count' do
49
- expect(subject.size).to eq(0)
50
- end
51
-
52
- it 'should return empty array of files' do
53
- expect(subject.to_a).to eq(EMPTY_FILE_LIST)
54
- end
55
- end
56
-
57
- context 'when path directory contains current working dir and parent' do
58
- before(:each) do
59
- allow(Dir).to receive(:foreach).and_yield('.').and_yield('.').and_yield(file_1.name)
60
- allow(File).to receive(:file?).and_return(true)
61
- allow(File).to receive(:zero?).and_return(false)
62
- end
63
-
64
- it 'should not count current working dir and parent' do
65
- expect(subject.size).to eq(1)
66
- end
21
+ describe "#each" do
22
+ let(:files) { three_files }
67
23
 
68
- it 'should not include current working dir and parent' do
69
- expect(subject.to_a.first.name).to eq(file_1.name)
24
+ it "responds to each_with_index" do
25
+ expect(subject).to respond_to(:each_with_index)
70
26
  end
71
- end
72
27
 
73
- context 'when path directory contains file and directory' do
74
- before(:each) do
75
- allow(Dir).to receive(:foreach).and_yield(file_1.name).and_yield('a_directory')
76
- allow(File).to receive(:file?).twice.and_return(true, false)
77
- allow(File).to receive(:zero?).twice.and_return(false, true)
78
- end
28
+ it "returns yields files in sorted order" do
29
+ ordered_file_names = %w(file1 file2 file3)
30
+ i = 0
79
31
 
80
- it 'should not count the directory' do
81
- expect(subject.size).to eq(1)
82
- end
83
-
84
- it 'should not include the directory' do
85
- expect(subject.to_a.first.name).to eq(file_1.name)
32
+ subject.each do |actual_file|
33
+ expect(actual_file.name).to eq ordered_file_names[i]
34
+ i += 1
35
+ end
86
36
  end
87
37
  end
88
38
 
89
- context 'when path directory contains valid files' do
90
- before do
91
- allow(Dir).to receive(:foreach).and_yield(file_1.name).and_yield(file_2.name)
92
- allow(File).to receive(:file?).twice.and_return(true)
93
- allow(File).to receive(:zero?).twice.and_return(false)
94
- end
39
+ describe "#file_by_id" do
40
+ context "with a request for a file index within range" do
41
+ let(:files) { three_files }
95
42
 
96
- it 'should count all files' do
97
- expect(subject.size).to eq(2)
43
+ it "returns the file requested in sorted order" do
44
+ expect(subject.file_by_id(0).name).to eq "file1"
45
+ expect(subject.file_by_id(1).name).to eq "file2"
46
+ expect(subject.file_by_id(2).name).to eq "file3"
47
+ end
98
48
  end
99
49
 
100
- describe "ordering" do
101
- let(:file_2) { double('file', name: 'alpha') }
102
- let(:file_1) { double('file', name: 'zeta') }
103
- let(:ordered_files) { [file_2.name, file_1.name] }
104
-
105
- it 'should yield files in order' do
106
- i = 0
107
- subject.each do | file |
108
- expect(file.name).to eq(ordered_files[i])
109
- i += 1
110
- end
50
+ context "with a request for a file index out of range" do
51
+ it "raises file not found error" do
52
+ expect { subject.file_by_id(0) }.to raise_error(Ferver::FileNotFoundError, "File id=0 not found")
111
53
  end
112
54
  end
113
55
  end
114
56
 
115
- describe 'requesting files' do
116
- before(:each) do
117
- allow(Dir).to receive(:foreach).and_yield(file_1.name).and_yield(file_2.name)
118
- allow(File).to receive(:file?).and_return(true)
119
- allow(File).to receive(:zero?).and_return(false)
120
- end
57
+ private
121
58
 
122
- context 'when requesting valid file_id' do
123
- it '#file_by_id should return the correct file for the first file' do
124
- expect(subject.file_by_id(0).name).to eq(file_1.name)
125
- end
126
-
127
- it '#file_by_id should return the correct file for the second file' do
128
- expect(subject.file_by_id(1).name).to eq(file_2.name)
129
- end
130
- end
131
-
132
- context 'when requesting invalid file_id' do
133
- it 'should raise_error if file_by_id is called' do
134
- expect { subject.file_by_id(2) }.to raise_error(IndexError)
135
- end
136
- end
59
+ def three_files
60
+ [
61
+ double("file", name: "file2"),
62
+ double("file", name: "file3"),
63
+ double("file", name: "file1")
64
+ ]
137
65
  end
138
66
  end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+ RSpec.describe Ferver::FoundFile do
3
+ subject { described_class.new("/dir", "file") }
4
+
5
+ describe "#name" do
6
+ it "is the file name" do
7
+ expect(subject.name).to eq "file"
8
+ end
9
+ end
10
+
11
+ describe "#path_to_file" do
12
+ it "is the full path to file" do
13
+ expect(subject.path_to_file).to eq "/dir/file"
14
+ end
15
+ end
16
+
17
+ describe "#valid?" do
18
+ context "when file exists" do
19
+ before do
20
+ allow(File).to receive(:file?).and_return true
21
+ end
22
+
23
+ context "when file is not empty" do
24
+ before do
25
+ allow(File).to receive(:zero?).and_return false
26
+ end
27
+
28
+ it "is valid" do
29
+ expect(subject).to be_valid
30
+ end
31
+ end
32
+
33
+ context "when file is empty" do
34
+ before do
35
+ allow(File).to receive(:zero?).and_return true
36
+ end
37
+
38
+ it "is not valid" do
39
+ expect(subject).not_to be_valid
40
+ end
41
+ end
42
+ end
43
+
44
+ context "when file does not exist" do
45
+ before do
46
+ allow(File).to receive(:file?).and_return false
47
+ end
48
+
49
+ it "is not valid" do
50
+ expect(subject).not_to be_valid
51
+ end
52
+ end
53
+ end
54
+ end
@@ -1,41 +1,56 @@
1
- require 'rubygems'
2
- require 'spork'
3
- require 'coveralls'
4
- require 'codeclimate-test-reporter'
1
+ # frozen_string_literal: true
2
+ require "rubygems"
3
+ require "coveralls"
4
+ require "simplecov"
5
+
6
+ # Loading more in this block will cause your tests to run faster. However,
7
+ # if you change any configuration or code from libraries loaded here, you'll
8
+ # need to restart spork for it take effect.
9
+ require File.join(File.dirname(__FILE__), "..", "/lib/", "ferver")
10
+ require "ferver"
11
+ require "rubygems"
12
+ require "sinatra"
13
+ require "rack/test"
14
+ require "rspec-html-matchers"
15
+ require "byebug"
5
16
 
6
17
  # force the environment to 'test'
7
- ENV['RACK_ENV'] = 'test'
18
+ ENV["RACK_ENV"] = "test"
8
19
 
9
- CodeClimate::TestReporter.start
20
+ SimpleCov.start
10
21
  Coveralls.wear!
11
22
 
12
- Spork.prefork do
13
- require File.join(File.dirname(__FILE__), '..', '/lib/', 'ferver')
14
- require 'ferver'
15
-
16
- require 'rubygems'
17
- require 'sinatra'
18
- require 'rspec'
19
- require 'rack/test'
20
- require 'rspec-html-matchers'
23
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
24
+ RSpec.configure do |config|
25
+ config.expect_with :rspec do |expectations|
26
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
27
+ end
21
28
 
22
- # test environment stuff
23
- set :environment, :test
24
- set :run, false
25
- set :raise_errors, true
26
- set :logging, false
29
+ config.mock_with :rspec do |mocks|
30
+ mocks.verify_partial_doubles = true
31
+ end
27
32
 
28
- EMPTY_FILE_LIST = []
33
+ config.shared_context_metadata_behavior = :apply_to_host_groups
34
+ config.filter_run_when_matching :focus
35
+ config.disable_monkey_patching!
36
+ config.warnings = true
37
+ config.default_formatter = "doc" if config.files_to_run.one?
29
38
 
30
- RSpec.configure do |config|
31
- config.include Rack::Test::Methods
32
- config.include RSpecHtmlMatchers
33
- end
39
+ config.order = :random
40
+ Kernel.srand config.seed
34
41
 
35
- def app
36
- @app ||= Ferver::App
37
- end
42
+ config.include Rack::Test::Methods
43
+ config.include RSpecHtmlMatchers
38
44
  end
39
45
 
40
- Spork.each_run do
46
+ # test environment stuff
47
+ set :environment, :test
48
+ set :run, false
49
+ set :raise_errors, true
50
+ set :logging, false
51
+
52
+ EMPTY_FILE_LIST = [].freeze
53
+
54
+ def app
55
+ @app ||= Ferver::App
41
56
  end
metadata CHANGED
@@ -1,41 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ferver
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Murray
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-24 00:00:00.000000000 Z
11
+ date: 2017-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - "~>"
18
32
  - !ruby/object:Gem::Version
19
- version: '1.5'
33
+ version: 1.6.0
20
34
  type: :development
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
38
  - - "~>"
25
39
  - !ruby/object:Gem::Version
26
- version: '1.5'
40
+ version: 1.6.0
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
- - - "~>"
45
+ - - ">="
32
46
  - !ruby/object:Gem::Version
33
47
  version: '0'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - "~>"
52
+ - - ">="
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
41
55
  - !ruby/object:Gem::Dependency
@@ -67,49 +81,49 @@ dependencies:
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0.6'
69
83
  - !ruby/object:Gem::Dependency
70
- name: spork
84
+ name: rspec-html-matchers
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: '0.9'
89
+ version: '0.6'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: '0.9'
96
+ version: '0.6'
83
97
  - !ruby/object:Gem::Dependency
84
- name: rspec-html-matchers
98
+ name: coveralls
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: '0.6'
103
+ version: '0.7'
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
108
  - - "~>"
95
109
  - !ruby/object:Gem::Version
96
- version: '0.6'
110
+ version: '0.7'
97
111
  - !ruby/object:Gem::Dependency
98
- name: coveralls
112
+ name: codeclimate-test-reporter
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
- - - "~>"
115
+ - - ">="
102
116
  - !ruby/object:Gem::Version
103
- version: '0.7'
117
+ version: '0'
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
- - - "~>"
122
+ - - ">="
109
123
  - !ruby/object:Gem::Version
110
- version: '0.7'
124
+ version: '0'
111
125
  - !ruby/object:Gem::Dependency
112
- name: codeclimate-test-reporter
126
+ name: byebug
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
129
  - - ">="
@@ -147,6 +161,7 @@ extra_rdoc_files: []
147
161
  files:
148
162
  - ".gitignore"
149
163
  - ".rspec"
164
+ - ".rubocop.yml"
150
165
  - ".ruby-version"
151
166
  - ".travis.yml"
152
167
  - CHANGELOG.md
@@ -160,16 +175,17 @@ files:
160
175
  - lib/ferver/app.rb
161
176
  - lib/ferver/configuration.rb
162
177
  - lib/ferver/controller.rb
163
- - lib/ferver/directory_not_found_error.rb
164
- - lib/ferver/file_id_request.rb
178
+ - lib/ferver/errors.rb
179
+ - lib/ferver/ferver_directory.rb
165
180
  - lib/ferver/file_list.rb
166
181
  - lib/ferver/found_file.rb
167
182
  - lib/ferver/version.rb
168
183
  - lib/ferver/views/index.erb
169
184
  - spec/configuration_spec.rb
185
+ - spec/ferver_directory_spec.rb
170
186
  - spec/ferver_spec.rb
171
- - spec/file_id_request_spec.rb
172
187
  - spec/file_list_spec.rb
188
+ - spec/found_file_spec.rb
173
189
  - spec/spec_helper.rb
174
190
  homepage: https://github.com/rob-murray/ferver
175
191
  licenses:
@@ -183,7 +199,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
183
199
  requirements:
184
200
  - - ">="
185
201
  - !ruby/object:Gem::Version
186
- version: 1.9.3
202
+ version: 2.0.0
187
203
  required_rubygems_version: !ruby/object:Gem::Requirement
188
204
  requirements:
189
205
  - - ">="
@@ -191,13 +207,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
191
207
  version: '0'
192
208
  requirements: []
193
209
  rubyforge_project:
194
- rubygems_version: 2.4.8
210
+ rubygems_version: 2.6.8
195
211
  signing_key:
196
212
  specification_version: 4
197
213
  summary: A simple web app to serve files over HTTP.
198
214
  test_files:
199
215
  - spec/configuration_spec.rb
216
+ - spec/ferver_directory_spec.rb
200
217
  - spec/ferver_spec.rb
201
- - spec/file_id_request_spec.rb
202
218
  - spec/file_list_spec.rb
219
+ - spec/found_file_spec.rb
203
220
  - spec/spec_helper.rb