try-catch-FAIL

Failure is inevitable

NAVIGATION - SEARCH

SpecsFor 5.0 Released!

The new version of SpecsFor should now be live on NuGet.  This version uses the latest version of StructureMap and Moq and fixes a couple of other issues. 

SpecsFor also gained a new partial matching method a while back, I just haven’t had time blog about it.  Read on to find out how to use it.

Partial matching is pretty awesome:

[Test]
public void then_returns_the_expected_model()
{
     _account.ShouldLookLike(() => new Customer
     {
          //AccountNumber = ? //Ignore!
          CustomerName = "Atticus Finch",
          Balance = 5042.61
     });
}

Partial matching with fuzzy checks is even better:

[Test]
public void then_you_can_check_for_values_in_a_range()
{
    var engine = new Engine {YearBuilt = 2015};
    engine.ShouldLookLike(() => new Engine
    {
        YearBuilt = Some.ValueInRange(2014, 2016)
    });
}

Partial matching with fuzzy checks against items within a collection is just awesome:

[Test]
public void then_you_can_check_for_an_item_in_a_list()
{
    var warehouse = new Warehouse
    {
        Engines = new[] {new Engine {YearBuilt = 2013}, new Engine {YearBuilt = 2016}}
    };

    warehouse.ShouldLookLike(() => new Warehouse
    {
        Engines = Some.ListContaining(() => new Engine
        {
            //Yep, you can use partial matching recursively!
            YearBuilt = Some.ValueOf<int>(i => i % 2 == 0)
        })
    });
}

Enjoy, and as always, please let me know if you run into any problems.

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