Skip to content
This repository has been archived by the owner on May 28, 2019. It is now read-only.

Improve parser testing support #3

Closed
msassak opened this issue Sep 3, 2009 · 13 comments
Closed

Improve parser testing support #3

msassak opened this issue Sep 3, 2009 · 13 comments

Comments

@msassak
Copy link
Contributor

msassak commented Sep 3, 2009

The current parser testing is a hack pretty much all around. What we have for table parsing works well enough, but I'm not sure it's going to cut it for full-blown feature file parsing.

@aslakhellesoy
Copy link
Contributor

What do you think is hacky about it? I think a mock based approach where we expect certain events is good. Do you see any problems with that approach or are you referring to how it's currently implemented with the spec's #scan method? (I think that can be improved).

@msassak
Copy link
Contributor Author

msassak commented Sep 3, 2009

The spec's #scan method. It can be removed in favor of a before block that sets up @Listener and @table. I was also thinking of writing some custom matchers for use with the listener to enable writing specs like

parsing("|a|b|\n").should find(3).rows
parsing("Feature: foo").should find_feature("foo")

or something like that, but that might be more trouble than it's worth.

@aslakhellesoy
Copy link
Contributor

Let's wait with custom matchers until we see some repetitive patterns that can't be solved nicely without matchers. For features it could be something along the lines of:

@listener.should_receive(:feature).with("Feature", "foo")
@listener.should_receive(:scenario).with("Scenario", "bar")
@listener.should_receive(:step).with("Given", "bar")
@parser.parse("Feature: foo\nScenario: bar\nGiven bar")

Think that could work?

@msassak
Copy link
Contributor Author

msassak commented Sep 3, 2009

For sure! That's close to what's in feature_spec.rb right now as it is. I'll move everything over to that and push later tonight.

@aslakhellesoy
Copy link
Contributor

Mike, can we close this now?

@ghnatiuk
Copy link
Contributor

ghnatiuk commented Sep 8, 2009

I'm looking into creating a TestListener that outputs something like to_sexp does in cucumber. As the feature files we're parsing get longer, I'm finding it harder to correctly ensure proper message reception and counts, particularly in regards to ordering and ensuring only a single message reception.

I'd like to be able to do something like:

@listener.messages.should == [
    [:feature, "Feature", "This is a feature\n  With multiple lines", 1],
    [:comment, "This is a comment", 3],
    [:scenario, "Scenario", "This is a scenario, 4]]

by simply appending all calls to the TestListener to a list in the order they're received. It would allow for simple assertions, and provide far better output than the current method when the assertion fails (e.g. "Mock 'listener' received :feature out of order" doesn't really tell me much about how the rest of the parsing went).

It would, however, provide a level of indirection between the behavior of the parser and the expectations on the interface of the listener. What do you think?

@aslakhellesoy
Copy link
Contributor

I love that idea. Instead of calling it TestListener, maybe we could call it SexpRecorder? It could serve two purposes: Testing and documentation of the Listener API. (It would only have one non-API method: #to_sexp)

@aslakhellesoy
Copy link
Contributor

Come to think of it - it might be easier to implement SexpRecorder with #method_missing, which would render it useless as documentation ;-) (We could always write a different reference implementation. Maybe a pretty printer or something)

@msassak
Copy link
Contributor Author

msassak commented Sep 8, 2009

I was screwing around with Google AppEngine last night and whipped this up: http://gherkintest.appspot.com. Pretty useless as it currently stands, but the code does contain an UglyPrinter that perhaps we could use as a basis for a reference implementation. :-)

@aslakhellesoy
Copy link
Contributor

OK, I just pushed an implementation of a simple SexpRecorder and wrote one spec using it. I'm a bit busy working on a presentation I have tomorrow, so I won't be converting any of the existing specs...

@aslakhellesoy
Copy link
Contributor

Oooh nice! Is the code open source?

@msassak
Copy link
Contributor Author

msassak commented Sep 8, 2009

It will be tonight. :-) I used the google-appengine gem, and while it's super-easy to get started, I need to figure out how to create a git repo for a google app without all the extra generated stuff before pushing it to github.

@ghnatiuk
Copy link
Contributor

ghnatiuk commented Sep 8, 2009

Perfect! Thanks. I'll close this issue. I'll work through converting the existing specs as I revisit them. Shouldn't take too long.

This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants