Skip to content
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

Merged
merged 2 commits into from
Sep 1, 2014

Conversation

erran
Copy link
Contributor

@erran erran commented Aug 30, 2014

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 method outline? provides a quick way to check vs. doing type based conditionals.

@os97673
Copy link
Member

os97673 commented Aug 31, 2014

+1 from me. Similar check needed for formatters (from time to time)
@mattwynne WDYT?

@mattwynne
Copy link
Member

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?

@mattwynne
Copy link
Member

@os97673
Copy link
Member

os97673 commented Sep 1, 2014

@mattwynne why do you want to test them in context of hooks?
I'd expect that every place which may get scenario as param can call it. Do you suggest to write separate test for every case?

@mattwynne
Copy link
Member

@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
[2] https://github.com/cucumber/cucumber/blob/master/lib/cucumber/reports/legacy_formatter.rb#L1223

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.

@os97673
Copy link
Member

os97673 commented Sep 1, 2014

thank you do explanation.

@erran
Copy link
Contributor Author

erran commented Sep 1, 2014

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.

@mattwynne
Copy link
Member

@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?

@erran
Copy link
Contributor Author

erran commented Sep 1, 2014

@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

@erran erran force-pushed the test-case-outline-predicate branch from 50fe919 to 6ccc717 Compare September 1, 2014 15:58
@erran
Copy link
Contributor Author

erran commented Sep 1, 2014

I rebased against master and pushed the specs. I'll leave the before hook feature alone since the Ruby code is essentially the same.

@erran
Copy link
Contributor Author

erran commented Sep 1, 2014

@mattwynne Also, the mapping specs where a lot more clear after your latest changes. 😉

@erran erran changed the title Add TestCase#outline? for conditionals in hooks Feature: Add TestCase#outline? for conditionals in hooks Sep 1, 2014
@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks :)

mattwynne added a commit that referenced this pull request Sep 1, 2014
Feature: Add TestCase#outline? for conditionals in hooks
@mattwynne mattwynne merged commit 4b6a91b into cucumber:master Sep 1, 2014
@erran erran deleted the test-case-outline-predicate branch September 1, 2014 16:33
@erran
Copy link
Contributor Author

erran commented Sep 1, 2014

Great to see this merged. Thanks guys. 👍

@mattwynne
Copy link
Member

Thank you. We’ll put it out in the next beta, probably Friday.

@lock
Copy link

lock bot commented Oct 25, 2018

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.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants