This repository has been archived by the owner on Dec 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix adding custom context to current context (#54)
* Fix adding custom context to current context * The data hash would lose custom context information since merging was not happening in place. * Add CurrentContext specs
- Loading branch information
1 parent
ea41997
commit 7ebff4e
Showing
2 changed files
with
96 additions
and
22 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,57 @@ | ||
require "spec_helper" | ||
|
||
describe Timber::CurrentContext, :rails_23 => true do | ||
describe ".add" do | ||
after(:each) do | ||
described_class.reset | ||
end | ||
|
||
it "should add the context" do | ||
expect(described_class.hash).to eq({}) | ||
|
||
described_class.add({build: {version: "1.0.0"}}) | ||
expect(described_class.hash).to eq({:custom=>{:build=>{:version=>"1.0.0"}}}) | ||
|
||
described_class.add({testing: {key: "value"}}) | ||
expect(described_class.hash).to eq({:custom=>{:build=>{:version=>"1.0.0"}, :testing=>{:key=>"value"}}}) | ||
end | ||
end | ||
|
||
describe ".remove" do | ||
it "should remove the context by object" do | ||
context = {:build=>{:version=>"1.0.0"}} | ||
described_class.add(context) | ||
expect(described_class.hash).to eq({:custom => context}) | ||
|
||
described_class.remove(context) | ||
expect(described_class.hash).to eq({}) | ||
end | ||
|
||
it "should remove context by key" do | ||
context = {:build=>{:version=>"1.0.0"}} | ||
described_class.add(context) | ||
expect(described_class.hash).to eq({:custom => context}) | ||
|
||
described_class.remove(:custom) | ||
expect(described_class.hash).to eq({}) | ||
end | ||
end | ||
|
||
describe ".with" do | ||
it "should merge the context and cleanup on block exit" do | ||
expect(described_class.hash).to eq({}) | ||
|
||
described_class.with({build: {version: "1.0.0"}}) do | ||
expect(described_class.hash).to eq({:custom=>{:build=>{:version=>"1.0.0"}}}) | ||
|
||
described_class.with({testing: {key: "value"}}) do | ||
expect(described_class.hash).to eq({:custom=>{:build=>{:version=>"1.0.0"}, :testing=>{:key=>"value"}}}) | ||
end | ||
|
||
expect(described_class.hash).to eq({:custom=>{:build=>{:version=>"1.0.0"}}}) | ||
end | ||
|
||
expect(described_class.hash).to eq({}) | ||
end | ||
end | ||
end |