Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Documentation Driven Development

Documentation Driven Development

A lightning talk about documentation

Rafael França

May 12, 2016
Tweet

More Decks by Rafael França

Other Decks in Programming

Transcript

  1. # Public: Duplicate some text an arbitrary number of times.

    # # text - The String to be duplicated. # count - The Integer number of times to duplicate the text. # # Examples # # multiplex('Tom', 4) # # => 'TomTomTomTom' # # Returns the duplicated String. def multiplex(text, count) text * count end
  2. def active? return true if ( Time.now.utc > self.start_date &&

    self.end_date.nil?) return (Time.now.utc > self.start_date && Time.now.utc < self.end_date) end
  3. # Public: checks if the campaign is active. # #

    Return `true` if the campaign started in the past and the end date is # `nil` or is in the future. def active? return true if ( Time.now.utc > self.start_date && self.end_date.nil?) return (Time.now.utc > self.start_date && Time.now.utc < self.end_date) end
  4. it "returns true if the campaign is active right now"

    do active_voucher_campaign.should be_active end it "returns false if the campaign's end date is in past" do inactive_voucher_campaign.should_not be_active end it "returns true if the campaign has started in past and there is no end date" voucher_campaign_without_end_date.should be_active end
  5. # Public: checks if the campaign is active. # #

    Return `true` if the campaign started in the past and the end date is # `nil` or is in the future. def active? now = Time.now.utc return true if (started_in_past?(now) && self.end_date.nil?) return (started_in_past?(now) && now < self.end_date) end # Internal: checks if the campaign started in the past. # # time - the time you want to compare. def started_in_past?(time) time > start_date end
  6. # Public: checks if the campaign is active. # #

    Return `true` if the campaign started in the past and the end date is # `nil` or is in the future. def active? now = Time.now.utc return true if (started_in_past?(now) && self.end_date.nil?) return (started_in_past?(now) && will_end_in_future?(now)) end # Internal: checks if the campaign started in the past. # # time - the time you want to compare. def started_in_past?(time) time > start_date end # Internal: checks if the campaign will end in the future. # # time - the time you want to compare. def will_end_in_future?(time) time < end_date end
  7. # Public: checks if the campaign is active. # #

    Return `true` if the campaign started in the past and the end date is # `nil` or is in the future. def active? now = Time.now.utc started_in_past?(now) && (self.end_date.nil? || will_end_in_future? (now)) end # Internal: checks if the campaign started in the past. # # time - the time you want to compare. def started_in_past?(time) time > start_date end # Internal: checks if the campaign will end in the future. # # time - the time you want to compare. def will_end_in_future?(time) time < end_date end
  8. # Public: checks if the campaign is active. def active?

    now = Time.now.utc started_in_past?(now) && (self.end_date.nil? || will_end_in_future?(now)) end # Internal: checks if the campaign started in the past. # # time - the time you want to compare. def started_in_past?(time) time > start_date end # Internal: checks if the campaign will end in the future. # # time - the time you want to compare. def will_end_in_future?(time) time < end_date end