forked from errbit/errbit
-
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.
Handle strings in pretty_hash to prevent exceptions (errbit#1544)
- Loading branch information
1 parent
cc0249a
commit 7bd1803
Showing
2 changed files
with
31 additions
and
1 deletion.
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,30 @@ | ||
describe HashHelper do | ||
describe '.pretty_hash' do | ||
let(:expected_pretty_hash) do | ||
<<~HASH.chomp | ||
{ | ||
"action" => "some_action", | ||
"controller" => "some_controller" | ||
} | ||
HASH | ||
end | ||
|
||
it 'is expected to prettify hashes' do | ||
expect(pretty_hash('controller' => 'some_controller', 'action' => 'some_action')).to eq expected_pretty_hash | ||
end | ||
|
||
it 'is expected to handle empty hashes' do | ||
expect(pretty_hash({})).to eq '{}' | ||
end | ||
|
||
context 'with string, instead of hash' do | ||
it 'is expected not to raise exception' do | ||
expect { pretty_hash('This is a string.') }.not_to raise_exception | ||
end | ||
|
||
it 'is expected to handle strings' do | ||
expect(pretty_hash('{ a_string: "But it looks like a hash"}')).to eq '{}' | ||
end | ||
end | ||
end | ||
end |