{"id":22824983,"url":"https://github.com/michaeljklein/nil-passer","last_synced_at":"2026-04-27T23:33:52.961Z","repository":{"id":56885558,"uuid":"84262931","full_name":"michaeljklein/nil-passer","owner":"michaeljklein","description":"Pass nils to single-arg blocks in Ruby on Rails for testing","archived":false,"fork":false,"pushed_at":"2017-12-11T18:04:27.000Z","size":89,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-06T18:50:34.205Z","etag":null,"topics":["nil-passer","rails","ruby","testing-tools"],"latest_commit_sha":null,"homepage":"https://michaeljklein.github.io/nil-passer/","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/michaeljklein.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-08T01:11:19.000Z","updated_at":"2018-03-03T16:26:02.000Z","dependencies_parsed_at":"2022-08-20T13:50:50.311Z","dependency_job_id":null,"html_url":"https://github.com/michaeljklein/nil-passer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaeljklein%2Fnil-passer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaeljklein%2Fnil-passer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaeljklein%2Fnil-passer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaeljklein%2Fnil-passer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/michaeljklein","download_url":"https://codeload.github.com/michaeljklein/nil-passer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246397058,"owners_count":20770481,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nil-passer","rails","ruby","testing-tools"],"created_at":"2024-12-12T17:09:03.149Z","updated_at":"2026-04-27T23:33:50.006Z","avatar_url":"https://github.com/michaeljklein.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nil-Passer \n\n## Status\n\n[![Build Status](https://travis-ci.org/michaeljklein/nil-passer.svg?branch=master)](https://travis-ci.org/michaeljklein/nil-passer)\n\n[![Maintainability](https://api.codeclimate.com/v1/badges/4723ba66092afa0a20e1/maintainability)](https://codeclimate.com/github/michaeljklein/nil-passer/maintainability)\n\n[![Test Coverage](https://api.codeclimate.com/v1/badges/4723ba66092afa0a20e1/test_coverage)](https://codeclimate.com/github/michaeljklein/nil-passer/test_coverage)\n\n[![Gem Version](https://badge.fury.io/rb/nil-passer.svg)](https://badge.fury.io/rb/nil-passer)\n\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/8ec82f7c480c412587116366b89189bf)](https://www.codacy.com/app/michaeljklein/nil-passer?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=michaeljklein/nil-passer\u0026amp;utm_campaign=Badge_Grade)\n\n[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/nil-passer/Lobby?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\n\n## Introduction\n\nEver been sick of blocks not handling nil in Ruby, or more specifically Rails?\n\nThis gem defines the [`NilPasser`](https://github.com/michaeljklein/nil-passer/blob/master/lib/nil_passer.rb#L3) class, which can be used to monitor all passing of blocks on an object, through a specific method, or to a class.\n\nEach block passed is passed `nil` and the execution _usually_ continues normally. (Usually meaning you probably don't want to use this in production.)\n\nDuring or after execution, you can `grep '^[no_nil]'` on your logs to get all the results.\n\nLoosely inspired by the [`bullet`](https://github.com/flyerhzm/bullet) gem.\n\n\n# Examples\n\nFrom [the tests](https://github.com/michaeljklein/nil-passer/blob/master/test/test_nil_passer.rb), we have example usage for \"good, bad, and subtle\" blocks:\n\n\n## Good\n\nThis is the control: we provide the caller's location and the identity (function) block ([source](https://github.com/michaeljklein/nil-passer/blob/master/test/test_nil_passer.rb#L45)):\n\n```\n  def test_test_ignores_good_block\n    assert @log.blank?\n    NilPasser.test [Rails.path], Proc.new{|x| x}\n    assert @log.blank?\n  end\n```\n\n\n## Bad\n\nThis is a simple exception-handling case, where the block accepts `nil` but always raises an exception ([source](https://github.com/michaeljklein/nil-passer/blob/master/test/test_nil_passer.rb#L51)):\n\n```\n  def test_test_catches_bad_block\n    assert  @log.blank?\n    NilPasser.test [Rails.path], Proc.new{|x| (raise \"hi\")}\n    assert !@log.blank?\n  end\n```\n\n\n## Subtle\n\nThis is an example of a block that _only_ raises an exception when passed `nil` ([source](https://github.com/michaeljklein/nil-passer/blob/master/test/test_nil_passer.rb#L57)):\n\n```\n  def test_test_catches_subtle_block\n    assert  @log.blank?\n    NilPasser.test [Rails.path], Proc.new{|x| x.nil? \u0026\u0026 (raise \"hi\")}\n    assert !@log.blank?\n  end\n```\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaeljklein%2Fnil-passer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmichaeljklein%2Fnil-passer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaeljklein%2Fnil-passer/lists"}