New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can we get an alias for it_should_behave_like? #74
Comments
I'm not sure I'd want to add this, but .... There is a method on ExampleGroup called
And that lets you say:
And it's the same as saying:
What if we added
Which would produce output:
|
Looks nice. I hadn't thought about the formatting of the output because in general I find the existing output to be fine (ie. the "it should behave like" text which is sometimes problematic for me doesn't appear in the output, only the included examples do). If you think it would be a good idea, then sure. All in all, I don't think it's a bad idea to expose this (and perhaps other) aliasing methods. All my specs are in English, but I am sure there are a lot of developers out there working in other languages who wouldn't mind having an easy way to alias some of those keywords to something else. But I guess that is a subject for another ticket. Don't want to overload this one. |
Actually, with the recent changes, "it should behave like" DOES show up in the output text, which I think is a huge win. I'll give this aliasing some thought. |
Ah, well if it appears in the output like that, yeah, it would be pretty essential to offer the override that you proposed above, otherwise there's no point in aliasing. As it reads in those examples I find it a bit incongruous:
While the examples themselves are concise (starting with a verb) like "has three items", the "it should behave like ..." seems comparatively verbose. Would read nicer as:
ie. "behaves like" instead of "it should behave like". |
|
The benefit of that is that you can choose your style. Lots of people still write |
Seems like a plan. |
You wanna fire that up? |
I'll have a try. |
Ok, first cut at pushed to this branch: http://github.com/wincent/rspec-core/commits/issue-74 Specifically this commit: http://github.com/wincent/rspec-core/commit/8ff5f2d05f37495b2b724535488fceca8bab0466 This commit basically just to show that it works. I'd like to remove the duplication, however, wherein the Not sure which way you'd like to remove this duplication, but the way I'd do it would be something like the following: Make a new method, similar to
Haven't actually done it yet (typed in browser, so usual disclaimers apply). What would you do? |
Yes, much better. |
Cool - I'll merge that to master then. |
it is set in an options file. Closes rspec#74.
One thing which has always bugged me about
it_should_behave_like
is that it requires me to describe my behaviors in terms of a concrete "thing", as opposed to an abstract thing. ie.it_should_behave_like
"this thing" orit_should_behave_like
"that thing"I often find it difficult to describe groups of behavior in this way. For example, I have methods in my
ApplicationController
and I specify their behavior in shared example groups which I then included in the subclasses, but then I find it difficult to name the group and wind up with a bunch of declarations like:What do you think of providing one alias that allows us to labelled shared examples as abstract behaviors rather than concrete things. For example,
it_has_behavior
.Then I could write things like:
Instead of:
At least for me, the former is preferable, and in line with the trend to write out examples without the "should"; ie:
Rather than
What do you think?
The text was updated successfully, but these errors were encountered: