JBehave
  1. JBehave
  2. JBEHAVE-733

Composed steps don't behave like steps in a story when using parameters

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 3.5.4
    • Fix Version/s: 3.6
    • Component/s: Core
    • Labels:
      None
    • Environment:
      Windows XP using Eclipse Indigo in Java
    • Testcase included:
      yes
    • Number of attachments :
      1

      Description

      Problem Statement:
      When I use a composite step that calls another step which takes parameters, the correct step is rejected because it doesn't match the patternString.

      Steps to Recreate:
      1. Create a step and method that take a parameter, (ex. @When("I click the $button button")public void clickButton(String button)

      {...}

      2. Create a Composite step that references step 1. (ex. @When("I login")
      @Composite(steps=

      {"I click the login button"}

      )

      Actual Results:
      The second step will give you a pending method, that matches step 1. but they don't match because of the paramter.

      Suggested Change:
      Found this while debugging in the StepCandidate.class on line 179:
      if (StringUtils.startsWith(composedStep, candidate.getStartingWord())
      && StringUtils.endsWith(composedStep, candidate.getPatternAsString()) )

      { return candidate; }

      Could be changed to:

      if (StringUtils.startsWith(composedStep, candidate.getStartingWord())
      && (StringUtils.endsWith(composedStep, candidate.getPatternAsString()) || candidate.matches(composedStep))) { return candidate; }

      JUnit Test:

      @Test
      public void shouldMatchCompositStepsWhenStepParamterIsProvided(){
      CompositeStepParamterMatching steps = new CompositeStepParamterMatching();
      List<StepCandidate> candidates = steps.listCandidates();
      StepCandidate candidate = candidates.get(0);
      assertThat(candidate.isComposite(), is(true));
      Map<String, String> noNamedParameters = new HashMap<String, String>();
      List<Step> composedSteps = new ArrayList<Step>();
      candidate.addComposedSteps(composedSteps, "When I login", noNamedParameters, candidates);
      assertThat(composedSteps.size(), equalTo(2));
      for (Step step : composedSteps)

      { step.perform(null); }

      assertThat(steps.button, equalTo("Login"));
      }

      static class CompositeStepParamterMatching extends Steps {
      private String button;

      @When("I login")
      @Composite(steps=

      {"I click the Login button"}

      )
      public void whenILogin(){}

      @When("I click the <button> button")
      public void whenIClickTheButton(@Named("button") String button)

      { this.button = button; }

      }

        Activity

        David Tanner made changes -
        Field Original Value New Value
        Attachment JunitTest.txt [ 59130 ]
        Hide
        David Tanner added a comment -

        Corrected JUnit Test

        Show
        David Tanner added a comment - Corrected JUnit Test
        David Tanner made changes -
        Attachment JunitTest.txt [ 59131 ]
        Mauro Talevi made changes -
        Fix Version/s 3.6 [ 17721 ]
        Hide
        Mauro Talevi added a comment -

        Applied patch with thanks.

        Show
        Mauro Talevi added a comment - Applied patch with thanks.
        Mauro Talevi made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Hide
        Brian Repko added a comment -

        Not sure that this is really a bug (as this works for me on 3.5.4) and that the patch might need to be removed.
        I think that the step listed in the @Composite needs to have a When put in it.

        @When("I login")
        @Composite(steps=

        {"When I click the Login button"}

        )

        The composite allows you to use Givens/Whens/Thens but you have to specify them.

        Show
        Brian Repko added a comment - Not sure that this is really a bug (as this works for me on 3.5.4) and that the patch might need to be removed. I think that the step listed in the @Composite needs to have a When put in it. @When("I login") @Composite(steps= {"When I click the Login button"} ) The composite allows you to use Givens/Whens/Thens but you have to specify them.
        Hide
        Brian Repko added a comment -

        Oh, take that back. I'm doing this within parameterized scenarios so there may be a bug there - but I think that the When is still required, no?

        Show
        Brian Repko added a comment - Oh, take that back. I'm doing this within parameterized scenarios so there may be a bug there - but I think that the When is still required, no?
        Hide
        David Tanner added a comment -

        I apologize for the confusion, I fixed the junit test and attached it as JunitTest.txt If you run the test, it fails in 3.5.4, but with the change I suggest it works. It can't work otherwise because the text doesn't match. I know it doesn't work because I had to dig through the code to find why it wasn't working.

        Show
        David Tanner added a comment - I apologize for the confusion, I fixed the junit test and attached it as JunitTest.txt If you run the test, it fails in 3.5.4, but with the change I suggest it works. It can't work otherwise because the text doesn't match. I know it doesn't work because I had to dig through the code to find why it wasn't working.

          People

          • Assignee:
            Unassigned
            Reporter:
            David Tanner
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 1 hour
              1h
              Remaining:
              Remaining Estimate - 1 hour
              1h
              Logged:
              Time Spent - Not Specified
              Not Specified