forked from pact-foundation/pact-mock_service
-
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.
feat(stub-server): allow pacts to be loaded from a directory
Closes: pact-foundation#94
- Loading branch information
Showing
3 changed files
with
97 additions
and
7 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,26 @@ | ||
module Pact | ||
module Support | ||
module ExpandFileList | ||
def self.call pact_files | ||
pact_files | ||
.collect{ |path| unixify_path(path) } | ||
.collect{ | path | expand_path(path) } | ||
.flatten | ||
end | ||
|
||
def self.unixify_path(path) | ||
path.gsub(/\\+/, '/') | ||
end | ||
|
||
def self.expand_path(path) | ||
if File.directory?(path) | ||
Dir.glob(File.join(path, "*.json")) | ||
elsif Dir.glob(path).any? | ||
Dir.glob(path) | ||
else | ||
path | ||
end | ||
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,54 @@ | ||
require 'pact/support/expand_file_list' | ||
|
||
module Pact | ||
module Support | ||
module ExpandFileList | ||
describe "#call" do | ||
|
||
subject { ExpandFileList.call(file_list) } | ||
|
||
context "with a list of json files" do | ||
let(:file_list) { ["file1.json", "file2.json"] } | ||
|
||
it "returns the list" do | ||
expect(subject).to eq file_list | ||
end | ||
end | ||
|
||
context "with a list of json files that contains a windows path" do | ||
let(:file_list) { ["c:\\foo\\file1.json"] } | ||
|
||
it "returns the list in Unix format" do | ||
expect(subject).to eq ["c:/foo/file1.json"] | ||
end | ||
end | ||
|
||
context "with a directory" do | ||
let(:file_list) { ["spec/support/"] } | ||
|
||
it "returns a list of the json files inside" do | ||
expect(subject.size).to be > 1 | ||
|
||
subject.each do | path | | ||
expect(path).to start_with("spec/support") | ||
expect(path).to end_with(".json") | ||
end | ||
end | ||
end | ||
|
||
context "with a glob" do | ||
let(:file_list) { ["spec/support/*.json"] } | ||
|
||
it "returns a list of the json files inside" do | ||
expect(subject.size).to be > 1 | ||
|
||
subject.each do | path | | ||
expect(path).to start_with("spec/support") | ||
expect(path).to end_with(".json") | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |