-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Feature: Add TestCase#outline? for conditionals in hooks #728
Conversation
+1 from me. Similar check needed for formatters (from time to time) |
Fantastic, thanks @erran. I think we should try to document this new API with tests. I started this here: https://github.com/cucumber/cucumber/blob/master/spec/cucumber/mappings_spec.rb though perhaps this would be easier to read if we did this in features. WDYT? |
This feature is relevant to this discussion: https://github.com/cucumber/cucumber/blob/master/features/docs/writing_support_code/before_hook.feature |
@mattwynne why do you want to test them in context of hooks? |
@os97673 good question. At the moment they are different objects[1][2], but perhaps we should fix that. [1] https://github.com/cucumber/cucumber/blob/master/lib/cucumber/mappings.rb#L128 TBH, I care a lot more about the hook API than the formatter one, because I want to deprecate the formatter API as soon as possible after we release 2.0, wheras I see the Before / After hooks API lasting a lot longer. That's why I'm concerned about documenting it. |
thank you do explanation. |
Thanks for the input. I was thinking about adding tests, but couldn't determine where they belonged. I think I'll start with Gherkin unless someone thinks RSpec makes more sense. In this case having read through both the before hook feature and the mapping spec I believe the spec would be less clear due to the stubbing/mocking going on. |
@erran sorry it wasn't more obvious where to add tests - that's a codebase usability failure on our part. I've worked on the mapping spec a little to make it a bit easier / more obvious how to add specs. WDYT? |
@mattwynne No problem. I'd rack it up as a fact that this is normally used from a before hook IMO but has impact on report formatters as well. I'll check out the mapping spec before I push my latest changes to the before hook doc feature. Scenario: Examine type of test case
Given a file named "features/foo.feature" with:
"""
Feature: Feature name
Scenario: Scenario name
Given a step
Scenario Outline: Scenario Outline name
Given a step with a <placeholder>
Examples: Examples Table name
| <placeholder> |
| step |
"""
And a file named "features/support/hooks.rb" with:
"""
Before do |test_case|
@test_case = test_case
end
"""
And a file named "features/step_definitions/naughty_steps.rb" with:
"""
Given /^a step$/ do
expect(@test_case).to_not be_an_outline
end
Given /^a step with a (.*)$/ do |_placeholder|
expect(@test_case).to be_an_outline
end
"""
When I run `cucumber`
Then it should pass |
50fe919
to
6ccc717
Compare
I rebased against master and pushed the specs. I'll leave the before hook feature alone since the Ruby code is essentially the same. |
@mattwynne Also, the mapping specs where a lot more clear after your latest changes. 😉 |
@@ -33,7 +33,7 @@ class Mappings | |||
|
|||
describe "#scenario_outline" do | |||
|
|||
it "is thows NoMethodError when the test case is from a scenario" do | |||
it "throws a NoMethodError when the test case is from a scenario" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks :)
Feature: Add TestCase#outline? for conditionals in hooks
Great to see this merged. Thanks guys. 👍 |
Thank you. We’ll put it out in the next beta, probably Friday. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
In Before/After hooks I commonly have a need to type check using the class name. One change I had to make while refactoring for the
2.0.0.beta.2
was updating from the previous Ast classes to the new TestCase mappings for scenarios/outlines. Adding the predicate methodoutline?
provides a quick way to check vs. doing type based conditionals.