0

I have a set of preferences I want to test the exact same tests for, and make sure they all behave appropriately. So, the for loop would iterate over each preference configuration, and run the same set of tests is the previous and next iteration. *With IF statements of course, so tests that don't apply to the current configuration don't need to be tested.

Is there a way to do this / something similar?

I'm using rails 2.3.8

NullVoxPopuli
  • 61,906
  • 73
  • 206
  • 352
  • This sounds very similar to this question: http://stackoverflow.com/q/7335794/74152 - is it the same situation? – Jon M Sep 08 '11 at 11:34
  • not quite. Mine is more general. – NullVoxPopuli Sep 08 '11 at 13:57
  • 1
    It sounds like my answer to that question could be applicable to you in any case - and [the gem](https://github.com/jmerrifield/cuke_iterations) I linked to would be of use. It lets you specify 'configurations' in an external file with included/excluded tags for each one, then 'tricks' cucumber into running each of your scenarios for each configuration inside a single run. – Jon M Sep 08 '11 at 14:05

3 Answers3

3

Cucumber has a concept called Scenario Outlines that is used to describe a scenario that needs to be run repeatedly with differing data.

jdl
  • 17,702
  • 4
  • 51
  • 54
3

It sounds like you want cucumber example tables, where you can enumerate all your Preference values you want to test the same behavior of:

Given I have a preference defined
When I do some thing
Then I should see this behavior

Examples:
  | preference | label_name |
  | foo        | It's Foo!  |
  | bar        | So bar...  |

Here's a link to a tutorial using table based examples for testing like this:

http://asciicasts.com/episodes/159-more-on-cucumber

Winfield
  • 18,985
  • 3
  • 52
  • 65
  • not quite. the preferences are part of the frontend. but the affect the behavior, what gets rendered, etc. EDIT: nvm, I see what this does. Not quite what I'm lookingfor though. I have a bunch of boolean values that I can mess with. IT would be neat to just iterate over all combinations of them or something. – NullVoxPopuli Sep 06 '11 at 16:16
  • would this method work over multiple scenarios? or even multiple files? – NullVoxPopuli Sep 06 '11 at 16:30
2

This sounds like something you use a scenario outline for:

https://github.com/cucumber/cucumber/wiki/Scenario-outlines

Andy Waite
  • 10,785
  • 4
  • 33
  • 47
  • is there a way to generate that table? My preferences are boolean values. essentially, it'll be like... a 4 bit binary number than I need to iterate over ( the different binary values) – NullVoxPopuli Sep 06 '11 at 16:19
  • would this method work over multiple scenarios? or even multiple files? – NullVoxPopuli Sep 06 '11 at 16:31
  • If you have 4 booleans and you want to test all configurations, that's 256 tests. If you have more than 4 it will quickly become unmanageable. Generally it's not necessary to test every possible combination. Have a look at http://blog.josephwilk.net/ruby/pairwise-testing-with-cucumber.html – Andy Waite Sep 06 '11 at 17:18