No commit activity in last 3 years
No release in over 3 years
A Rails Gem for handling Fixtures without a database. Allows mocks, stubs, hashes, model object, and inserting into the database when you want it to. No need for the bloat of FactoryGirl or other Object Factory Gems.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0

Runtime

>= 4.1.0.beta1
 Project Readme

Warning!!

Deprecated

Going to provide a rails-esque fixture-mock library

FixtureOverlord

  • This is an Alpha version and is currently under heavy development.

Build Status

Code Climate

Setup

require 'minitest/autorun'

class MiniTest::Unit::TestCase
  # include FixtureOverlord's Mixin
  include FixtureOverlord

  # add the fixture accessor that will define 1 method for each YAML file
  # within {spec,test}/fixtures.
  fixture_overloard :rule # set to :off to not define methods
end

How to use in your Tests

Mocks

class GameTest < MiniTest::Unit::TestCase

  # mock will create an OpenStruct Class with accessors
  # to reference the data.
  #
  # Assuming we have a fixture file named games.yml,
  # and inside that file, we have:
  #
  # tron:
  #   name:    'Tron'
  #   type:    'Video Game'
  #   rating:  'Gold'
  #
  #
  # e.g.
  #   OpenStruct.new(hashed_version_of_yaml_file)
  #
  def test_mock_game
    tron = games(:tron).mock

    assert_equal 'Tron',       tron.name
    assert_equal 'Video Game', tron.tyoe
    assert_equal 'Gold',       tron.rating
  end

end

Use as a plain old hash

class GameTest < MiniTest::Unit::TestCase

  # when a fixture is instantiated, it's a hash with super powers,
  # and it's keys are automatically symbolized.
  #
  # games.yml:
  #
  #   tron:
  #     name:    'Tron'
  #     type:    'Video Game'
  #     rating:  'Gold'
  #
  #
  def test_hash_attributes
    tron = games(:tron)

    assert_instance_of Hashish, tron
    assert_equal 'Tron',       tron[:name]
    assert_equal 'Video Game', tron[:type]
    assert_equal 'Gold',       tron[:rating]
  end

end

Remove Attributes

class GameTest < MiniTest::Unit::TestCase

  # removing attributes
  #
  # games.yml:
  #
  #   tron:
  #     name:    'Tron'
  #     type:    'Video Game'
  #     rating:  'Gold'
  #
  #
  def test_hash_attributes
    tron = games(:tron)

    tron.remove(:name)
    assert_nil tron[:name]
  end

end

Add Attributes

class GameTest < MiniTest::Unit::TestCase

  # adding attributes
  #
  # games.yml:
  #
  #   tron:
  #     name:    'Tron'
  #     type:    'Video Game'
  #     rating:  'Gold'
  #
  #
  def test_hash_attributes
    tron = games(:tron)

    tron.add(likes: 20)
    assert_equal 20, tron[:likes]

    tron = tron.mock
    assert_equal 20, tron.likes
  end

end

Change Attributes

class GameTest < MiniTest::Unit::TestCase

  # adding attributes
  #
  # games.yml:
  #
  #   tron:
  #     name:    'Tron'
  #     type:    'Video Game'
  #     rating:  'Gold'
  #
  #
  def test_hash_attributes
    tron = games(:tron)

    tron.change(rating: 'Silver')
    assert_equal 'Silver', tron[:rating]

    tron = tron.mock
    assert_equal 'Silver', tron.rating
  end

end

Create an ActiveRecord Object, but don't save to the database

Create an ActiveRecord Object, and save it to the database

Build Associations