Skip to content

Commit 8f291c9

Browse files
committed
Added tests for source and destination factories.
1 parent 060425c commit 8f291c9

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed

spec/support/factories.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77

88
require_relative 'factories/config/destination_factory'
99
require_relative 'factories/config/source_factory'
10+
require_relative 'factories/destination/one_drive_factory'
1011
require_relative 'factories/service/one_drive_factory'
1112
require_relative 'factories/source/url_factory'
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../../../../lib/destination/one_drive'
4+
5+
FactoryBot.define do
6+
factory :destination_one_drive, class: DocumentTransfer::Destination::OneDrive do
7+
transient do
8+
config { build(:config_destination, type: :onedrive, path: 'rspec-docs') }
9+
end
10+
11+
initialize_with { new(config) }
12+
end
13+
end
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../../../lib/destination'
4+
5+
RSpec.describe DocumentTransfer::Destination do
6+
describe '.load' do
7+
let(:config) { build(:config_destination, type: destination_type) }
8+
let(:destination) { build(:destination_one_drive) }
9+
let(:destination_type) { :onedrive }
10+
11+
before do
12+
allow(destination.class).to receive(:new).and_return(destination)
13+
end
14+
15+
it 'returns the proper destination' do
16+
expect(described_class.load(config)).to eq(destination)
17+
end
18+
19+
context 'when an invalid destination type is provided' do
20+
before do
21+
# If we try to set an invalid type directly on the config object, it
22+
# will raise an error.
23+
allow(config).to receive(:type).and_return(:invalid)
24+
end
25+
26+
it 'raises an exception' do
27+
expect { described_class.load(config) }.to \
28+
raise_error(DocumentTransfer::Destination::InvalidDestinationError)
29+
end
30+
end
31+
end
32+
end
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../../../lib/source'
4+
5+
RSpec.describe DocumentTransfer::Source do
6+
describe '.load' do
7+
let(:config) { build(:config_source, type: source_type) }
8+
let(:source) { build(:source_url) }
9+
let(:source_type) { :url }
10+
11+
before do
12+
allow(source.class).to receive(:new).and_return(source)
13+
end
14+
15+
it 'returns the proper source' do
16+
expect(described_class.load(config)).to eq(source)
17+
end
18+
19+
context 'when an invalid source type is provided' do
20+
before do
21+
# If we try to set an invalid type directly on the config object, it
22+
# will raise an error.
23+
allow(config).to receive(:type).and_return(:invalid)
24+
end
25+
26+
it 'raises an exception' do
27+
expect { described_class.load(config) }.to \
28+
raise_error(DocumentTransfer::Source::InvalidSourceError)
29+
end
30+
end
31+
end
32+
end

0 commit comments

Comments
 (0)