-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make json format approvals resilient to differences in pretty json fo…
…rmatting
- Loading branch information
1 parent
05f658c
commit 0d776cb
Showing
11 changed files
with
119 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
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,15 @@ | ||
require 'approvals/verifiers/json_verifier' | ||
|
||
module Approvals | ||
module Verifier | ||
REGISTRY = { | ||
json: Verifiers::JsonVerifier, | ||
} | ||
|
||
class << self | ||
def for(format) | ||
REGISTRY[format] | ||
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,27 @@ | ||
module Approvals | ||
module Verifiers | ||
class JsonVerifier | ||
def initialize(received_path, approved_path) | ||
self.received_path = received_path | ||
self.approved_path = approved_path | ||
end | ||
|
||
def verify | ||
return false unless approved == received | ||
true | ||
end | ||
|
||
private | ||
|
||
attr_accessor :approved_path, :received_path | ||
|
||
def approved | ||
@approved = JSON.parse(File.read(approved_path)) | ||
end | ||
|
||
def received | ||
@receiver = JSON.parse(File.read(received_path)) | ||
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
6 changes: 6 additions & 0 deletions
6
...s_json_where_the_pretty_generation_is_different_but_the_content_is_the_same.approved.json
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,6 @@ | ||
{ | ||
"foo": { | ||
|
||
|
||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
spec/fixtures/approvals/approvals_verifies_json_with_a_time_object.approved.json
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 @@ | ||
{ | ||
"foo": "2017-01-01 00:00:00 +0100" | ||
} |
7 changes: 7 additions & 0 deletions
7
spec/fixtures/json_approval_with_different_whitespace/approved.json
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,7 @@ | ||
{ | ||
"foo": { | ||
|
||
|
||
|
||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
spec/fixtures/json_approval_with_different_whitespace/received.json
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 @@ | ||
{ | ||
"foo": {} | ||
} |
3 changes: 3 additions & 0 deletions
3
spec/fixtures/json_approval_with_different_whitespace/received_different_content.json
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 @@ | ||
{ | ||
"bar": 1 | ||
} |
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,33 @@ | ||
require 'spec_helper' | ||
|
||
describe Approvals::Verifiers::JsonVerifier do | ||
subject(:instance) do | ||
described_class.new(received_path, approved_path) | ||
end | ||
|
||
context "with same json content but different formatting" do | ||
let(:received_path) do | ||
"./spec/fixtures/json_approval_with_different_whitespace/received.json" | ||
end | ||
let(:approved_path) do | ||
"./spec/fixtures/json_approval_with_different_whitespace/approved.json" | ||
end | ||
|
||
it "passes verification" do | ||
expect(instance.verify).to be_truthy | ||
end | ||
end | ||
|
||
context "with different json content" do | ||
let(:received_path) do | ||
"./spec/fixtures/json_approval_with_different_whitespace/received_different_content.json" | ||
end | ||
let(:approved_path) do | ||
"./spec/fixtures/json_approval_with_different_whitespace/approved.json" | ||
end | ||
|
||
it "does not passe verification" do | ||
expect(instance.verify).to be_falsy | ||
end | ||
end | ||
end |