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
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.
SpecFlow is mostly used for system-level examples, while MSpec is normally used for class-level ones.
For URL behavior and more technical details, I would tend to use a class-level example, AKA unit test. MSpec is great for this. For instance, this describes a Navigator class that provides the URLs:
My Navigator class should provide readable and memorable urls
Given an article with the slug cat-in-a-tree
When we ask the Navigator for a url
Then it should be readable.
You can then do the checking for your actual URL inside that example.
At a higher level, try thinking about the scenario in terms of the capabilities that your system delivers to the user. If I'm a user, why do I care that I can use that particular URL for the Guestbook? Why am I even going to the Guestbook in the first place? SpecFlow is better suited at this level.
My Guestbook should show me who has signed in
Given Keyboard Cat recently signed my guest book
When I go to the guestbook
Then I should see Keyboard Cat's name in the list.
Now you can have the scenario navigate to the guestbook, but keep the detail of how the user navigates to the guestbook inside the steps of the scenario. You can also see that the scenario doesn't say anything about whether you're using a web page, a windows application, a mobile phone or a physical book - it's just about the capabilities you're delivering. Generally higher-level scenarios like this will be easier to maintain, and help your entire team to focus on the value that you're delivering to the user.