Skip to content

Instantly share code, notes, and snippets.

@rhunter
Created October 22, 2013 23:47
Show Gist options
  • Save rhunter/7110157 to your computer and use it in GitHub Desktop.
Save rhunter/7110157 to your computer and use it in GitHub Desktop.
One way to do Cucumber-style scenario tables in RSpec (in reply to @jbrains's question <https://twitter.com/jbrains/status/392794624416579584> )
describe 'scenario tables' do
scenarios = [
{given_balance: 10, when_withdrawing: 10, expected_balance: 0},
{given_balance: 20, when_withdrawing: 10, expected_balance: 10},
{given_balance: 30, when_withdrawing: 30, expected_balance: 0}
]
scenarios.each_with_index do |scenario, n|
context "given a starting balance of #{scenario[:given_balance]} (scenario #{n})" do
it "should have #{scenario[:expected_balance]} left after withdrawing #{scenario[:when_withdrawing]}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment