
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
= ModelMocker
This plugin gives you an easy way of generating partially mocked ActiveRecord model objects. This is a useful way of simulating some aspects of a model (like the persistence layer) but leaving the domain logic parts intact, so that you test those in isolation, without worry about database reads and writes.
It's similar to RSpec's mock_model method, but gives you a slightly more declarative way of going about things. I found myself wanting something along these lines a long time ago, and created something very simple that I've used in several projects. More recently I've found myself wanting to easily control certain kinds of behaviour in controller specs, like wanting to ensure that a model instance is valid to allow easy and declarative speccing of the controller.
The plugin adds a mock method to ActiveRecord::Base when mock_models is required, which behaves a lot like AR::Base.new or AR::Base.create, except that you can specify an ID too. Special behaviour is added by passing a block to mock and calling methods on the object it yields.
== Installation
For Rails 2, add model_mocker to your config.gem for the test evironment.
For Rails 3, add model_mocker to your +Gemfile+ in the :test group.
== Requirements
ModelMocker uses the Mocha[http://mocha.rubyforge.org/] Gem.
== Examples
To create a mocked model instance which behaves as it's been fetched from the DB:
ModelClass.mock(:id => 1)
To create one which behaves as if it's a new record
ModelClass.mock { |m| m.as_new_record }
One which is new and will always report that is invalid, whether or not ActiveRecord validations have been met or not.
ModelClass.mock do |m|
m.as_new_record
m.invalid
end
The RDoc for the instance methods on ModelMocker gives a complete rundown of what's possible.
Copyright (c) 2008 Matt Patterson, released under the MIT license
FAQs
Unknown package
We found that model_mocker 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.
Security News
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.