Search code examples
routesbddmspec

Can I include URL characters in an MSpec test name when testing routing?


How I can represent the following scenario using MSpec?:

Scenario: Navigation to homepage
   When I navigate to /Guestbook
   Then I should be on the guestbook page

SpecFlow makes this sort of thing easier because we can pass parameters into our specifications:

[When(@"I navigate to (.*)")]
public void WhenINavigateTo(string relativeUrl)
{
}

With MSpec, the context/specification comes from the name of the class, so I can't use any special characters (such as those used in a url).

What I would like to achieve is an output like:

Browsing the site, When I navigate to /guestbook
¯ should go to the guestbook page
Browsing the site, When I navigate to /news/article-slug
¯ should go to the news article with matching slug

Solution

  • There's not really a way to use special characters in the context or the specification in MSpec, it's never been needed before. I think you're the only person I've seen that has had a convincing reason to have a real url path in their spec. Generally you would avoid that, but if SEO specialists are reading your spec report then I can see that. You may want to try a different tool or submit a patch to MSpec that adds support for attributes that can override the string name of the context or spec.