Socket
Book a DemoInstallSign in
Socket

rspec-radar

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rspec-radar

0.1.0
bundlerRubygems
Version published
Maintainers
1
Created
Source

rspec-radar

rspec-radar monkey patches rspec-mocks to prevent the stubbing of methods that don't exist. If you try and stub a method that doesn't exist, an UndefinedMethodError will be raised.

Usage

Step 1. Add the gem to your gemfile.

  # Gemfile
  gem 'rspec-radar'

Step 2. In the spec_helper.rb file, require 'rspec/radar'

  # spec_helper.rb
  require 'rspec/radar'

Now if you call stub or should_receive on a class or variable, it will check to see if the method exists and raise an exception if it doesn't.

How it works

rspec-radar monkey patches rspec-mocks and will raise an excpetion if you stub a method that doesn't exist. Spefically it alters the method visibility in the class MethodDouble.

Motivations

I want to be able to prevent the stubbing of nonexistent methods when using rspec. Currently there is no way to do this with rspec-mocks. There is a popular mocking alternative called rspec-fire; however, rspec-fire isn't what I am after. rspec-fire introduces a different stubbing syntax and doesn't guard against a stub on an instance variable.

Contributing

I'm more that happy to accept pull-requests. Also, I'm more than happy to receive crticism/suggestions for a better way to make this work.

git clone https://github.com/wusher/rspec-radar.git
bundle install
bundle exec rake spec

Future Plans

The following are features in want to add. (not in any spefic order)

  • make it work when stubbing an entire class ( i.e. stub(Avocado, fake_method: "boom") # raises undefined method error)
  • make it work with any_instance ( i.e. Avocado.any_instance.stub(:fake_method) # raises undefined method error)
  • make the existance checks a configuration option
  • setup stub! so it will skip the existance check`

FAQs

Package last updated on 05 Jan 2013

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.