-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for source and destination factories.
- Loading branch information
1 parent
060425c
commit 8f291c9
Showing
4 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../../../../lib/destination/one_drive' | ||
|
||
FactoryBot.define do | ||
factory :destination_one_drive, class: DocumentTransfer::Destination::OneDrive do | ||
transient do | ||
config { build(:config_destination, type: :onedrive, path: 'rspec-docs') } | ||
end | ||
|
||
initialize_with { new(config) } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../../../lib/destination' | ||
|
||
RSpec.describe DocumentTransfer::Destination do | ||
describe '.load' do | ||
let(:config) { build(:config_destination, type: destination_type) } | ||
let(:destination) { build(:destination_one_drive) } | ||
let(:destination_type) { :onedrive } | ||
|
||
before do | ||
allow(destination.class).to receive(:new).and_return(destination) | ||
end | ||
|
||
it 'returns the proper destination' do | ||
expect(described_class.load(config)).to eq(destination) | ||
end | ||
|
||
context 'when an invalid destination type is provided' do | ||
before do | ||
# If we try to set an invalid type directly on the config object, it | ||
# will raise an error. | ||
allow(config).to receive(:type).and_return(:invalid) | ||
end | ||
|
||
it 'raises an exception' do | ||
expect { described_class.load(config) }.to \ | ||
raise_error(DocumentTransfer::Destination::InvalidDestinationError) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../../../lib/source' | ||
|
||
RSpec.describe DocumentTransfer::Source do | ||
describe '.load' do | ||
let(:config) { build(:config_source, type: source_type) } | ||
let(:source) { build(:source_url) } | ||
let(:source_type) { :url } | ||
|
||
before do | ||
allow(source.class).to receive(:new).and_return(source) | ||
end | ||
|
||
it 'returns the proper source' do | ||
expect(described_class.load(config)).to eq(source) | ||
end | ||
|
||
context 'when an invalid source type is provided' do | ||
before do | ||
# If we try to set an invalid type directly on the config object, it | ||
# will raise an error. | ||
allow(config).to receive(:type).and_return(:invalid) | ||
end | ||
|
||
it 'raises an exception' do | ||
expect { described_class.load(config) }.to \ | ||
raise_error(DocumentTransfer::Source::InvalidSourceError) | ||
end | ||
end | ||
end | ||
end |