Created
March 9, 2012 06:39
-
-
Save shageman/2005366 to your computer and use it in GitHub Desktop.
Why a question mark method should return the true object or the false object
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
require 'rspec/core' | |
class TheClassThatIsTrueButNeverInTheSameWay | |
def initialize(truthiness) | |
@truthiness = truthiness | |
end | |
def truthy? | |
@truthiness ? Time.now : false | |
end | |
end | |
describe "the class that is true but never in the same way's truthy method" do | |
context "initialized with false" do | |
it "should be falsy" do | |
TheClassThatIsTrueButNeverInTheSameWay.new(false).should_not be_truthy | |
end | |
end | |
context "initialized with true" do | |
it "should be truthy" do | |
TheClassThatIsTrueButNeverInTheSameWay.new(true).should be_truthy | |
end | |
it "should not be the same truthy for different objects" do | |
never_the_same_way_1 = TheClassThatIsTrueButNeverInTheSameWay.new(true) | |
never_the_same_way_2 = TheClassThatIsTrueButNeverInTheSameWay.new(true) | |
never_the_same_way_1.truthy?.should_not == never_the_same_way_2.truthy? | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment