I’ve been quietly shipping preview releases of new things for SpecsFor for the last couple of months. It’s time to finally get these things promoted to “final” status and talk about them. From better assertions to a whole new helper library, there’s a lot to talk about, so buckle up!
[more]
SpecsFor 4.1.0 Released!
This one has been cooking for a while now. I don’t have time to talk in-depth about all the features now, but here’s the quick summary.
- Safer partial matching – ShouldLookLikePartial can be used for doing partial object matches, but it works using an anonymous type to specify what properties to check. This is not type-safe and is prone to breaking in spectacular ways as your code changes. Thanks to Robert Simmons, SpecsFor now has a strongly-typed partial matching extension method. Just pass a lambda expression to ShouldLookLike (not ShouldLookLikePartial). Rob has a write-up on this feature and how it works.
- Updated to StructureMap 3.1. There are a lot of fixes in the 3.1 release of StructureMap, including some that SpecsFor depends on. 3.1 is now required.
- You can now create a IContext spec context classes that can be applied to any spec class. Previously, there was only the generic IContext<T> context interface, which required you to tie it to a particular type you wished to test. No longer!
- SpecsFor (and related projects) now have an icon. Yeah, I know that’s super-useful, but now at least you can spot the SpecsFor packages more easily in the NuGet Package Explorer!
SpecsFor<Web> Helpers Released (and updated)!
I do a lot of ASP.NET MVC application development. A LOT. Testing ASP.NET MVC applications isn’t as easy as it should be. Libraries like MvcContrib.TestHelpers do make things easier, but MvcContrib is effectively dead, plus it doesn’t play as nicely with SpecsFor as I would like. Hence I created my own library specifically to alleviate testing pain for ASP.NET MVC applications. There’s already a lot in this project, but here’s a quick recap of what it can do for you:
- Fluent API for asserting off of ActionResults. You can do things like ShouldRenderView, ShouldRenderDefaultValue, ShouldRedirecTo, etc.
- Fake objects for common System.Web.Abstraction entities, such as FakeHttpContext, FakeIdentity, etc. Use these when you need to test something that depends on one of the underlying abstractions, and you’ll get a nice, ready-to-use object graph that you can customize the behavior of easily.
- FakeHtmlHelper and FakeUrlHelper. You can use these to simplify testing of HtmlHelper extension methods. Just make your spec derive from SpecsFor<FakeHtmlHelper>, and off you go!
- Have you ever tried to load up your routing in a test project? Have you ever tried to do that while using Attribute Routing? If so, you probably hit the brick wall of failure. SpecsFor<Web> Helpers provides the RouteCollection.MapMvcAttributeRoutesForTestingFromAssemblyContaining<TType>() extension method that will load up your attribute-routing defined routes for you.
SpecsFor.Mvc 3.2.0 Released!
SpecsFor.Mvc is due for much more love in the near future, but the 3.2.0 release takes a few small steps forward.
- You can now specify the path to MSBuild.exe manually. Just set the full path to whatever version of MSBuild you want it to use for deploying your app by calling the UseMSBuildExecutableAt method on the IIS Expression config API.
- You can now specify the path to your project’s solution file manually. Before, SpecsFor would try to guess the location of your project’s solution file using the common “Solution\Project” folder hierarchy. If you didn’t organize your solution this way, SpecsFor wouldn’t work for you. Now you can tell it the path using the optional pathToSolution argument on the existing With method.
- By default, SpecsFor.Mvc chooses an available port number to spin up IIS Express on automatically. You can now override this behavior by calling the new UsePort on the IIS Express config API.
- Test runners do crazy things, like randomly deciding to Shadow Copy only some of the assemblies that are going to be tested. This can cause problems with SpecsFor.Mvc since it needs the Selenium web driver executables. SpecsFor.Mvc now throws a better exception when Selenium can’t find its web drivers, and this exception will hopefully make it easier to debug this sort of problem when it occurs.
Each of these bullet points really deserves its own blog post. But, time is short, so this will have to do for now. Enjoy!