Created
November 8, 2016 23:42
-
-
Save jacobthemyth/29d4fa745fd245ec7ebafceb7018772e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RSpec.describe "Using a table for multiple examples" do | |
def self.define_data_table(name, table_doc) | |
fields, *records = *table_doc.lines.map { |l| l.split('|').map(&:strip).reject(&:empty?) } | |
define_singleton_method(name) { records.map { |r| Hash[fields.map(&:to_sym).zip(r)] } } | |
end | |
define_data_table(:users, <<~USERS) | |
| name | email | twitter | | |
| Aslak | [email protected] | @aslak_hellesoy | | |
| Julien | [email protected] | @jbpros | | |
| Matt | [email protected] | @mattwynne | | |
USERS | |
users.each do |user| | |
it "should have the correct email for #{user[:name]}" do | |
expect(user[:email]).to eq("#{user[:name].downcase}@cucumber.io") | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment