Skip to content

Commit a3b591f

Browse files
committed
refactor(data-extractor): split lib tests
1 parent 782d447 commit a3b591f

File tree

2 files changed

+47
-24
lines changed

2 files changed

+47
-24
lines changed

spec/lib/file_handler_spec.rb

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,30 @@
33
require 'spec_helper'
44
require 'file_handler'
55

6-
describe FileHandler do
6+
describe 'FileHandler - Validations' do
77
let(:basic_log_path) { 'spec/fixtures/basic.log' }
8+
let(:complex_log_path) { 'spec/fixtures/webserver.log' }
89
subject(:options) { { file_path: log_path } }
9-
subject(:call_scope) { described_class.new(options).call }
10+
subject(:call_scope) { FileHandler.new(options).call }
1011
subject(:result) { call_scope }
1112

12-
context 'data collect' do
13+
context 'with a simple file' do
1314
let(:log_path) { basic_log_path }
1415
subject(:result_first) { result['/help_page/1'] }
1516

16-
it 'count hits and uniques' do
17+
it 'collect data' do
1718
expect(result_first[:hits]).to eq 3
1819
expect(result_first[:uniques]).to eq 1
1920
end
2021
end
2122

22-
context 'validations' do
23-
let(:log_path) { '' }
24-
subject(:first_error) { result[:errors][0] }
23+
context 'with a complex file' do
24+
let(:log_path) { complex_log_path }
25+
subject(:result_home) { result['/home'] }
2526

26-
it 'no filepath' do
27-
expect(first_error[:message]).to eq 'Please provide a file to be analysed.'
28-
end
29-
30-
it 'empty file' do
31-
options[:file_path] = 'spec/fixtures/empty.log'
32-
expect(first_error[:message]).to eq 'File is empty.'
33-
end
34-
35-
it 'empty lines' do
36-
options[:file_path] = 'spec/fixtures/with-empty-lines.log'
37-
expect(first_error[:message]).to eq 'File have empty lines.'
38-
end
39-
40-
it 'malformed lines' do
41-
options[:file_path] = 'spec/fixtures/malformed-lines.log'
42-
expect(first_error[:message]).to eq 'File have malformed lines.'
27+
it 'collect data' do
28+
expect(result_home[:hits]).to eq 78
29+
expect(result_home[:uniques]).to eq 23
4330
end
4431
end
4532
end
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
require 'file_handler'
5+
6+
# A extension of file handler spec that handle error scenarios
7+
describe FileHandler do
8+
let(:basic_log_path) { 'spec/fixtures/basic.log' }
9+
subject(:options) { { file_path: log_path } }
10+
subject(:call_scope) { described_class.new(options).call }
11+
subject(:result) { call_scope }
12+
13+
context 'validations' do
14+
let(:log_path) { '' }
15+
subject(:first_error) { result[:errors][0] }
16+
17+
it 'no filepath' do
18+
expect(first_error[:message]).to eq 'Please provide a file to be analysed.'
19+
end
20+
21+
it 'empty file' do
22+
options[:file_path] = 'spec/fixtures/empty.log'
23+
expect(first_error[:message]).to eq 'File is empty.'
24+
end
25+
26+
it 'empty lines' do
27+
options[:file_path] = 'spec/fixtures/with-empty-lines.log'
28+
expect(first_error[:message]).to eq 'File have empty lines.'
29+
end
30+
31+
it 'malformed lines' do
32+
options[:file_path] = 'spec/fixtures/malformed-lines.log'
33+
expect(first_error[:message]).to eq 'File have malformed lines.'
34+
end
35+
end
36+
end

0 commit comments

Comments
 (0)