Created
August 11, 2012 06:05
-
-
Save danielsz/3321662 to your computer and use it in GitHub Desktop.
def is my stub framework
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 code | |
describe "#pubdate" do | |
describe "before publishing" do | |
it "is blank" do | |
@it.pubdate.must_be_nil | |
end | |
end | |
describe "after publishing" do | |
before do | |
@clock = stub! | |
@now = DateTime.parse("2011-09-11T02:56") | |
stub(@clock).now(){@now} | |
@it.blog = stub! | |
@it.publish(@clock) | |
end | |
it "is a datetime" do | |
@it.pubdate.class.must_equal(DateTime) | |
 end | |
it "is the current time" do | |
@it.pubdate.must_equal(@now) | |
end | |
end | |
end |
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
## suggested code | |
describe "#pubdate" do | |
describe "before publishing" do | |
it "is blank" do | |
@it.pubdate.must_be_nil | |
end | |
end | |
describe "after publishing" do | |
before do | |
class Clock < DateTime | |
def now | |
DateTime.parse("2011-09-11T02:56") | |
end | |
end | |
@clock = Clock.new | |
@blog = MiniTest::Mock.new | |
@blog.expect :add_entry, nil, [@it] | |
@it.blog = @blog | |
@it.publish(@clock) | |
end | |
after do | |
@blog.verify | |
end | |
it "is a datetime" do | |
@it.pubdate.class.must_equal(DateTime) | |
end | |
it "is the current time" do | |
@it.pubdate.must_equal(@clock.now) | |
end | |
end | |
end |
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
## or better yet | |
describe "after publishing" do | |
before do | |
class Clock < DateTime | |
def now | |
self.class.parse("2011-09-11T02:56") | |
end | |
end | |
... | |
end | |
... | |
it "is a datetime" do | |
@it.pubdate.class.must_equal(Clock) | |
end | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment