[tinybdd] r71 committed - Impl a neat feature for parsing the test methods name. This can be use...

0 views
Skip to first unread message

codesite...@google.com

unread,
Nov 3, 2009, 6:23:13 PM11/3/09
to tin...@googlegroups.com
Revision: 71
Author: goeran.hansen
Date: Tue Nov 3 15:22:32 2009
Log: Impl a neat feature for parsing the test methods name. This can be
used when describing Thens in scenarios.
http://code.google.com/p/tinybdd/source/detail?r=71

Modified:
/trunk/TinyBDD/Dsl/GivenWhenThen/Semantics.cs
/trunk/TinyBDD/Dsl/GivenWhenThen/TestMetadataParser.cs
/trunk/TinyBDDTests/Dsl/GivenWhenThen/SemanticsTests.cs

=======================================
--- /trunk/TinyBDD/Dsl/GivenWhenThen/Semantics.cs Sat May 30 05:38:42 2009
+++ /trunk/TinyBDD/Dsl/GivenWhenThen/Semantics.cs Tue Nov 3 15:22:32 2009
@@ -3,6 +3,7 @@
using System.Linq;
using System.Text;
using System.Reflection;
+using System.Diagnostics;

namespace TinyBDD.Dsl.GivenWhenThen
{
@@ -61,9 +62,20 @@

public ThenSemantics Then(Then then)
{
- return Then(metadataParser.TranslateToText(then),
+ var text = metadataParser.TranslateToText(then);
+ if (text == string.Empty)
+ text = GetCallersMethodName();
+
+ return Then(text,
() => { then(); });
}
+
+ private string GetCallersMethodName()
+ {
+ var st = new StackTrace();
+ var name = st.GetFrames().Skip(2).First().GetMethod().Name;
+ return metadataParser.FormatText(name);
+ }

public ThenSemantics Then(string text)
{
=======================================
--- /trunk/TinyBDD/Dsl/GivenWhenThen/TestMetadataParser.cs Thu Aug 20
00:35:16 2009
+++ /trunk/TinyBDD/Dsl/GivenWhenThen/TestMetadataParser.cs Tue Nov 3
15:22:32 2009
@@ -70,7 +70,7 @@
return string.Empty;
}

- private string FormatText(string title)
+ public string FormatText(string title)
{
title = title.Replace("_", " ");
return title;
=======================================
--- /trunk/TinyBDDTests/Dsl/GivenWhenThen/SemanticsTests.cs Thu Aug 20
00:35:16 2009
+++ /trunk/TinyBDDTests/Dsl/GivenWhenThen/SemanticsTests.cs Tue Nov 3
15:22:32 2009
@@ -129,6 +129,15 @@


semanticModelState.Acts.Values.First().First().Text.ShouldBe("user should
be deleted from the database");
}
+
+ [Test]
+ public void
Then_should_add_assert_to_the_semanticModel_when_code_block_is_specified()
+ {
+ semantics.When(user_is_deleted);
+ semantics.Then(() => { });
+
+
semanticModelState.Acts.Values.First().First().Text.ShouldBe("Then should
add assert to the semanticModel when code block is specified");
+ }

[Test]
public void
Reused_context_should_be_translated_to_a_title_if_its_a_private_field_in_test_class()

Reply all
Reply to author
Forward
0 new messages