Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shageman/2005366 to your computer and use it in GitHub Desktop.
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
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