tags:

views:

22

answers:

1

I want to pass YML-like config data to the scenario of cucumber.

for instance:

category:
  subcategory:
    name: whay

how to do this? thanks

+1  A: 

Following a test-driven approach, consider separating the YML parsing logic from your application logic, with something like:

def my_app_logic(my_hash)
  # app logic goes here
end

def my_yml_parsing_logic
  # load a file, or get a yml string
  # parse it and return a hash
end

Then you would write unit tests to check the yml parsing logic and all its edge cases. You can also write unit tests for the app logic without having to worry about yml.

For your cucumber tests, consider mocking up (or using a factory to create) a good hash for testing, and use this hash in your step definition, so you can have a step like:

When I run my app logic on a hash with 5 categories

or something simple like that.

Ben Taitelbaum
Thanks! pretty good point! And I want to know if there are too many mocks, does the cucumber testing make sense?
why
I use cucumber testing for functional and integration testing, so it makes sense from the perspective of defining and testing high-level functionality. I like using stories for BDD to keep me focused in my development effort and make sure I have the core functionality defined and working, so in this sense I would create good data to represent a typical use case. I'm really liking factory girl, since it allows me to use the same factories for rspec and cucumber.
Ben Taitelbaum