0.0
No commit activity in last 3 years
No release in over 3 years
Common configuration for RSpec and a dummy application
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 13.0

Runtime

 Project Readme

Jets Testing

RSpec configurations and utils for usage in gems, engines and apps.

Installation

Add this line to your application's Gemfile:

gem "jets-testing"

or to your engine's Gemfile and .gemspec:

# Gemfile
gem "jets-testing"

# .gemspec
s.add_development_dependency "jets-rubocop"

Usage

This gem provides two configurations, which could be loaded via:

  • require "jets/testing/rspec_configuration" – this is RSpec core configuration, which must be added to your spec_helper.rb; it doesn't contain anything Rails specific
  • require "jets/testing/rails_configuration" – typical RSpec config for Rails, which includes a lot of useful stuff (see below); require it in your rails_helper.rb`.

Tools

Here is the list of gems included into Rails config:

You can also add a dummy Rails app (in case of gem/engine) using combustion gem, which is included, too. For example:

require "jets/testing/rails_configuration"

require "combustion"

Combustion.initialize! :action_controller, :active_record, :active_job, :action_mailer do
  config.logger = Logger.new(nil)
  config.log_level = :fatal

  config.active_record.raise_in_transactional_callbacks = true

  config.active_job.queue_adapter = :test
end

Additional configuration could be added under spec/internal.

Helpers

  • fixture_file_path(*args) – returns path to a file fixture (based on fixture_path)

  • mails_for(email_or_user) - returns a proxy for user's emails; useful to test that an email has been sent and it's contents, for example:

mailbox = mails_for(user) # or mails_for(email)
expect { subject }.to change(mailbox, :size).by(1)
expect(mailbox.last.subject).to eq "Hey, you got an email!"

Shared Contexts

  • "active_job:perform" (active_job: :perform) – perform enqueued Active Job jobs automatically
  • "csrf:on" (csrf: :on) – turn on CSRF protection for ActionController::Base (it's off by default in specs)
  • "shared:request" (type: :request, i.e. included automatically) – add json_response method and declare subject for request specs (see testing guide).