ferver 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
- 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
-
8
+ it 'should return expected value' do
9
+ expect(subject.value).to eq(1)
10
+ end
30
11
  end
31
12
 
32
- describe "#value= method" do
33
-
34
- let(:id_request) { Ferver::FileIdRequest.new }
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
- 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
17
+ expect(id_request.valid?).to be_falsey
18
+ end
19
+ end
20
+ end
61
21
 
62
- end
22
+ describe '#value= method' do
23
+ subject { Ferver::FileIdRequest.new }
63
24
 
64
- context "when a string is passed" do
25
+ context 'when valid Integer is passed' do
26
+ before { subject.value = 1 }
65
27
 
66
- before { id_request.value = "foo" }
28
+ it 'should be valid' do
29
+ expect(subject.valid?).to be_truthy
30
+ end
67
31
 
68
- it "should be invalid" do
69
- expect(id_request.valid?).to be_false
70
- end
32
+ it 'should return expected value' do
33
+ expect(subject.value).to eq(1)
34
+ end
35
+ end
71
36
 
72
- end
37
+ context 'when valid String as Integer is passed' do
38
+ before { subject.value = '1' }
73
39
 
74
- context "when an empty string is passed" do
40
+ it 'should be valid' do
41
+ expect(subject.valid?).to be_truthy
42
+ end
75
43
 
76
- it "should be invalid" do
77
- id_request.value = ""
78
- expect(id_request.valid?).to be_false
79
- end
44
+ it 'should return expected value' do
45
+ expect(subject.value).to eq(1)
46
+ end
47
+ end
80
48
 
81
- end
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
- end
61
+ expect(subject.valid?).to be_falsey
62
+ end
63
+ end
64
+ end
65
+ end
@@ -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
- before { Dir.stubs(:exists?).returns(true) }
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
- end
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 "when path directory is empty" do
24
+ context 'when path argument passed does not exist' do
25
+ let(:path) { '/foo' }
49
26
 
50
- let(:file_list) { Ferver::FileList.new("/foo") }
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
- before { Dir.stubs(:foreach).returns(EMPTY_FILE_LIST) }
31
+ Ferver::FileList.new(path)
32
+ end
53
33
 
54
- it "should have zero #file_count" do
55
- expect(file_list.file_count).to eq(0)
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
- context "when path directory contains current working dir and parent" do
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
- context "when path directory contains file and directory" do
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
- let(:file_list) { Ferver::FileList.new("/foo") }
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
- before(:each) do
88
- Dir.stubs(:foreach).multiple_yields("file1", "a_directory")
89
- File.expects(:file?).at_most(2).returns(true, false)
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
- it "should not count the directory" do
93
- expect(file_list.file_count).to eq(1)
94
- end
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
- it "should not include the directory" do
97
- expect(file_list.files).to eq(["file1"])
98
- end
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
- context "when path directory contains valid files" do
79
+ it 'should not include the directory' do
80
+ expect(subject.all).to eq(['file1'])
81
+ end
82
+ end
103
83
 
104
- let(:file_list) { Ferver::FileList.new("/foo") }
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
- before {
107
- Dir.stubs(:foreach).multiple_yields("file1", "file2")
108
- File.stubs(:file?).returns(true)
109
- }
91
+ it 'should count all files' do
92
+ expect(subject.size).to eq(2)
93
+ end
110
94
 
111
- it "should count all files" do
112
- expect(file_list.file_count).to eq(2)
113
- end
95
+ it 'should list all files' do
96
+ expect(subject.all).to eq(files)
97
+ end
114
98
 
115
- it "should list all files" do
116
- expect(file_list.files).to eq(["file1", "file2"])
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
- describe "requesting files" do
122
-
123
- let(:file_list) { Ferver::FileList.new("/foo") }
124
-
125
- before {
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
- context "when requesting invalid file_id" do
116
+ context 'when requesting valid file_id' do
117
+ # TODO: possible to redesign this
153
118
 
154
- it "should return false for invalid file_id" do
155
- file_list.file_id_is_valid?(2).should be_false
156
- end
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
- it "should raise_error if file_by_id is called" do
159
- expect { file_list.file_by_id(2) }.to raise_error(IndexError)
160
- end
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
- end
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
- end
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
@@ -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
- Coveralls.wear! # this uses SimpleCov under its bonnet
9
+ CodeClimate::TestReporter.start
10
+ Coveralls.wear!
9
11
 
10
12
  Spork.prefork do
11
- require File.join(File.dirname(__FILE__), '..', '/lib/', 'ferver', 'file_list')
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 'webrat'
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 |conf|
30
- conf.include Rack::Test::Methods
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