![Maven Central Adds Sigstore Signature Validation](https://cdn.sanity.io/images/cgdhsj6q/production/7da3bc8a946cfb5df15d7fcf49767faedc72b483-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
shoulda-callback-matchers
Advanced tools
Matchers to test before, after and around hooks(currently supports method and object callbacks):
If you fancy maintaining this gem, tweet @beatrichartz and I'll transfer it to you!
Method Callbacks:
describe Post do
it { is_expected.to callback(:count_comments).before(:save) }
it { is_expected.to callback(:post_to_twitter).after(:create) }
it { is_expected.to callback(:evaluate_if_is_should_validate).before(:validation) }
it { is_expected.to callback(:add_some_convenience_accessors).after(:find) }
# with conditions
it { is_expected.to callback(:assign_something).before(:create).if(:this_is_true) }
it { is_expected.to callback(:destroy_something_else).before(:destroy).unless(:this_is_true) }
end
describe User do
it { is_expected.not_to callback(:make_email_validation_ready!).before(:validation).on(:update) }
it { is_expected.to callback(:make_email_validation_ready!).before(:validation).on(:create) }
it { is_expected.to callback(:update_user_count).before(:destroy) }
end
Object Callbacks:
class CallbackClass
def before_save
...
end
def after_create
...
end
def before_validation
...
end
def after_find
...
end
end
describe Post do
it { is_expected.to callback(CallbackClass).before(:save) }
it { is_expected.to callback(CallbackClass).after(:create) }
it { is_expected.to callback(CallbackClass).before(:validation) }
it { is_expected.to callback(CallbackClass).after(:find) }
# with conditions
it { is_expected.to callback(CallbackClass).before(:create).if(:this_is_true) }
it { is_expected.to callback(CallbackClass).after(:find).unless(:is_this_true?) }
end
describe User do
it { is_expected.not_to callback(CallbackClass).before(:validation).on(:update) }
it { is_expected.to callback(CallbackClass).before(:validation).on(:create) }
it { is_expected.to callback(CallbackClass).before(:destroy) }
end
This will test:
Either on the model itself or on the callback object. Be aware that obviously this does not test the callback method or object itself. It makes testing via triggering the callback events (validation, save) unnecessary, but you still have to test the called procedure seperately.
In Rails 3 or 4 and Bundler, add the following to your Gemfile:
group :test do
gem 'shoulda-callback-matchers', '~> 1.1.1'
end
This gem uses semantic versioning, so you won't have incompability issues with patches.
rspec-rails needs to be in the development group so that Rails generators work.
group :development, :test do
gem "rspec-rails"
end
Shoulda will automatically include matchers into the appropriate example groups.
If you're getting this error, it's probably due to classes being redefined by Spring - currently this library does not accommodate for reloaded classes. The easiest fix is to load the matchers into the test library config in your rails_helper.rb
:
RSpec.configure do |config|
config.include(Shoulda::Callback::Matchers::ActiveModel)
end
This gem is maintained by me and its contributors, Shoulda is maintained and funded by thoughtbot
Let's make this gem useful, send me a PR if you've discovered an issue you'd like to fix!
Shoulda is Copyright © 2006-2014 thoughtbot, inc. Callback Matchers is Copyright © 2014 Beat Richartz It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
FAQs
Unknown package
We found that shoulda-callback-matchers demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 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.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.