Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
rspec-activemodel-mocks
Advanced tools
RSpec::ActiveModel::Mocks provides tools for testing ActiveModel
classes.
mock_model(Person, name: "Fred")
Add this line to your application's gemfile:
gem 'rspec-activemodel-mocks'
And then execute:
$ bundle
To finish the installation and start using stub_model
and mock_model
, require the
following file in your spec_helper.rb
or rails_helper.rb
.
require 'rspec/active_model/mocks'
Creates a test double representing string_or_model_class
with common
ActiveModel methods stubbed out. Additional methods may be easily stubbed
(via add_stubs
) if stubs
is passed. This is most useful for impersonating
models that don't exist yet.
ActiveModel methods, plus new_record?
, are stubbed out implicitly.
new_record?
returns the inverse of persisted?
, and is present only for
compatibility with extension frameworks that have yet to update themselves to
the ActiveModel API (which declares persisted?
, not new_record?
).
string_or_model_class
can be any of:
ActiveModel::Naming
ActiveModel::Naming
Creates an instance of Model
with to_param
stubbed using a generated value
that is unique to each object. If Model
is an ActiveRecord
model, it is
prohibited from accessing the database.
For each key in stubs
, if the model has a matching attribute (determined by
respond_to?
) it is simply assigned the submitted values. If the model does
not have a matching attribute, the key/value pair is assigned as a stub return
value using RSpec's mocking/stubbing framework.
persisted?
is overridden to return the result of !id.nil?
This means that
by default persisted?
will return true. If you want the object to behave as a
new record, sending it as_new_record
will set the id to nil. You can also
explicitly set :id => nil
, in which case persisted?
will return false, but
using as_new_record
makes the example a bit more descriptive.
While you can use stub_model
in any example (model, view, controller,
helper), it is especially useful in view examples, which are inherently more
state-based than interaction-based.
stub_model(Person)
stub_model(Person).as_new_record
stub_model(Person, :to_param => 37)
stub_model(Person) {|person| person.first_name = "David"}
FAQs
Unknown package
We found that rspec-activemodel-mocks demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers 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
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.