# RSpec

RSpec is a behavior-driven development framework for Ruby that provides tools for writing and running executable examples.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## Automatic RSpec Sharding on GitHub Actions

DevFeed: [Automatic RSpec Sharding on GitHub Actions](<https://devfeed.tech/articles/automatic-rspec-sharding-on-github-actions-144065.md>)

Original publisher: [Read original article](<https://code.dblock.org/2026/11/19/automatic-rspec-sharding-on-github-actions.html>)

Author: Daniel Doubrovkine (dblock@dblock.org)

Published: 2026-11-19T00:00:00Z

Content type: tutorial

Language: en

Sources: [Daniel Doubrovkine](<https://devfeed.tech/sources/daniel-doubrovkine.md>)

Topics: [dynamic test splitting](<https://devfeed.tech/topics/dynamic-test-splitting.md>), [RSpec](<https://devfeed.tech/topics/rspec.md>), [GitHub Actions](<https://devfeed.tech/topics/github-actions.md>), [sharding](<https://devfeed.tech/topics/sharding.md>)

Tags: [ci](<https://devfeed.tech/tags/ci.md>), [github-actions](<https://devfeed.tech/tags/github-actions.md>), [rails](<https://devfeed.tech/tags/rails.md>), [rspec](<https://devfeed.tech/tags/rspec.md>), [ruby](<https://devfeed.tech/tags/ruby.md>), [sharding](<https://devfeed.tech/tags/sharding.md>), [testing](<https://devfeed.tech/tags/testing.md>), [timing](<https://devfeed.tech/tags/timing.md>)

### AI overview

The `parallel_tests-ci` reusable GitHub Actions workflow cut Posebook's RSpec time from 395 seconds serially to under 80 seconds on eight workers in every run shown, excluding setup and spec loading. It requires Ruby 3.3 or newer and can run database or other setup commands on each worker. Without timing history, `parallel_tests` groups spec files by size; after successful default-branch pushes, the workflow stores per-file timings in a `runtime.log` artifact. Later runs use the newest available artifact from recent successful runs of the same workflow on the default branch to balance worker loads. Pull requests can use that history but cannot update it.

### Source excerpt

Running RSpec on eight workers got Posebook, a custom Rails CMS, from more than six minutes of RSpec time to about one using parallel_tests-ci that I built to adjust shards automatically as tests get faster or slower, without repeating the GitHub Actions boilerplate for splitting files, running workers, and passing timings between runs. Posebook Benchmarks Each bar shows the slowest worker's RSpec execution time, excluding setup and spec loading. The serial run took 395 seconds. With eight workers, every run shown took less than 80 seconds of RSpec time. Sharding improved further capturing data from previous runs. How to Use It With Ruby 3.3 or newer, add the gem to your Gemfile and run bundle install: gem 'parallel_tests-ci', '0.1.0', require: false In .github/workflows/test.yml, call the reusable workflow at the same version: name: Test on: [push, pull_request] permissions: contents: read actions: read jobs: test: uses: dblock/parallel_tests-ci/.github/workflows/rspec.yml@v0.1.0 with: shards: 8 If your specs need a database or other setup, use the workflow's setup input to run those commands on each worker. How It Works Without timing history, parallel_tests groups spec files by size. After a successful run triggered by a push to the default branch, the workflow saves per-file timings in a runtime.log and uploads it as a GitHub Actions artifact. Before splitting the suite, later runs look for that artifact in recent successful runs of the same workflow on the default branch. They download the newest one still available and use its timings to give each worker roughly the same amount of work. Pull requests can also download the artifact, but cannot update the timing history. Automatic RSpec Sharding on GitHub Actions was originally published by Daniel Doubrovkine at code.dblock.org | tech blog on November 19, 2026.

## From slow tests to slow production: Debugging with Stackprof

DevFeed: [From slow tests to slow production: Debugging with Stackprof](<https://devfeed.tech/articles/from-slow-tests-to-slow-production-debugging-with-stackprof-33519.md>)

Original publisher: [Read original article](<https://www.aha.io/engineering/articles/debugging-with-stack-prof>)

Published: 2026-08-13T00:00:00Z

Content type: tutorial

Language: en

Sources: [Aha! Engineering Blog](<https://devfeed.tech/sources/aha-engineering-blog.md>)

Topics: [debugging](<https://devfeed.tech/topics/debugging.md>), [Developer Tools](<https://devfeed.tech/topics/developer-tools.md>), [RSpec](<https://devfeed.tech/topics/rspec.md>), [Database](<https://devfeed.tech/topics/database.md>)

Tags: [ci](<https://devfeed.tech/tags/ci.md>), [cpu-time](<https://devfeed.tech/tags/cpu-time.md>), [database](<https://devfeed.tech/tags/database.md>), [debugging](<https://devfeed.tech/tags/debugging.md>), [logs](<https://devfeed.tech/tags/logs.md>), [overhead](<https://devfeed.tech/tags/overhead.md>), [performance](<https://devfeed.tech/tags/performance.md>), [production-debugging](<https://devfeed.tech/tags/production-debugging.md>), [profiling](<https://devfeed.tech/tags/profiling.md>), [rspec](<https://devfeed.tech/tags/rspec.md>), [snapshots](<https://devfeed.tech/tags/snapshots.md>), [tests](<https://devfeed.tech/tags/tests.md>), [timing](<https://devfeed.tech/tags/timing.md>)

### AI overview

An investigation into tests that became six times slower traces the stall to code generating example data and Active Record callbacks. The article explains using Stackprof with RSpec to profile the test, including I/O time, and reports that the test spent 71% of its time sleeping.

### Source excerpt

One morning, a developer announced in our Slack channel that some tests were failing on our main branch. The cause of the failures was not obvious. No recent PRs seemed related, and neither the code nor the tests had changed in a long time. The test

## Upgrading Rails 4.2 to Rails 8: Count Sites, Not Warnings

DevFeed: [Upgrading Rails 4.2 to Rails 8: Count Sites, Not Warnings](<https://devfeed.tech/articles/upgrading-rails-4-2-to-rails-8-count-sites-not-warnings-39663.md>)

Original publisher: [Read original article](<https://www.gauravsarma.com/posts/2026-08-08_upgrading-rails-4-to-rails-8>)

Published: 2026-08-08T00:00:00Z

Content type: tutorial

Language: en

Sources: [Gaurav Sarma's](<https://devfeed.tech/sources/gaurav-sarma-s-blog.md>)

Topics: [Ruby on Rails](<https://devfeed.tech/topics/ruby-on-rails.md>), [upgrade](<https://devfeed.tech/topics/upgrade.md>), [version](<https://devfeed.tech/topics/version.md>), [test-coverage](<https://devfeed.tech/topics/test-coverage.md>), [RSpec](<https://devfeed.tech/topics/rspec.md>), [Docker Compose](<https://devfeed.tech/topics/docker-compose.md>), [Ruby](<https://devfeed.tech/topics/ruby.md>)

Tags: [coverage](<https://devfeed.tech/tags/coverage.md>), [docker-compose](<https://devfeed.tech/tags/docker-compose.md>), [rails](<https://devfeed.tech/tags/rails.md>), [rspec](<https://devfeed.tech/tags/rspec.md>), [ruby](<https://devfeed.tech/tags/ruby.md>), [upgrade](<https://devfeed.tech/tags/upgrade.md>), [version](<https://devfeed.tech/tags/version.md>)

### AI overview

An account of upgrading a multi-tenant JSON API from Rails 4.2.7.1 to Rails 8. The author argues that estimates focused on version gates missed the actual risks, and describes how characterization tests, an extracted frontend, and containerized development reduced the work.

### Source excerpt

. [Upgrading Rails 4...

## Writing expressive RSpec tests for Ruby objects and Rails views

DevFeed: [Writing expressive RSpec tests for Ruby objects and Rails views](<https://devfeed.tech/articles/spec-tacular-ways-to-think-about-writing-expressive-rspec-30006.md>)

Original publisher: [Read original article](<https://engineering.freeagent.com/2026/07/07/spec-tacular-ways-to-think-about-writing-expressive-rspec/>)

Author: Simon Fish

Published: 2026-07-07T13:26:00Z

Content type: tutorial

Language: en

Sources: [FreeAgent](<https://devfeed.tech/sources/freeagent.md>)

Topics: [RSpec](<https://devfeed.tech/topics/rspec.md>), [Software Testing](<https://devfeed.tech/topics/software-testing.md>), [Ruby](<https://devfeed.tech/topics/ruby.md>), [Ruby on Rails](<https://devfeed.tech/topics/ruby-on-rails.md>), [render](<https://devfeed.tech/topics/render.md>)

Tags: [rails](<https://devfeed.tech/tags/rails.md>), [render](<https://devfeed.tech/tags/render.md>), [rspec](<https://devfeed.tech/tags/rspec.md>), [ruby](<https://devfeed.tech/tags/ruby.md>), [ruby-on-rails](<https://devfeed.tech/tags/ruby-on-rails.md>), [testing](<https://devfeed.tech/tags/testing.md>), [tooling](<https://devfeed.tech/tags/tooling.md>)

### AI overview

The article explains how to use RSpec expressively to separate test phases, clarify expected behavior, and document interfaces. It also discusses why this approach needs adjustment when testing Rails views, which are rendered templates rather than ordinary Ruby objects.

### Source excerpt

Using RSpec's functionality expressively helps to draw focus to the right parts of a test, but it's not always easy to understand how best to use it.

## How we built a Ruby library that saves 50% in testing time

DevFeed: [How we built a Ruby library that saves 50% in testing time](<https://devfeed.tech/articles/how-we-built-a-ruby-library-that-saves-50-in-testing-time-83498.md>)

Original publisher: [Read original article](<https://www.datadoghq.com/blog/engineering/ruby-test-impact-analysis/>)

Author: Andrey Marchenko; Gillian McGarvey

Published: 2024-11-01T00:00:00Z

Content type: article

Language: en

Sources: [Datadog](<https://devfeed.tech/sources/datadog.md>)

Topics: [Ruby](<https://devfeed.tech/topics/ruby.md>), [Test automation](<https://devfeed.tech/topics/test-automation.md>), [Continuous integration](<https://devfeed.tech/topics/continuous-integration.md>), [RSpec](<https://devfeed.tech/topics/rspec.md>), [Test-driven development](<https://devfeed.tech/topics/tdd.md>)

Tags: [ci](<https://devfeed.tech/tags/ci.md>), [compaction](<https://devfeed.tech/tags/compaction.md>), [intelligent-test-runner](<https://devfeed.tech/tags/intelligent-test-runner.md>), [ruby](<https://devfeed.tech/tags/ruby.md>), [test-impact-analysis](<https://devfeed.tech/tags/test-impact-analysis.md>), [testing](<https://devfeed.tech/tags/testing.md>), [tracing](<https://devfeed.tech/tags/tracing.md>)

### AI overview

Datadog describes building a Ruby library for test impact analysis that maps tests to the source files they execute, enabling selective test runs in CI. The article explains how the team moved from Ruby coverage and TracePoint to interpreter events and allocation tracing, then optimized file tracking to reduce overhead while addressing code-less classes. The resulting tool has a median 25% performance overhead and is reported to be 5-10 times faster than the alternatives the team tried, with known limitations around external processes and data files.

### Source excerpt

Learn how we built a test impact analysis library in Ruby, the challenges we faced, the solutions we found, and what we discovered about tracing the Ruby VM.

## RSpec Tests in Ruby on Rails: Every Spec Type Explained (2026)

DevFeed: [RSpec Tests in Ruby on Rails: Every Spec Type Explained (2026)](<https://devfeed.tech/articles/rspec-tests-in-ruby-on-rails-every-spec-type-explained-2026-90803.md>)

Original publisher: [Read original article](<https://blog.appsignal.com/2024/02/07/a-deep-dive-into-rspec-tests-in-ruby-on-rails.html>)

Author: Thomas Riboulet

Published: 2024-02-07T00:00:00Z

Content type: tutorial

Language: en

Sources: [AppSignal](<https://devfeed.tech/sources/appsignal.md>)

Topics: [RSpec](<https://devfeed.tech/topics/rspec.md>), [Ruby on Rails](<https://devfeed.tech/topics/ruby-on-rails.md>), [Ruby](<https://devfeed.tech/topics/ruby.md>), [Test automation](<https://devfeed.tech/topics/test-automation.md>), [Sidekiq](<https://devfeed.tech/topics/sidekiq.md>)

Tags: [2026](<https://devfeed.tech/tags/2026.md>), [job](<https://devfeed.tech/tags/job.md>), [model](<https://devfeed.tech/tags/model.md>), [rails](<https://devfeed.tech/tags/rails.md>), [request](<https://devfeed.tech/tags/request.md>), [rspec](<https://devfeed.tech/tags/rspec.md>), [ruby](<https://devfeed.tech/tags/ruby.md>), [ruby-on-rails](<https://devfeed.tech/tags/ruby-on-rails.md>), [spec](<https://devfeed.tech/tags/spec.md>), [system](<https://devfeed.tech/tags/system.md>), [tests](<https://devfeed.tech/tags/tests.md>)

### AI overview

The article recommends keeping Rails tests fast by testing models and plain Ruby objects with many focused unit specs, avoiding database access where possible. Use request specs for HTTP behavior across routing, middleware, controllers, and views; they are preferred over legacy controller specs and suit APIs. Reserve slower Capybara system specs for important user flows. The default Selenium driver can run browser tests, while `:rack_test` is faster but does not execute JavaScript; JavaScript flows need a browser driver. Mailer specs should check email headers and content without delivery, and job specs should check whether application code enqueues the right job, queue, and arguments. It also describes installing `rspec-rails` with the Rails generator and notes version 8 supports Rails 7.2 and later.

### Source excerpt

Learn every spec type rspec-rails supports on Rails 8: model, request, system, mailer, and job specs, with setup steps and runnable examples for each.

## How to Use Shoulda Matchers with RSpec for Ruby on Rails

DevFeed: [How to Use Shoulda Matchers with RSpec for Ruby on Rails](<https://devfeed.tech/articles/how-to-use-shoulda-matchers-with-rspec-for-ruby-on-rails-77081.md>)

Original publisher: [Read original article](<https://blog.appsignal.com/2023/12/06/how-to-use-shoulda-matchers-with-rspec-for-ruby-on-rails.html>)

Author: Kingsley Chijioke

Published: 2023-12-06T00:00:00Z

Content type: tutorial

Language: en

Sources: [AppSignal](<https://devfeed.tech/sources/appsignal.md>)

Topics: [RSpec](<https://devfeed.tech/topics/rspec.md>), [Ruby on Rails](<https://devfeed.tech/topics/ruby-on-rails.md>), [Ruby](<https://devfeed.tech/topics/ruby.md>), [Test-driven development](<https://devfeed.tech/topics/tdd.md>), [Test automation](<https://devfeed.tech/topics/test-automation.md>)

Tags: [how-to](<https://devfeed.tech/tags/how-to.md>), [rspec](<https://devfeed.tech/tags/rspec.md>), [ruby](<https://devfeed.tech/tags/ruby.md>), [ruby-on-rails](<https://devfeed.tech/tags/ruby-on-rails.md>)

### AI overview

This tutorial explains how to install and configure shoulda-matchers 8 with RSpec in a Rails app, troubleshoot an undefined matcher error, and use matchers for validations, Active Record behavior, and controller parameters. It also notes setup requirements for uniqueness matchers and version compatibility.

### Source excerpt

Set up shoulda-matchers 8 with RSpec on Rails 8.1: install and configure the gem, fix the validate_presence_of NoMethodError, and use grouped matcher tables.

## Making RSpec Tests More Robust

DevFeed: [Making RSpec Tests More Robust](<https://devfeed.tech/articles/making-rspec-tests-more-robust-21077.md>)

Original publisher: [Read original article](<https://jakeyesbeck.com/2020/07/19/making-rspec-tests-more-robust/>)

Published: 2020-07-19T12:00:00Z

Content type: tutorial

Language: en

Sources: [Jake Yesbeck](<https://devfeed.tech/sources/jake-yesbeck.md>)

Topics: [RSpec](<https://devfeed.tech/topics/rspec.md>), [Ruby](<https://devfeed.tech/topics/ruby.md>), [Software Testing](<https://devfeed.tech/topics/software-testing.md>), [Mocking](<https://devfeed.tech/topics/mocking.md>), [API](<https://devfeed.tech/topics/api.md>), [client](<https://devfeed.tech/topics/client.md>), [HTTP](<https://devfeed.tech/topics/http.md>)

Tags: [api](<https://devfeed.tech/tags/api.md>), [code](<https://devfeed.tech/tags/code.md>), [framework](<https://devfeed.tech/tags/framework.md>), [mocking](<https://devfeed.tech/tags/mocking.md>), [ruby](<https://devfeed.tech/tags/ruby.md>), [testing](<https://devfeed.tech/tags/testing.md>), [tests](<https://devfeed.tech/tags/tests.md>)

### AI overview

This article explains how an RSpec test for Ruby API client code can pass even after the tested method is removed. It shows that mocking the method under test may override its implementation and hide a broken contract. The article recommends stubbing the HTTP client response so the test verifies the request behavior without making a real HTTP request.

### Source excerpt

RSpec is a popular framework for testing Ruby code. With an expect assertion, a developer can make sure their code calls the proper method or an acceptable result is returned. The expect().to receive matcher in a test overrides the default implementation and can cause some unintended side effects. To demonstrate this potential problem, assume a very simple API client exists that can update models. Testing an API Client An example api_client.rb class defines a single put method that calls the underlying API with a Faraday connection. # api_client.rb class APIClient def put(url, body) client.put(url, body) end private def client Faraday.new('https://some-cool-api.com') end end Inheriting from api_client.rb is my_model.rb which defines an update method. # my_model.rb class MyModel < APIClient def update(payload) put('/my_models/1', payload) end end A typical test for the update method on MyModel in RSpec might look like: # my_model_spec.rb describe MyModel do describe 'update' do it 'updates the model' do expect(subject).to receive(:put) subject.update({ foo: :bar }) end end end The subject in the above test is MyModel.new and is expected to receive the method put. Since MyModel#update calls the put method, this seems like a reasonable test. $: rspec my_model_spec.rb . Finished in 0.0054 seconds (files took 0.07101 seconds to load) 1 example, 0 failures Running the test produces a passing result, the MyModel class calls its parent method correctly and all is well. Until something changes that the test is unable to detect. Breaking the Contract If MyModel's contract changes, the test should fail. If, for instance, the put method on the APIClient class is removed or commented out, the update method on MyModel would no longer work. # api_client.rb class APIClient # def put(url, body) # client.put(url, body) # end private def client Faraday.new('https://some-cool-api.com') end end However, the test still passes despite this method being removed. $: rspec my_model_spec.rb .

## Rails Test Basics

DevFeed: [Rails Test Basics](<https://devfeed.tech/articles/rails-test-basics-28258.md>)

Original publisher: [Read original article](<http://fuzzyblog.io/blog/rails/2020/01/27/rails-test-basics.html>)

Author: Fuzzygroup

Published: 2020-01-27T00:00:00Z

Content type: tutorial

Language: en

Sources: [Scott Johnson](<https://devfeed.tech/sources/scott-johnson.md>)

Topics: [Ruby on Rails](<https://devfeed.tech/topics/ruby-on-rails.md>), [Software Testing](<https://devfeed.tech/topics/software-testing.md>), [Test automation](<https://devfeed.tech/topics/test-automation.md>), [RSpec](<https://devfeed.tech/topics/rspec.md>), [Tutorial](<https://devfeed.tech/topics/tutorial.md>), [software-development](<https://devfeed.tech/topics/software-development.md>)

Tags: [basics](<https://devfeed.tech/tags/basics.md>), [rails](<https://devfeed.tech/tags/rails.md>), [rspec](<https://devfeed.tech/tags/rspec.md>), [test](<https://devfeed.tech/tags/test.md>), [testing](<https://devfeed.tech/tags/testing.md>), [tests](<https://devfeed.tech/tags/tests.md>)

### AI overview

The excerpt recaps standard Rails testing in a Jumpstart project: add `byebug` to the Gemfile's development and test groups and require it at the top of `test_helper.rb` to use breakpoints; skip a test with `skip`; and run model tests, a file, the full suite, verbose tests, fail-fast tests, or a line-specific test with the shown `rails test` commands. It notes that a stale line number can yield zero runs and assertions, unlike the author's experience with RSpec. For FactoryBot, it lists adding the test dependency, installing it, creating `test/factories`, including `FactoryBot::Syntax::Methods` in `test_helper.rb`, restarting Spring, and writing a factory-based test. Examples use `assert_equal` and `assert_redirected_to`; other listed assertions include `assert_response`, `assert_difference`, and `assert_match`.

### Source excerpt

More than a decade using RSpec has left me flummoxed in terms of "classical" Rails testing. I'm on a new project built using the Jumpstart application template and all the tests are standard Rails tests so here's a quick recap that I wrote, well, to force myself to step back in time and go "old school". And if you don't like my version then you should really read this. And if you are using Devise for authentication then you really must read this. Making Tests Debuggable The ability to use byebug in a testing context for breakpoints and stepping through code is utterly invaluable. Here's what you need to do for that: Add byebug into a development, test group in Gemfile. Add the line require 'byebug' to the very top of test_helper.rb How Do You Skip a Test? You put the keyword 'skip' at the top of the test that you need to skip. This is equivalent to xit in RSpec. Running Tests The very basic of testing is nothing more than test execution so to run all model tests: rails test test/models/ and to run one file rails test test/models/user_test.rb and to run everything: rails test and to run with verbose mode: rails test -v test/models and to run verbosely and fail on the first test failure: rails test -v -f test/helpers/application_helper.rb and to run just one specific test: rails test test/controllers/labels_controller_test.rb:9 Note: RSpec is very good at running the next test if the line number shifts a bit (example you put in :8 but you added a line so its actually :9). With standard rails test, you get this madness: ❯ rails test test/controllers/projects_controller_test.rb:17 Running via Spring preloader in process 95090 Run options: --seed 52687 # Running: Finished in 0.010622s, 0.0000 runs/s, 0.0000 assertions/s. 0 runs, 0 assertions, 0 failures, 0 errors, 0 skips The 0 runs, 0 assertions, 0 failures, 0 errors, 0 skips can best be interpreted as: Yo! Hoser! I don't know what to do here so I'm going to confuse you deliberately. Ha Haw! Death to Fixtures; Viva La F

## Generating Random Numbers in Ruby: rand, Random & SecureRandom

DevFeed: [Generating Random Numbers in Ruby: rand, Random & SecureRandom](<https://devfeed.tech/articles/generating-random-numbers-in-ruby-rand-random-securerandom-85899.md>)

Original publisher: [Read original article](<https://blog.appsignal.com/2018/07/31/generating-random-numbers-in-ruby.html>)

Author: Joyce Echessa

Published: 2018-07-31T00:00:00Z

Content type: tutorial

Language: en

Sources: [AppSignal](<https://devfeed.tech/sources/appsignal.md>)

Topics: [Ruby](<https://devfeed.tech/topics/ruby.md>), [Test-driven development](<https://devfeed.tech/topics/tdd.md>), [Randomizer](<https://devfeed.tech/topics/randomizer.md>), [RSpec](<https://devfeed.tech/topics/rspec.md>)

Tags: [algorithm](<https://devfeed.tech/tags/algorithm.md>), [api-keys](<https://devfeed.tech/tags/api-keys.md>), [database](<https://devfeed.tech/tags/database.md>), [entropy](<https://devfeed.tech/tags/entropy.md>), [passwords](<https://devfeed.tech/tags/passwords.md>), [random](<https://devfeed.tech/tags/random.md>), [ruby](<https://devfeed.tech/tags/ruby.md>), [tests](<https://devfeed.tech/tags/tests.md>), [tokens](<https://devfeed.tech/tags/tokens.md>)

### AI overview

A practical guide to Ruby randomness explains when to use `rand`, seeded `Random` instances, and `SecureRandom`. It covers ranges, reproducible tests, secure tokens and UUIDs, and when third-party gems can help with statistical distributions or realistic fake data.

### Source excerpt

Learn every way to generate random numbers in Ruby: rand and ranges, seeded Random instances for tests, and SecureRandom for tokens, UUIDs, and passwords.

## A Few RSpec Helpful Hints

DevFeed: [A Few RSpec Helpful Hints](<https://devfeed.tech/articles/a-few-rspec-helpful-hints-21074.md>)

Original publisher: [Read original article](<https://jakeyesbeck.com/2017/07/12/a-few-rspec-helpful-hints/>)

Published: 2017-07-12T12:00:00Z

Content type: tutorial

Language: en

Sources: [Jake Yesbeck](<https://devfeed.tech/sources/jake-yesbeck.md>)

Topics: [RSpec](<https://devfeed.tech/topics/rspec.md>), [Software Testing](<https://devfeed.tech/topics/software-testing.md>), [Ruby](<https://devfeed.tech/topics/ruby.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [developer](<https://devfeed.tech/tags/developer.md>), [ruby](<https://devfeed.tech/tags/ruby.md>), [testing](<https://devfeed.tech/tags/testing.md>), [tests](<https://devfeed.tech/tags/tests.md>)

### AI overview

This tutorial presents practical RSpec techniques for writing Ruby tests that are readable, reusable, and easier to maintain. It covers subject and let variables, loose expectations, argument matchers, and hash matchers.

### Source excerpt

Two main frameworks dominate the Ruby testing world: Rspec and MiniTest. RSpec is a very expressive testing framework with many great features and helpers to make tests readable. When writing RSpec tests, here are just a few not so obvious hints that could make tests even easier to write, read, and maintain. Assuming a system exists with Books and Authors, let's utilize these hints to make testing easy. class Book attr_reader :title, :genre def initialize(title, genre) @title = title @genre = genre end end class Author attr_reader :books def initialize(name, books) @name = name @books = Array(books) end def has_written_a_book? !books.empty? end end subject and let Variables A great way to keep specs DRY and readable are via subject and let variable declarations. For example, if we want to assert an Author has a name, a test without let and subject variables might look something like: describe Author do before do @book_genre = 'Historical Fiction' @book_title = 'A Tale of Two Cities' @book = Book.new(@book_genre, @book_title) @author_name = 'Charles Dickens' @author = Author.new(@author_name, [@book]) end describe '#name'do it 'has a name set' do expect(@author.name).to eq(@author_name) end end end While correct, additional tests asserting number of books, a different name, or other things about this Author could become very verbose. Instead, we can introduce subject and let variables to keep things DRY and reusable: describe Author do let(:book_genre) { 'Historical Fiction' } let(:book_title) { 'A Tale of Two Cities' } let(:book) { Book.new(book_genre, book_title) } let(:book_array) { [book] } let(:author_name) { 'Charles Dickens' } subject { Author.new(author_name, book_array) } describe '#name'do it 'has a name set' do expect(subject.name).to eq(author_name) end end describe '#books' do context 'with books' do it 'has books set' do expect(subject.books).to eq(book_array) end end context 'without books' do context 'books variable is nil' do let(:book_array) { nil }

## Spock tests grouping using @Category from junit

DevFeed: [Spock tests grouping using @Category from junit](<https://devfeed.tech/articles/spock-tests-grouping-using-category-from-junit-27265.md>)

Original publisher: [Read original article](<https://blog.pchudzik.com/201701/spock-groups/>)

Published: 2017-01-14T00:00:00Z

Content type: tutorial

Language: en

Sources: [Paweł Chudzik](<https://devfeed.tech/sources/pawe-chudzik.md>)

Topics: [Gradle](<https://devfeed.tech/topics/gradle.md>), [Software Testing](<https://devfeed.tech/topics/software-testing.md>), [RSpec](<https://devfeed.tech/topics/rspec.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [development](<https://devfeed.tech/tags/development.md>), [gradle](<https://devfeed.tech/tags/gradle.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [junit](<https://devfeed.tech/tags/junit.md>), [testing](<https://devfeed.tech/tags/testing.md>), [tests](<https://devfeed.tech/tags/tests.md>)

### AI overview

This tutorial explains how to group Spock tests with JUnit @Category and configure those groups in Gradle. It uses marker interfaces and a helper class to select which test groups run, allowing slower database tests to be skipped during unrelated development work.

### Source excerpt

When the project gets bigger and bigger there should be more and more tests. In the perfect world, all tests should be executed really fast, but life is far from perfect and sometimes some tests are slow. When using Gradle + Spock combination we have few ways of deciding how to group tests. I'm going to explore junit @Category in combination with Spock and grade. Read more

## How to Write Future-proof Mocks in RSpec 3

DevFeed: [How to Write Future-proof Mocks in RSpec 3](<https://devfeed.tech/articles/how-to-write-future-proof-mocks-in-rspec-3-21051.md>)

Original publisher: [Read original article](<https://jakeyesbeck.com/2015/11/22/how-to-write-futureproof-mocks/>)

Published: 2015-11-22T12:00:00Z

Content type: tutorial

Language: en

Sources: [Jake Yesbeck](<https://devfeed.tech/sources/jake-yesbeck.md>)

Topics: [RSpec](<https://devfeed.tech/topics/rspec.md>), [software-development](<https://devfeed.tech/topics/software-development.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [development](<https://devfeed.tech/tags/development.md>), [tests](<https://devfeed.tech/tags/tests.md>)

### AI overview

This tutorial explains how to write future-proof mocks in RSpec 3. It demonstrates how ordinary doubles can allow tests to pass even after an external service changes its method signature, and recommends verifying doubles to ensure mocked methods exist on the underlying object.

### Source excerpt

Tests are an important component in most software applications. Whether tests drive the development, or are strapped on after the fact, tests need to be reliable for future development to progress. An application's complexity rises with time. During and after this increase, a rock solid test suite is crucial. Let the Dogs Out Given an application that deals with Dogs: class Dog end Keeping track of grooming statistics about this application's dogs is the obvious cash cow. But that sounds very tedious and complicated, so we can assume that a GroomingService exists that exposes a single Groomer object: module GroomingService class Groomer def initialize(dog) @dog = dog end def groom # Some complex grooming logic end end end This service was included by the groomer gem and will become a core piece of the application. To keep everyone in the project sane and well rested, a robust spec suite is needed. Spec It Up Using RSpec and the GroomingService, a very basic test can be written to make sure the code works as expected. Introducing the GroomingService into the Dog class could look like: class Dog def groom GroomingService::Groomer.new(self).groom end end The first test should be to make sure that when the groom method on a Dog is called, it initializes and calls groom out to the GroomService::Groomer object. When asserting that a certain set of methods is called on a particular object, the built in RSpec double method is very handy. The double method returns a stand-in object to assert allow and expect messages against. Any method that is called on the test double which is not explicitly allowed or expected results in an error. describe Dog do subject { described_class.new } describe '#groom' do let(:groomer) { double(GroomingService::Groomer) } it 'initializes and calls groom' do expect(GroomingService::Groomer).to receive(:new) { groomer } expect(groomer).to receive(:groom) subject.groom end end end As expected, this test passes beautifully: $: rspec dog_spec.rb Dog

## Faster Ruby Testing: Only Test What Matters

DevFeed: [Faster Ruby Testing: Only Test What Matters](<https://devfeed.tech/articles/faster-ruby-testing-only-test-what-matters-21035.md>)

Original publisher: [Read original article](<https://jakeyesbeck.com/2015/08/02/test-only-what-matters/>)

Published: 2015-08-02T12:00:00Z

Content type: tutorial

Language: en

Sources: [Jake Yesbeck](<https://devfeed.tech/sources/jake-yesbeck.md>)

Topics: [Software Testing](<https://devfeed.tech/topics/software-testing.md>), [RSpec](<https://devfeed.tech/topics/rspec.md>), [Ruby](<https://devfeed.tech/topics/ruby.md>), [Ruby on Rails](<https://devfeed.tech/topics/ruby-on-rails.md>), [Database](<https://devfeed.tech/topics/database.md>), [software-development](<https://devfeed.tech/topics/software-development.md>)

Tags: [activerecord](<https://devfeed.tech/tags/activerecord.md>), [bugs](<https://devfeed.tech/tags/bugs.md>), [code](<https://devfeed.tech/tags/code.md>), [database](<https://devfeed.tech/tags/database.md>), [development](<https://devfeed.tech/tags/development.md>), [ruby](<https://devfeed.tech/tags/ruby.md>), [ruby-on-rails](<https://devfeed.tech/tags/ruby-on-rails.md>), [speed](<https://devfeed.tech/tags/speed.md>), [testing](<https://devfeed.tech/tags/testing.md>), [tests](<https://devfeed.tech/tags/tests.md>)

### AI overview

This article explains how to make Ruby on Rails tests faster by keeping each test within the responsibility of the method under test. Using RSpec examples, it recommends avoiding unnecessary database writes and asserting method behavior directly when persistence is handled elsewhere.

### Source excerpt

Automated testing is important. Fast, exhaustive automated testing is even more important. Tests are responsible for ensuring the code you spend hours creating actually works. A great test suite can be a safeguard against bugs, a directional guide towards extending the code, and an accurate measurement of the codebase's health. The key to writing good tests is understanding where pieces of responsibility begin and end. Maintaining small concise automated tests can make all the difference. Speed is King Aside from the general importance of short feedback cycles, a fast test suite will greatly improve your work-flow and mood. Conversely, a slow test suite can make your development cycle a living nightmare. How many unfortunate software artisans have dealt with something like: Bleh! What a horrible thing to deal with. What, am I supposed to just wait 5 whole minutes every time I want to test my system? A test suite this slow is simply unacceptable. So what could be causing this slowness? More than likely, a number of tests in this application are doing too much. To try and replicate and solve this problem, let's assume we have a Ruby on Rails application we test using RSpec. Testing Database Models is Slow We can assume that there exists a very important class called MyAwesomeClass: class MyAwesomeClass < ActiveRecord::Base def assign_and_save! saved_on_the_weekend = weekend? self.save! end def weekend? Time.now.saturday? || Time.now.sunday? end end If we wanted to test that the assign_and_save! method works correctly, we might write a test like: describe '#assign_and_save!' do it 'assigns and saves' do awesome_test = MyAwesomeClass.new expect do awesome_test.assign_and_save! end.to change(MyAwesomeClass, :count).by(1) expect(awesome_test.saved_on_the_weekend).to_not be_nil end end These tests make sure that the model is saved correctly to the database and a value is assigned to saved_on_the_weekend. However, the test code is overstepping the boundaries of the method i

## Stricter Tests for Expectations Set on Nil in RSpec

DevFeed: [Stricter Tests for Expectations Set on Nil in RSpec](<https://devfeed.tech/articles/stricter-tests-for-expectations-set-on-nil-in-rspec-15898.md>)

Original publisher: [Read original article](<https://developer.squareup.com/blog/stricter-tests-for-expectations-set-on-nil-in-rspec>)

Author: Square Engineering

Published: 2015-06-19T07:00:00Z

Content type: article

Language: en

Sources: [Square Corner](<https://devfeed.tech/sources/square-corner-blog-medium.md>)

Topics: [RSpec](<https://devfeed.tech/topics/rspec.md>), [Software Testing](<https://devfeed.tech/topics/software-testing.md>)

Tags: [bug](<https://devfeed.tech/tags/bug.md>), [code-review](<https://devfeed.tech/tags/code-review.md>), [config](<https://devfeed.tech/tags/config.md>), [configuration](<https://devfeed.tech/tags/configuration.md>), [context](<https://devfeed.tech/tags/context.md>), [engineering](<https://devfeed.tech/tags/engineering.md>), [errors](<https://devfeed.tech/tags/errors.md>), [expectation](<https://devfeed.tech/tags/expectation.md>), [fail](<https://devfeed.tech/tags/fail.md>), [false-positives](<https://devfeed.tech/tags/false-positives.md>), [framework](<https://devfeed.tech/tags/framework.md>), [logger](<https://devfeed.tech/tags/logger.md>), [logs](<https://devfeed.tech/tags/logs.md>), [maintainers](<https://devfeed.tech/tags/maintainers.md>), [rspec](<https://devfeed.tech/tags/rspec.md>), [tests](<https://devfeed.tech/tags/tests.md>)

### AI overview

The article describes an RSpec mocks configuration for catching false-positive tests caused by setting expectations on nil. Leave the setting unchanged to keep the default warning without failing the test; set `allow_message_expectations_on_nil` to `true` to suppress the warning, or to `false` to make the test raise `RSpec::Mocks::MockExpectationError`. The article also shows how maintainers tested the stricter behavior using isolated configuration so it would not affect the rest of the suite.

### Source excerpt

Make your RSpec tests fail when expectations are set on nil.

## Short Feedback Cycles

DevFeed: [Short Feedback Cycles](<https://devfeed.tech/articles/short-feedback-cycles-21027.md>)

Original publisher: [Read original article](<https://jakeyesbeck.com/2015/06/07/short-feedback-cycles/>)

Published: 2015-06-07T12:00:00Z

Content type: article

Language: en

Sources: [Jake Yesbeck](<https://devfeed.tech/sources/jake-yesbeck.md>)

Topics: [Software Testing](<https://devfeed.tech/topics/software-testing.md>), [RSpec](<https://devfeed.tech/topics/rspec.md>), [software-development](<https://devfeed.tech/topics/software-development.md>), [Code](<https://devfeed.tech/topics/code.md>), [Refactoring](<https://devfeed.tech/topics/refactoring.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [development](<https://devfeed.tech/tags/development.md>), [refactoring](<https://devfeed.tech/tags/refactoring.md>), [testing](<https://devfeed.tech/tags/testing.md>), [tests](<https://devfeed.tech/tags/tests.md>)

### AI overview

The article explains how automated tests and short feedback cycles improve software development. It distinguishes unit and integration tests, emphasizes fast test suites for preventing bugs and easing feature work and refactoring, and describes using Guard to run RSpec tests automatically when code changes.

### Source excerpt

Forty-two days into my year of commits initiative has come and gone. With it, I have found some great processes for making my contributions efficient and effective. Feedback is extremely important when writing software. After all, the code you write is probably designed to work, right? Right. A good way to verify correctness in your software is through automated tests. These can either be unit tests for specific methods and functions or integration tests; those that make sure a complete code path behaves as expected. Regardless, we write these tests to ensure our code works now and in the future. "In the future" is where I have started to contribute to projects. Good projects have test files that the original author(s) provide. Great projects have fast test files that the original author(s) provide. Fast tests provide short feedback cycles. Short feedback cycles prevent bugs and help make new feature development and refactoring much more painless. Feedback governs our behaviors in and outside the development world. Without it, we would not be as efficient or effective at the tasks that are important to us. From writing software to training for a half marathon, feedback matters a great deal. In a recent contribution of mine, I relied heavily on automated testing and short feedback cycles. It was important to me that I was able to identify how the specs were changing as I upgraded them to RSpec 3. I used Guard to help run my tests automatically when any of the code changed. Guard is a tool to automatically run your automated test files as you are making changes to the code. Guard has been around for a long time. I chose to use it due to how simple it is to set up. All you need to do is include the guard-rspec gem in your repository create a Guardfile. An example Guardfile (which exists in the root of your repository) would look something like this: guard :rspec, cmd: 'rspec', notification: false do watch(%r{^spec/.+_spec\.rb$}) watch(%r{^lib/(.+)\.rb$}) { |m| "spec/li

## Kochiku: CI for long test suites

DevFeed: [Kochiku: CI for long test suites](<https://devfeed.tech/articles/kochiku-ci-for-long-test-suites-15736.md>)

Original publisher: [Read original article](<https://developer.squareup.com/blog/kochiku-ci-for-long-test-suites>)

Author: Square Engineering

Published: 2013-09-06T16:04:00Z

Content type: release

Language: en

Sources: [Square Corner](<https://devfeed.tech/sources/square-corner-blog-medium.md>)

Topics: [Continuous integration](<https://devfeed.tech/topics/continuous-integration.md>), [GitHub Actions](<https://devfeed.tech/topics/github-actions.md>), [Ruby](<https://devfeed.tech/topics/ruby.md>), [Ruby on Rails](<https://devfeed.tech/topics/ruby-on-rails.md>), [Cucumber](<https://devfeed.tech/topics/cucumber.md>), [RSpec](<https://devfeed.tech/topics/rspec.md>), [Amazon EC2](<https://devfeed.tech/topics/amazon-ec2.md>), [Selenium](<https://devfeed.tech/topics/selenium.md>)

Tags: [build](<https://devfeed.tech/tags/build.md>), [ci](<https://devfeed.tech/tags/ci.md>), [continuous-integration](<https://devfeed.tech/tags/continuous-integration.md>), [ec2](<https://devfeed.tech/tags/ec2.md>), [engineering](<https://devfeed.tech/tags/engineering.md>), [rails](<https://devfeed.tech/tags/rails.md>), [ruby](<https://devfeed.tech/tags/ruby.md>), [selenium](<https://devfeed.tech/tags/selenium.md>), [tests](<https://devfeed.tech/tags/tests.md>), [unit-tests](<https://devfeed.tech/tags/unit-tests.md>)

### AI overview

Square introduces Kochiku, a continuous integration system that partitions long test suites into distributable chunks and runs them through a queue of build workers.

### Source excerpt

A new Continuous Integration tool from Square