Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Provides datasets to application via yaml files

tree: 235f052a6e

Fetching latest commit…

Cannot retrieve the latest commit at this time


Build Status

An easy to use gem that provides datasets that can be used by your application and tests. The data is stored in yaml files.


In order to use data_magic you will have to inform the gem where it can find the yaml files. You can do this with the following code:

DataMagic.yml_directory = 'data/yml'

If you do not specify a directory the gem will default to using a directory named config/data.

After setting the directory you must load a file. This can be accomplished by calling the load method.

DataMagic.load 'filename.yml'

If you do not specify a filename the gem will attempt to use a file named default.yml. If you are using this for testing you will more than likely want to call load before each test to load the proper data for the spcific test.

The final thing to do is use the data. The gem has a data_for method that will return the data for a specific key. The most common way to use this is to include the DataMagic module in a page-object and then populate a page with the data. Here's an example:

class MyPage
  include PageObject
  include DataMagic


  def populage_page
    populate_page_with data_for :my_page

Notice that I am including the module on line 3. On lin 8 I am calling the data_for method passing the key :my_page. The populate_page_with method is a part of the page-object gem.

Your data might look something like this:

  name: Cheezy
  address: 123 Main Street
  pay_type: 'Credit card'

In order to access the data directly you can just call the method on the module like this:

  my_data = DataMagic.data_for :my_test

Data generators

You can call one of many built-in methods in your yaml file to randomize the data. Here is an example of how you would randomize the above yaml:

  name: ~full_name
  address: ~street_address
  email: ~email_address
  pay_type: ~randomize ['Credit card', 'Purchase order', 'Check']


The rdocs for this project can be found at

To see the changes from release to release please look at the ChangeLog

Known Issues



Please ensure all contributions contain proper tests.

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request


Copyright (c) 2012 Jeffrey S. Morgan. See LICENSE for details.

Something went wrong with that request. Please try again.