ruby on rails - How to run a Cucumber Background step once for all Scenarios under the same feature? -


in cucumber, possible run background step whole feature? doesn't repeated every scenario?

i running tests on search engine, , need pre-seed search engine test data. since data can quite long generate , process (i'm using elasticsearch , need build indices), i'd rather background once, tests under same feature.

is possible cucumber?

note using mongodb, don't use transactions truncation, , believe have databasecleaner running automatically after each test, suppose i'll have disable (maybe @mention?)

edit :

yes i'm using cucumber ruby steps rails

edit2 : concrete examples

  • i need test search engine return relevant results (eg. when searching "buyers" should return results "buyer", "buying", "purchase", etc. (has es configuration), , other contextual information gets updates correctly (eg in sidebar

  • i have categories/filters number of hits in parenthesis, must make sure number gets refreshed user plays filters)

for pre-seed search engine dozen of results, , run tests based on same inputs. have "example" clauses different, based on same seeding

supposing search data meaningful part of scenario, reading feature should know about, i'd put in step rather hide in hook. there no built-in way of doing want do, need make step idempotent yourself. simplest way use global.

in features/step_definitions/search_steps.rb:

$search_data_initialized = false  given /^there foo, bar , baz$/   # initialize search data   $search_data_initialized = false end 

in features/search.feature:

feature: search    background:     given there foo, bar , baz    scenario: user searches "foo"   ... 

Comments