Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
A fast, tiny (82 lines) hybrid mocking library that supports classical and partial mocking. Partial mocking mixes classical mocking with real objects. There's no monkey patching Object
or copying. Mock objects are isolated leaving real objects completely untainted. Plays nicely with MiniTest and RSpec. The interface is 100% compatible with MiniTest::Mock so there is nothing new to learn. SimpleMock's one and only dependancy is Ruby 1.9.2 or greater.
Add this to your project's Gemfile and run $ bundle
.
gem 'simple_mock', :group => :test
SimpleMock is isolated so there is no need to set require to false.
A new SimpleMock object behaves identically to MiniTest::Mock.
mock_model = SimpleMock.new
mock_model.expect :valid?, true
mock_model.valid? # => true
mock_model.verify # => true
Pass an object to mix expectations with the real object's original behaviour.
class Post < ActiveRecord::Base
validates :title, :presence => true
end
real_model = Post.new
mock_model = SimpleMock.new real_model
mock_model.class # => Post
mock_model.expect :valid?, true
mock_model.valid? # => true
mock_model.create # => true
mock_model.verify # => true
This is done with delegation, avoiding monkey patching and copying. The real object is completely untainted.
mock_model.valid # => true
real_model.valid? # => false
real_model.object_id == mock_model.__getobj__.object_id # => true
real_model.object_id != mock_model.object_id # => true
More documentation is available at rubydoc.info.
SimpleMock is fast. In this benchmark we create an array, set an expectation and call that method 10,000 times.
user system total real
mocha: 0.000000 0.000000 0.000000 (0.000279)
simple_mock: 0.000000 0.000000 0.000000 (0.000057)
Like MiniTest::Mock, #expect
and #verify
are reserved methods. Expectations should not be defined on real objects which implement these methods. As an alternative, consider creating an anonymous class which inherits from SimpleDelegator.
mock_class = Class.new SimpleDelegator do
def verify *args
true
end
end
mock_instance = mock_class.new MyRealClass.new
mock_instance.verify # => true
SimpleMock does something similar to this under the hood.
Copyright © 2012 Tate Johnson. SimpleMock is released under the MIT license. See LICENSE for details.
FAQs
Unknown package
We found that simple_mock demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.