Failure is inevitable


SpecsFor - Better Partial Matching for Dates

I just shipped a small update to SpecsFor that improves the partial-matching story when dealing with dates.

Prior to this update, if you wanted to see if a DateTime value was “near” the current time, you had to do something like this:

obj.ShouldLookLike(() => new TestObject
    DateTimeValue = Some.ValueInRange(DateTime.Now.AddSeconds(-1), DateTime.Now)

With version 4.3.2 though, you can now use the new Some.DateTimeNear method:

obj.ShouldLookLike(() => new TestObject
    DateTimeValue = Some.DateTimeNear(DateTime.Now)

By default, any value within 1 second of the specified time will match, but you can adjust that globally by changing Some.DefaultDateTimeTolerance to another value.

It’s a small change, but I think it helps the spec convey its intent much more cleanly.


About Matt Honeycutt...

Matt Honeycutt is a software architect specializing in ASP.NET web applications, particularly ASP.NET MVC. He has over a decade of experience in building (and testing!) web applications. He’s an avid practitioner of Test-Driven Development, creating both the SpecsFor and SpecsFor.Mvc frameworks.

He's also an author for Pluralsight, where he publishes courses on everything from web applications to testing!

blog comments powered by Disqus