Closed Steinblock closed 8 years ago
The premise here was that the tree like output would be a quick "readable" summary. After that the assertion failure report at the very end would contain things like new lines. Are they retained correctly at the very boot of the test output?
I suppose you intendet to let the tree output look like this:
describe specifications
when creating specifications
true should be false - FAILED - Expected: False, But was: True
So the DomainExtensions.CleanMessage
should convert line breaks in error messages
Expected: False
But was: True
to become comma plus whitespace and the result should be Expected: False, But was: True
but infact it only does replace LF
thus converting windows line breaks to mac line breaks.
Well the master solution would be using a regex but I decided to just push a simple fix, that will do the trick. If you want, use this code, which is a more generic approach
using System.Text.RegularExpressions;
public static class Extensions
{
private static string pattern = @"(\r(?!\n)|(?<!\r)\n|\r\n)";
private static Regex regex = new Regex(pattern, RegexOptions.Compiled);
public static string ConvertNewLine(this string input, string replacement)
{
if (input == null) return null;
return regex.Replace(input, replacement);
}
}
public class NSpec_Tests : nspec
{
public void When_Dealing_With_Mixed_Line_Endings()
{
var expected = "Hello World";
var value1 = "Hello\rWorld";
var value2 = "Hello\nWorld";
var value3 = "Hello\r\nWorld";
context["and converting string values"] = () =>
{
it["CR should be replaced"] = () => value1.ConvertNewLine(" ").should_be(expected);
it["LF should be replaced"] = () => value2.ConvertNewLine(" ").should_be(expected);
it["CRLF should be replaced"] = () => value3.ConvertNewLine(" ").should_be(expected);
};
}
}
Naw, I'm fine with what you've got (simple works for me). Thanks for the contribution. I'll get a new version published this weekend if that's alright? I can do it sooner if needed.
No need to hurry. Be sure to rebuild your website afterwards. The examples have a line break, too.
describe specifications
when creating specifications
true should be false - FAILED - Expected: False
, But was: True
When running specifications with
NSpecRunner.exe
the console output should look like thisbut looks like
the issue comes from the
DomainExtensions.CleanMessage
extension method which converts<crlf>
to<lf>
:exception.Message.Trim().Replace("\n", ", ").Trim();