Failure is inevitable


SpecsFor, SpecsFor<Web> Helpers, and SpecsFor<Mvc> All Updated!

There are lots of small fixes and improvements across the SpecsFor suite today.  Let’s take a look!

SpecsFor 4.4.0

First, the Any.NonNullValueOf partial matcher now works with nullable types!

SUT.ShouldLookLike(() => new TestObject
        OptionalDate = Any.NonNullValueOf<DateTime?>()

I also added two new Should extension methods for checking IEnumerables for ascending/descending values:

Assert.DoesNotThrow(() => new[] { 1,2,3,4}.ShouldBeAscending());
Assert.DoesNotThrow(() => new[] { 4,3,2,1 }.ShouldBeDescending());

There’s also a new method you can hook in to if you need to customize something before each individual test case: BeforeEachTest!

public class some_spec : SpecsFor<object>
    protected override void BeforeEachTest()
        //This will run before each [Test] method.

SpecsFor<Web> Helpers 1.6.1

There was a bug hiding in the creation of FakeHtmlHelper.  This is fixed now!

SpecsFor<Mvc> 4.7.0

I closed out a slew of Github requests and issues in SpecsFor<Mvc> today:

You can now configure the size of the browser window using the SpecsForMvcConfiguration object:

var config = new SpecsForMvcConfig();
config.SetBrowserWindowSize(width: 1024, height: 768);

The publish and intermediate directories used to build the app-under-test are now separately configurable:

var config = new SpecsForMvcConfig();

You can now grab a field’s validation message to inspect its contents:

    .Field(x => x.UserName)
    .Text.ShouldEqual("The User name field is required.");

You can customize the convention used to locate a validation message by creating your own IElementConventions and plugging them in.  You can also subclass the DefaultElementConventions class and override the FindValidationMessageUsingNameFor method with your own implementation.  Here’s the default implementation:

public virtual By FindValidationMessageUsingNameFor<TModel, TProp>(Expression<Func<TModel, TProp>> property) where TModel : class
    var name = ExpressionHelper.GetExpressionText(property);

    return By.CssSelector($"[data-valmsg-for='{name}']");

It’s a small change, but you can now override the BrowserDriver’s preconfigured instances with your own, so feel free to plug in your own settings for Internet Explorer, Firefox, etc.

Finally, the Project.Named helper is now much more intelligent in how it searches for the target project’s solution.  It should automatically discover many common organization conventions now.

var config = new SpecsForMvcConfig();
    //This is now *much* more intelligent!

As always, if you run into any problems, please let me know!

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