Project

nilify

0.0
No commit activity in last 3 years
No release in over 3 years
A ruby gem to simply add mocked methods into a ruby class
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

Nilify

Gem Version CodeClimate

A gem for null object pattern easy implementation on Ruby objects.

Getting started

Nilify works with Ruby 1.9.3 onwards. Install this gem with:

gem install 'nilify'

##Example

Let's check an example for the next Item class.

class Item
	attr_accessor :sku, :title
end

To create a class with mock methods there are two options:

# Option 1
# on the nil class specify the methods to mock
class NilItem
  extend Nilify
  nilify [:sku, :title]
end

# Option 2
# Pass the Item class to mock all the defined methods inside that class.
class NilItem
  extend Nilify
  nilify_from Item
end

Then you can use the mocked methods like this:

> item = Item.new
> item.id
=> nil
> item = NilItem.new
> item.id
=> "id is a mock method"

Contributing

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

Devs

Future

  • Add better examples
  • Add support for ActiveRecord
  • Add conditional mocking
  • Add expected return value
  • Add custom response for mocked methods
  • Add wiki

Credits

Rubixware - hello@rubixware.com

Follow us

Like us on Facebook

License

MIT License. Copyright 2015 Rubixware. http://www.rubixware.com