Skip to content

getjets/jets-testing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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).

About

RSpec configurations and utilities for Jets gems, engines and apps.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages