Socket
Book a DemoInstallSign in
Socket

nilify

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nilify

0.0.6
bundlerRubygems
Version published
Maintainers
1
Created
Source

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

  • Fork it
  • Create your feature branch (git checkout -b my-new-feature)
  • Commit your changes (git commit -am 'Add some feature')
  • Push to the branch (git push origin my-new-feature)
  • 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

FAQs

Package last updated on 28 Sep 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.