'parse' 是默認的step mathcer, 他被使用最多, 有如下特色正則表達式
'cfparse' 是parse的擴展, 設計初衷是替代parse, 它有如下特色express
're'有如下特色less
# -- FILE: features/environment.py from behave import use_step_matcher # -- SELECT DEFAULT STEP MATCHER: Use "re" matcher as default. # use_step_matcher("parse") # use_step_matcher("cfparse") use_step_matcher("re")
# 簡單的group捕獲, 並賦值給P<test>
# -- SIMPLE GROUP: foo @when(u'I try to match "(?P<foo>foo)"') def step_when_I_try_to_match_foo(context, foo): context.foo = foo # -- SIMPLE GROUP: anything else @when(u'I try to match "(?P<anything>.*)"') def step_when_I_try_to_match_anything_else(context, anything): context.anything = anything
# 可選的的group: (?P<an_>an )?
@when(u'I try to match (?P<an_>an )?optional "(?P<foo>foo)"') def step_when_I_try_to_match_an_optional_foo(context, an_, foo): context.foo = foo context.an_ = an_
# 套嵌的正則
@when(u'I try to match nested "(?P<foo>foo(?P<bar>bar)?)"') def step_when_I_try_to_match_nested_foobar(context, foo, bar): context.foo = foo context.bar = bar