I've been following James Broome's tutorial to teach myself MSpec and some of the related infrastructure. I'm using the latest version of MSpec, MSpecMvc, and ASP.NET MVC 2 and I'm not using J.P Boodhoo's librarie开发者_如何转开发s.
When I run this test
[Subject(typeof(HomeController))]
public class when_the_home_controller_is_told_to_display_the_default_view
{
static string key;
static string message;
static ActionResult result;
static HomeController home_controller;
Establish context = () =>
{
key = "Message";
message = "Welcome to ASP.NET MVC!";
home_controller = new HomeController();
};
Because of = () => result = home_controller.Index();
It should_return_the_home_view = () => result.ShouldBeAView().And().ViewName.ShouldBeEmpty();
}
I get the following error
should return the home view : Failed
Should be of type System.Web.Mvc.ViewResult but is of type System.Web.Mvc.ViewResult
When I step through the code it conks in the assertion in this method (in the ActionResultExtensions.cs
file of MSpecMVC)
public static ViewResultAnd ShouldBeAView(this ActionResult actionResult)
{
actionResult.ShouldBeOfType<ViewResult>();
return new ViewResultAnd(actionResult as ViewResult);
}
Although, I can confirm that actionResult
is of type System.Web.Mvc.ViewResult
. I've used the same tools on another computer to run other tests but I've not encountered the current issue.
James Broome's MSpec.MVC extensions use Mspec v0.2. Since you are using Mspec v0.3 there is a mismatch. You should get the source and update the solution to use MSpec v0.3.
Make sure the Mspec.MVC extensions target the same .NET Framwork version as your ASP.NET MVC solution (for example, both are 4.0). That will also depend on which version of MSpec you are using. MSpec v0.3 is compiled against both .NET 3.5
and .NET 4.0
精彩评论