Can I include URL characters in the MSpec test name when validating routing?
How can I 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 easier because we can pass parameters to our specifications:
[When(@"I navigate to (.*)")]
public void WhenINavigateTo(string relativeUrl)
{
}
In MSpec, the context / specification comes from the class name, so I can't use special characters (like those used in the url).
What I would like to get is the result:
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
source to share
There is really no way to use special characters in context or specification in MSpec, it has never been required before. I think you are the only person I have seen who had a compelling reason to have a real url in their spec. Typically, you avoid it, but if SEOs read your specs report, I can see it. You might want to try a different tool, or submit a patch to MSpec that adds support for attributes that can override the name of a context line or spec.
source to share
SpecFlow is mainly used for system level examples, while MSpec is usually used for classes.
For url behavior and more technical details, I would like to use a class level example, AKA unit test. MSpec is great for this. For example, this describes a Navigator class that provides URLs:
My Navigator class should provide readable and memorable URLs
Considering an article with an empty cat-in-a-tree
When we request the navigator for the url Then it should be readable.
Then you can check your actual url in this example.
At a higher level, try to think about the scenario in terms of the capabilities your system presents to the user. If I am a user, why do I care that I can use this particular URL for the guestbook? Why am I going to the guestbook at all? SpecFlow is better suited for this level.
My guestbook should show me who signed
This Cat Keyboard recently signed my guestbook
When I go to the guestbook
Then I should see the Keyboard Cat name in the list.
You can now run the script in the guestbook, but keep the details of how the user navigates to the guestbook inside the script steps. You can also see that the script doesn't say anything about whether you're using a webpage, Windows app, mobile phone, or physical book - it's just about the possibilities you provide. Typically, higher-level scenarios like this will be easier to maintain and help the whole team focus on the value you are delivering to the user.
source to share