Hi Todd,

JBehave parameter matching works different from Cucumber.   It uses
regex parsing under the hood, but it hides away from the user all the
complexity of using regex patterns.

What is allows you as a scenario step writer to do is to identify which
portions of the pattern are parameters, via prefixed keywords, and uses
regex to extract the string values of these parameters.  E.g. using the
examples from
http://jbehave.org/reference/stable/developing-stories.html, let's
consider the pattern:

|||@Given||(||"a stock of symbol $symbol and a threshold of $threshold"||)|

The prefixed keywords are $symbol and $threshold (the prefix symbol is
configurable and has nothing to do with the regex syntax).

So, for a textual step, such as

Given a stock of symbol SBL and a threshold of 10.0

the parameters values extracted are $symbol="SBL" and $threshold="10.0".

JBehave then goes off and try to auto-convert these string value to the
Java types that are declared in the signature of the method, in our case
a String (ie no conversion) and a double.

You can control the parameter conversion as described in
http://jbehave.org/reference/stable/parameter-converters.html.

Hope that makes more sense.  As Paul and Brian have pointed out there
are plenty of examples and tutorials to look at.

Let us know if you have any more questions.

Cheers

On 28/01/2011 17:37, Bradley, Todd wrote:
>
> Hi, I'm a new user of JBehave.  I'm exploring it as a simpler
> alternative to Cuke4Duke (and its required technology stack) since our
> development environments are almost pure Java.
>
>  
>
> I'm doing a proof-of-concept using JBehave to test the product I
> develop, and am writing various story scenarios.  I'm so much happier
> with the "new user" type examples and documentation for JBehave than
> for Cucumber/Cuke4Duke.  But I can't find an example of using a
> regular expression to map a string in a When clause to a Java method.
>
>  
>
> The page http://jbehave.org/reference/latest/developing-stories.html
> says "JBehave maps textual steps to Java methods via CandidateSteps
> <http://jbehave.org/reference/latest/javadoc/core/org/jbehave/core/steps/CandidateSteps.html>.
> The scenario writer need only provide annotated methods that match, by
> regex patterns, the textual steps."  I took that to mean I could do
> something like this in my Java steps file:
>
>  
>
> @Then("I can view files.*")
>
>    public void canViewFiles()
>
>    {
>
> // blah blah blah
>
>    }
>
>  
>
> So that this code would match both
>
>  
>
> Given I open a new web browser
>
> When I connect to http://ViewSVN
>
> Then I can view files without logging in
>
>  
>
> And
>
>  
>
> Given I open a new web browser
>
> When I connect to http://ViewCVS
>
> Then I can view files on my screen
>
>  
>
>  
>
> But the @Then("I can view files.*") doesn't match either of those. 
> Neither does "I can view files(.*)"  So what kind of "regex patterns"
> is the JBehave web page talking about?  Or am I missing the real
> meaning of "The scenario writer need only provide annotated methods
> that match, by regex patterns, the textual steps"?
>
>  
>
>  
>
> Thanks,
>
> Todd.
>

Reply via email to