Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Utils#deprecate only prints each warning once, and has working specs.
- Loading branch information
Showing
2 changed files
with
36 additions
and
9 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 |
---|---|---|
@@ -1,10 +1,34 @@ | ||
require 'spec_helper' | ||
|
||
describe Koala::Utils do | ||
it "has a deprecate method" do | ||
Koala::Utils.should respond_to(:deprecate) | ||
end | ||
describe "#deprecate" do | ||
before :each do | ||
# unstub deprecate so we can test it | ||
Koala::Utils.unstub(:deprecate) | ||
end | ||
|
||
it "has a deprecation prefix that includes the words Koala and deprecation" do | ||
Koala::Utils::DEPRECATION_PREFIX.should =~ /koala/i | ||
Koala::Utils::DEPRECATION_PREFIX.should =~ /deprecation/i | ||
end | ||
|
||
it "prints a warning with Kernel.warn" do | ||
message = Time.now.to_s + rand.to_s | ||
Kernel.should_receive(:warn) | ||
Koala::Utils.deprecate(message) | ||
end | ||
|
||
# AFAIK there's no way to test that (Kernel.)warn receives the text | ||
# Kernel.should_receive(:warn) doesn't seem to work, even though the text gets printed | ||
it "prints the deprecation prefix and the warning" do | ||
message = Time.now.to_s + rand.to_s | ||
Kernel.should_receive(:warn).with(Koala::Utils::DEPRECATION_PREFIX + message) | ||
Koala::Utils.deprecate(message) | ||
end | ||
|
||
it "only prints each unique message once" do | ||
message = Time.now.to_s + rand.to_s | ||
Kernel.should_receive(:warn).once | ||
Koala::Utils.deprecate(message) | ||
Koala::Utils.deprecate(message) | ||
end | ||
end | ||
end |