Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9083597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:48:44+00:00 2026-06-16T20:48:44+00:00

I’m trying to write test that compare some dates. So far i have 2

  • 0

I’m trying to write test that compare some dates. So far i have 2 tests, one of them works as intended, but the other one fails because doesnt/not correctly compare dates.
Here is my code:

def self.has_expired?(card, start_month, start_year, annually)
    card_date = Date.new(card.year, card.month, -1)
    billing_date = Date.new(start_year, start_month, -1)
    if !annually
      p '--------'
      p card_date
      p billing_date
      card_date > billing_date

    else
      #return false
    end
  end

creditcard object

creditcard = ActiveMerchant::Billing::CreditCard.new(
        :number     => 1234567890123456
        :month      => 01,
        :year       => 13,
        :first_name => 'John', 
        :last_name  => 'Doe',
        :verification_value  => 132,
        :brand => 'visa'
      )

Here is output of p’s
First block works as intended.

"--------"
Tue, 31 Jan 0013
Thu, 28 Feb 2013
false

Second block fails, expecting true, but got false

."--------"
Tue, 31 Jan 0013
Fri, 30 Nov 2012
false

Here is my rspec code

describe CreditCard do 
  context 'card_expired' do
    it 'should return false with args passed to method (02month, 13 year, annually==false)' do
      CreditCard.has_expired?(creditcard, 02, 2013, false).should == false
    end

    it 'should return true with args passed to method (11month, 12 year, annually==false)' do
      CreditCard.has_expired?(creditcard, 11, 2012, false).should == true
    end
  end

end

in irb it works as charm, returning correct value(true/false)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T20:48:45+00:00Added an answer on June 16, 2026 at 8:48 pm

    I think the problem is in your logic. A card is expired when the expiration date is before the billing date, thus when

    card_date < billing_date # expired
    

    and not when

    card_date > billing_date # valid
    

    Also try puting in the full 2013 and see if that helps if it keeps breaking

    :year => 2013,
    

    You’re also missing a comma after this line (probably a copy/paste error) :number => 1234567890123456

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.