-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests and docs for
JSONSkooma::Sources
- Loading branch information
Showing
9 changed files
with
149 additions
and
2 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 |
---|---|---|
|
@@ -8,5 +8,6 @@ gemspec | |
gem "rake", "~> 13.0" | ||
|
||
gem "rspec", "~> 3.0" | ||
gem "webmock" | ||
|
||
gem "standard", "~> 1.35.0" |
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
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,3 @@ | ||
{ | ||
"key": "value" | ||
} |
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 @@ | ||
key: value |
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,37 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
RSpec.describe JSONSkooma::Sources::Local do | ||
subject(:local_source) { described_class.new(base, suffix: suffix) } | ||
|
||
let(:base) { File.expand_path(File.join(__dir__, "..", "..", "fixtures")) } | ||
let(:suffix) { ".json" } | ||
|
||
describe "#call" do | ||
context "when json file exists" do | ||
let(:relative_path) { "key_value" } | ||
|
||
it "returns parsed content of the file" do | ||
expect(local_source.call(relative_path)).to eq({"key" => "value"}) | ||
end | ||
end | ||
|
||
context "when yaml file exists" do | ||
let(:relative_path) { "key_value" } | ||
let(:suffix) { ".yml" } | ||
|
||
it "returns parsed content of the file" do | ||
expect(local_source.call(relative_path)).to eq({"key" => "value"}) | ||
end | ||
end | ||
|
||
context "when file does not exist" do | ||
let(:relative_path) { "non_existent_file" } | ||
|
||
it "raises an error" do | ||
expect { local_source.call(relative_path) }.to raise_error(JSONSkooma::Sources::Error) | ||
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,59 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
RSpec.describe JSONSkooma::Sources::Remote do | ||
subject(:remote_source) { described_class.new(base, suffix: suffix) } | ||
|
||
let(:base) { "http://example.com/" } | ||
let(:suffix) { ".yml" } | ||
let(:relative_path) { "test" } | ||
|
||
describe "#call" do | ||
context "when the remote file exists and is valid yaml" do | ||
before do | ||
stub_request(:get, "#{base}#{relative_path}#{suffix}") | ||
.to_return(body: "---\nkey: value\n") | ||
end | ||
|
||
it "returns the parsed YAML content" do | ||
expect(remote_source.call(relative_path)).to eq({"key" => "value"}) | ||
end | ||
end | ||
|
||
context "when the remote file exists and is valid json" do | ||
let(:suffix) { ".json" } | ||
|
||
before do | ||
stub_request(:get, "#{base}#{relative_path}#{suffix}") | ||
.to_return(body: "{\"key\":\"value\"}") | ||
end | ||
|
||
it "returns the parsed JSON content" do | ||
expect(remote_source.call(relative_path)).to eq({"key" => "value"}) | ||
end | ||
end | ||
|
||
context "when the remote file does not exist" do | ||
before do | ||
stub_request(:get, "#{base}#{relative_path}#{suffix}") | ||
.to_return(status: 404) | ||
end | ||
|
||
it "raises an error" do | ||
expect { remote_source.call(relative_path) }.to raise_error(JSONSkooma::Sources::Error) | ||
end | ||
end | ||
|
||
context "when the remote file is not valid YAML" do | ||
before do | ||
stub_request(:get, "#{base}#{relative_path}#{suffix}") | ||
.to_return(body: "not: valid: yaml:") | ||
end | ||
|
||
it "raises an error" do | ||
expect { remote_source.call(relative_path) }.to raise_error(JSONSkooma::Sources::Error) | ||
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