-
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.
Merge pull request #14 from DataDog/tonycthsu/test-callback
Test for callback
- Loading branch information
Showing
2 changed files
with
95 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,87 @@ | ||
require "minitest/spec" | ||
require "minitest/autorun" | ||
|
||
require "graft/callback" | ||
|
||
describe Graft::Callback do | ||
describe "initialize" do | ||
it do | ||
callback = Graft::Callback.new | ||
|
||
_(callback.name).must_be_nil | ||
end | ||
|
||
it do | ||
name = "Tony Stark" | ||
|
||
callback = Graft::Callback.new(name) | ||
|
||
_(callback.name).must_be :==, name | ||
end | ||
|
||
describe "enabled?" do | ||
it do | ||
callback = Graft::Callback.new | ||
|
||
_(callback).must_be :enabled? | ||
|
||
callback.disable | ||
|
||
_(callback).wont_be :enabled? | ||
|
||
callback.enable | ||
|
||
_(callback).must_be :enabled? | ||
end | ||
end | ||
|
||
describe "#call" do | ||
invocations = [ | ||
->(c) { c.call }, # with no args | ||
->(c) { c.call(:foo) }, # with positional arg | ||
->(c) { c.call(:foo, :bar) }, # with 2 positional args | ||
->(c) { c.call({foo: :bar}) }, # with positional arg(hash) | ||
->(c) { c.call(foo: :bar) }, # with kwargs | ||
->(c) { c.call { :baz } }, # with block | ||
->(c) { c.call(:foo) { :baz } }, # with positional arg + block | ||
->(c) { c.call(:foo, :bar) { :baz } }, # with 2 positional arg + block | ||
->(c) { c.call({foo: :bar}) { :baz } }, # with positional arg(hash) + block | ||
->(c) { c.call(foo: :bar) { :baz } } # with kwargs + block | ||
# Add more invocations here... | ||
] | ||
|
||
it do | ||
callback = Graft::Callback.new("name", {}) | ||
|
||
callback.enable | ||
|
||
invocations.each do |i| | ||
_ { i.call(callback) }.must_raise NoMethodError | ||
end | ||
|
||
callback.disable | ||
|
||
invocations.each do |i| | ||
_(i.call(callback)).must_be_nil | ||
end | ||
end | ||
|
||
it do | ||
callback = Graft::Callback.new("name", {}) { :wuff } | ||
# NOTE: What is missing? | ||
|
||
callback.enable | ||
|
||
invocations.each do |i, v| | ||
_(i.call(callback)).must_be :==, :wuff | ||
end | ||
|
||
callback.disable | ||
|
||
invocations.each do |i| | ||
_(i.call(callback)).must_be_nil | ||
end | ||
end | ||
end | ||
end | ||
end |