Using SpecFlowLangParser directly

75 views
Skip to first unread message

Dirk Rombauts

unread,
Feb 16, 2012, 8:27:39 AM2/16/12
to SpecFlow
Hi,

I'm trying out ideas for "Living Documentation", and I was thinking
about creating something like relishapp.com. (Why? Because I like more
flexibility than what relishapp currently offers).

Since I'm familiar with SpecFlow I naturally thought I'd try to use
that, and SpecFlowLangParser seemed to be a good entry point.

static void Main(string[] args)
{
var parser = new
SpecFlowLangParser(System.Globalization.CultureInfo.CurrentCulture);

string fileName = "SampleFeature.feature";

Feature feature = null;

using(FileStream fileStream = File.OpenRead(fileName))
{
using (var reader = new StreamReader(fileStream))
{
string content = reader.ReadToEnd();
feature = parser.Parse(new StringReader(content),
fileName + ".cs");
}
}

if (feature != null)
{
string text = new SampleTemplate() { Feature =
feature }.TransformText();

using (FileStream writeStream =
File.OpenWrite(fileName + ".html"))
{
using (var streamWriter = new
StreamWriter(writeStream))
{
streamWriter.Write(text);
}
}
}
}

SampleFeature.feature is the standard SpecFlow feature file (the one
about Addition). SampleTemplate is a razor-template that I use to
generate html.

However, I ran into troubles. the call to parser.Parse(...) throws a
SpecFlowParserException with message:

Invalid Gherkin file!
(1,1): Parsing error near 'Feature: Addition'
(2,1): Parsing error near 'In order to avoid silly mistakes'
(3,1): Parsing error near 'As a math idiot'
(4,1): Parsing error near 'I want to be told the sum of two numbers'
(7,1): Parsing error near 'Scenario: Add two numbers'
(8,1): Parsing error near 'Given I have entered 50 into the
calculator'

So obviously my approach was too naive ... could somebody point me in
the right direction? Thanks!

Dirk

Roman Gavrilov

unread,
Feb 16, 2012, 2:14:37 PM2/16/12
to spec...@googlegroups.com
I don't think its naive. From the error looks like you have some extra
kruft at the beginning of each line. Add a comment as a first line
("#this is a comment") see if you get an error there. Make sure you
put it all the way to the left.

Also second argument to Parse is .feature file, not .cs file. But that
probably has nothing to do with the error you are getting.

Matthieu Gironnet

unread,
Feb 16, 2012, 2:38:28 PM2/16/12
to spec...@googlegroups.com

hi,

There is already a project doing something like relishapp and it is linked to specflow. It is called pickles. See here https://github.com/x97mdr/pickles
I've already tried it and it is working well.
Regards,

Le 16 févr. 2012 15:00, "Dirk Rombauts" <dirk.r...@chello.at> a écrit :

x97mdr

unread,
Feb 16, 2012, 7:50:20 PM2/16/12
to spec...@googlegroups.com
Hi Dirk,

As Mathieu mentioned I started a project called Pickles with much the same goals as yours in mind.  If you would like to collaborate with me I'd love to hear your ideas.  I could use some more contributers

Thanks

Dazzler

unread,
Feb 16, 2012, 8:04:09 PM2/16/12
to SpecFlow
+1 for Pickles. I started using it earlier this week. It's nice.
Darren.

Jimmy Li

unread,
Feb 16, 2012, 9:51:32 PM2/16/12
to SpecFlow
+1 for Pickles too. I started using it last week and I think it's
going to help making "live specification" a reality in my environment.
I prefer this term over "living documentation" because the material
generated is still far from the materials in our "functional
documentation", making it hard to do a complete replacement. Pickles
also supports something called MarkDown, that I need to look into,
maybe that will help close the gap even more.

Dirk Rombauts

unread,
Feb 17, 2012, 3:30:05 AM2/17/12
to SpecFlow
Hi,

Thanks for all the replies! And thanks for the Pickles hint as well -
browsing through the Pickles code gave me a clue as to what I was
doing wrong.

The problem is in the initialization of the parser: var parser = new
SpecFlowLangParser(System.Globalization.CultureInfo.CurrentCulture);

I was wondering what the culture argument means. Apparently it means
"use Gherkin keywords in that language". I changed the call to var
parser = new SpecFlowLangParser(new CultureInfo("en-US")); and
suddenly all was well :-) The current culture of my machine is
Austrian, so I should have used a German language Gherkin file. Yuk.

Dirk

x97mdr

unread,
Feb 20, 2012, 5:16:32 PM2/20/12
to spec...@googlegroups.com
Hi Jimmy,

Markdown is a common text markup language (used by StackOverflow for instance) that can be generated to HTML.  It's a great way to add some context to the features.

If you have a broader set of documentation you might want to look into DITA.  It's meant as a way to take topic-based documentation (think of a feature as a topic) and produce output in several different formats.  If your features are DITA topics and you have other static DITA topics then you have a recipe for some very powerful documentation.

HTH.

Jimmy Li

unread,
Feb 20, 2012, 11:08:05 PM2/20/12
to SpecFlow
Thanks x97mdr. I'll check out Markdown and DITA to see which one need.
I'll stop here to avoid going off topic for this thread.
Reply all
Reply to author
Forward
0 new messages