try-catch-FAIL

Failure is inevitable

NAVIGATION - SEARCH

SpecsFor.Mvc and SpecsFor<Web> Helpers updated!

There are two new releases on the SpecsFor front today.  First, thanks to Neuhoffm again, SpecsFor.Mvc now supports radio buttons properly.  You can “check” a radio button by string value or by using a strongly-typed value:

SUT.FindFormFor<Task>()
    .Field(m => m.Title).SetValueTo("use radio buttons")
    //By string...
    .Field(m => m.Complete, "false").Click()
    .Submit();

SUT.FindFormFor<Task>()
    .Field(m => m.Title).SetValueTo("use radio buttons")
    .Field(m => m.Complete, true).Click()
       //Or by strongly-typed value!
    .Field(m => m.Priority, Priority.High).Click()
    .Submit();

You can check out this change in the 4.3.0 release.

Next, there’s a preview release of SpecsFor<Web> Helpers out today.  It adds support for fake ControllerContext, and you can easily wire this up on your controller specs like so:

public class when_initializing_the_SUT_with_a_fake_controller : SpecsFor<DummyController>
{
    protected override void When()
    {
        this.UseFakeContextForController();

        GetMockFor<IPrincipal>()
            .Setup(x => x.Identity.Name)
            .Returns("My test!");
    }

    [Test]
    public void then_it_configures_the_fake_user_correctly()
    {
        SUT.User.ShouldNotBeNull();
        SUT.User.Identity.Name.ShouldEqual("My test!");
    }
}

Note that SpecsFor<Web> Helpers 1.5.0  is currently in pre-release form.  I nuked FakePrinciple and FakeIdentity as part of this change as they seemed unnecessary.  If anyone can make a strong argument for why they should be kept, let me know, otherwise, this change will become final later this week.

As always, 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