Skip to content
This repository has been archived by the owner on Dec 8, 2020. It is now read-only.

Commit

Permalink
Test ToJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
binarylogic committed Aug 21, 2016
1 parent 22eccce commit de0876e
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions spec/timber/patterns/to_json_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require "spec_helper"

describe Timber::Patterns::ToJSON do
class TestJSON
include Timber::Patterns::ToJSON

attr_reader :json_payload

def initialize(json_payload)
@json_payload = json_payload
end
end

describe ".as_json" do
let(:hash) { {} }
let(:target) { TestJSON.new(hash) }
subject { target.as_json }
it { should eq({}) }

context "with a value" do
let(:hash) { {:test => 1} }
it { should eq({"test" => 1}) }
end

context "with a nil value" do
let(:hash) { {:test => nil} }
it { should eq({}) }
end

context "with an empty array" do
let(:hash) { {:test => []} }
it { should eq({}) }
end
end
end

0 comments on commit de0876e

Please sign in to comment.