Skip to content

Commit 19074da

Browse files
committed
running single tests is slow, use spring
1 parent d3f4dbb commit 19074da

File tree

6 files changed

+30
-5
lines changed

6 files changed

+30
-5
lines changed

Gemfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ group :development, :test do
114114
gem "faker"
115115
gem "parallel_tests"
116116
gem "rails-erd"
117-
gem "rubocop-rails"
118-
gem "standard"
117+
gem "rubocop-rails", require: false
118+
gem "standard", require: false
119119
gem "webmock"
120120
end
121121

@@ -149,6 +149,7 @@ group :test do
149149
gem "rspec-request_snapshot", github: "tsubik/rspec-request_snapshot", branch: "fix/ignore-order"
150150
gem "shoulda-matchers", "~> 4.0.1"
151151
gem "simplecov"
152+
gem "spring-commands-rspec"
152153
gem "super_diff"
153154
end
154155

Gemfile.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,9 @@ GEM
724724
simplecov_json_formatter (~> 0.1)
725725
simplecov-html (0.13.1)
726726
simplecov_json_formatter (0.1.4)
727+
spring (4.3.0)
728+
spring-commands-rspec (1.0.4)
729+
spring (>= 0.9.1)
727730
sprockets (4.2.2)
728731
concurrent-ruby (~> 1.0)
729732
logger
@@ -884,6 +887,7 @@ DEPENDENCIES
884887
shoulda-matchers (~> 4.0.1)
885888
sidekiq
886889
simplecov
890+
spring-commands-rspec
887891
sprockets-rails
888892
standard
889893
super_diff

bin/rspec

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env ruby
2+
load File.expand_path("spring", __dir__)
3+
require 'bundler/setup'
4+
load Gem.bin_path('rspec-core', 'rspec')

bin/spring

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env ruby
2+
3+
# This file loads Spring without loading other gems in the Gemfile in order to be fast.
4+
# It gets overwritten when you run the `spring binstub` command.
5+
6+
if !defined?(Spring) && [nil, "development", "test"].include?(ENV["RAILS_ENV"])
7+
require "bundler"
8+
9+
Bundler.locked_gems.specs.find { |spec| spec.name == "spring" }&.tap do |spring|
10+
Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
11+
gem "spring", spring.version
12+
require "spring/binstub"
13+
end
14+
end

config/environments/test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
Rails.application.configure do
1010
# Settings specified here will take precedence over those in config/application.rb.
1111

12-
# While tests run files are not watched, reloading is not necessary.
13-
config.enable_reloading = false
12+
# While tests run files are not watched, reloading is not necessary. (unless you are using Spring)
13+
config.enable_reloading = defined?(Spring)
1414

1515
# Eager loading loads your entire application. When running a single test locally,
1616
# this is usually not necessary, and can slow down your test suite. However, it's

spec/rails_helper.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424

2525
# TODO: try to remove the line below the comment after some time, not sure why this still not working
2626
# see https://github.com/rails/rails/issues/49958
27-
RSpec::Matchers::AliasedNegatedMatcher.undef_method(:with)
27+
# somehow this does not work with spring. I have no time to debug this, only one test is failing without this line
28+
# and mostly using spring to run single tests so this is not a problem for me
29+
RSpec::Matchers::AliasedNegatedMatcher.undef_method(:with) unless defined?(Spring)
2830
RSpec::Matchers.define_negated_matcher :have_not_enqueued_mail, :have_enqueued_mail
2931

3032
# Configuration for Shoulda::Matchers

0 commit comments

Comments
 (0)