Picture of the author

GAURAV VARMA

← BACK TO BLOG

RSpec 4.0 adds improved DSL and Rails 6.1 compatibility


RSpec 4.0 brings developer-focused enhancements with an improved DSL and seamless integration with Rails 6.1. This version simplifies how we write, generate, and run specs — especially in modern Rails apps.

DSL Improvements

RSpec 4.0 refines its syntax for better readability and expressiveness:

  • Cleaner one-liners and metadata support
  • Better introspection for matchers
  • Smarter defaults in generated spec files

These changes make specs easier to read, write, and maintain — especially helpful in large projects or teams.

Rails 6.1 Compatibility

RSpec 4.0 works out of the box with the latest features from Rails 6.1:

  • Zeitwerk autoloading support
  • Compatibility with ActiveRecord 6.1 APIs
  • Support for ActionMailbox and ActionCable testing
  • Works well with ActiveJob, system specs, and Rails generators

ActionMailbox + ActionCable Testing

RSpec Rails now supports mailbox and channel specs with the corresponding helpers:

1RSpec.describe InboxMailbox, type: :mailbox do
2  it "marks email as delivered" do
3    mail = Mail.new(subject: "[123456] ticket")
4    result = process(mail)
5
6    expect(result).to have_been_delivered
7  end
8end

And for channels:

1RSpec.describe ChatChannel, type: :channel do
2  it "subscribes to a stream" do
3    subscribe
4    expect(subscription).to be_confirmed
5    expect(streams).to include("chat_#{current_user.id}")
6  end
7end

Generator Enhancements

Specs generated via Rails generators are now more aligned with Rails conventions:

  • Uses Ruby 1.9+ hash syntax
  • Defaults to request specs over controller specs
  • New generators for system specs, mailboxes, channels, and more

Additional Highlights

  • Option to disable ActiveRecord: config.use_active_record = false
  • Set ActiveJob.queue_adapter directly in system specs
  • Silences Puma logs in system test output

Links

Summary

RSpec 4.0 makes writing and maintaining tests more intuitive with DSL improvements, modern matchers, and Rails 6.1 compatibility. Whether you’re testing channels, mailboxes, or jobs, this version helps you stay productive and upgrade-ready.