Skip to content

Commit 859af30

Browse files
authored
Merge pull request rails#45216 from yahonda/rubocop_minitest_020_enables_skip_ensure_cop
Do not run tests that have `ensure` instead of `skip`
2 parents 2d01da8 + 1b736a8 commit 859af30

File tree

4 files changed

+73
-76
lines changed

4 files changed

+73
-76
lines changed

activerecord/test/cases/connection_adapters/connection_handler_test.rb

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -423,38 +423,38 @@ def test_retrieve_connection_pool_copies_schema_cache_from_ancestor_pool
423423
rd.close
424424
end
425425

426-
def test_pool_from_any_process_for_uses_most_recent_spec
427-
skip unless current_adapter?(:SQLite3Adapter)
426+
if current_adapter?(:SQLite3Adapter)
427+
def test_pool_from_any_process_for_uses_most_recent_spec
428+
file = Tempfile.new "lol.sqlite3"
428429

429-
file = Tempfile.new "lol.sqlite3"
430+
rd, wr = IO.pipe
431+
rd.binmode
432+
wr.binmode
430433

431-
rd, wr = IO.pipe
432-
rd.binmode
433-
wr.binmode
434+
pid = fork do
435+
config_hash = ActiveRecord::Base.configurations.configs_for(env_name: "arunit", name: "primary").configuration_hash.merge(database: file.path)
436+
ActiveRecord::Base.establish_connection(config_hash)
434437

435-
pid = fork do
436-
config_hash = ActiveRecord::Base.configurations.configs_for(env_name: "arunit", name: "primary").configuration_hash.merge(database: file.path)
437-
ActiveRecord::Base.establish_connection(config_hash)
438+
pid2 = fork do
439+
wr.write ActiveRecord::Base.connection_db_config.database
440+
wr.close
441+
end
438442

439-
pid2 = fork do
440-
wr.write ActiveRecord::Base.connection_db_config.database
441-
wr.close
443+
Process.waitpid pid2
442444
end
443445

444-
Process.waitpid pid2
445-
end
446-
447-
Process.waitpid pid
446+
Process.waitpid pid
448447

449-
wr.close
448+
wr.close
450449

451-
assert_equal file.path, rd.read
450+
assert_equal file.path, rd.read
452451

453-
rd.close
454-
ensure
455-
if file
456-
file.close
457-
file.unlink
452+
rd.close
453+
ensure
454+
if file
455+
file.close
456+
file.unlink
457+
end
458458
end
459459
end
460460
end

activerecord/test/cases/query_cache_test.rb

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -565,37 +565,38 @@ def test_query_cache_is_enabled_on_all_connection_pools
565565
}.call({})
566566
end
567567

568-
def test_clear_query_cache_is_called_on_all_connections
569-
skip "with in memory db, reading role won't be able to see database on writing role" if in_memory_db?
570-
571-
ActiveRecord::Base.connected_to(role: :reading) do
572-
db_config = ActiveRecord::Base.configurations.configs_for(env_name: "arunit", name: "primary")
573-
ActiveRecord::Base.establish_connection(db_config)
574-
end
575-
576-
mw = middleware { |env|
568+
# with in memory db, reading role won't be able to see database on writing role
569+
unless in_memory_db?
570+
def test_clear_query_cache_is_called_on_all_connections
577571
ActiveRecord::Base.connected_to(role: :reading) do
578-
@topic = Topic.first
572+
db_config = ActiveRecord::Base.configurations.configs_for(env_name: "arunit", name: "primary")
573+
ActiveRecord::Base.establish_connection(db_config)
579574
end
580575

581-
assert @topic
576+
mw = middleware { |env|
577+
ActiveRecord::Base.connected_to(role: :reading) do
578+
@topic = Topic.first
579+
end
582580

583-
ActiveRecord::Base.connected_to(role: :writing) do
584-
@topic.title = "Topic title"
585-
@topic.save!
586-
end
581+
assert @topic
587582

588-
assert_equal "Topic title", @topic.title
583+
ActiveRecord::Base.connected_to(role: :writing) do
584+
@topic.title = "Topic title"
585+
@topic.save!
586+
end
589587

590-
ActiveRecord::Base.connected_to(role: :reading) do
591-
@topic = Topic.first
592588
assert_equal "Topic title", @topic.title
593-
end
594-
}
595589

596-
mw.call({})
597-
ensure
598-
clean_up_connection_handler
590+
ActiveRecord::Base.connected_to(role: :reading) do
591+
@topic = Topic.first
592+
assert_equal "Topic title", @topic.title
593+
end
594+
}
595+
596+
mw.call({})
597+
ensure
598+
clean_up_connection_handler
599+
end
599600
end
600601

601602
test "query cache is enabled in threads with shared connection" do

railties/test/console_helpers.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ def assert_output(expected, io, timeout = 10)
1818

1919
assert_includes output, expected, "#{expected.inspect} expected, but got:\n\n#{output}"
2020
end
21+
end
2122

22-
def available_pty?
23-
defined?(PTY) && PTY.respond_to?(:open)
24-
end
23+
def available_pty?
24+
defined?(PTY) && PTY.respond_to?(:open)
2525
end

railties/test/engine/commands_test.rb

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,35 +30,31 @@ def test_runner_command_work_inside_engine
3030
assert_equal "test", output.strip
3131
end
3232

33-
def test_console_command_work_inside_engine
34-
skip "PTY unavailable" unless available_pty?
35-
36-
primary, replica = PTY.open
37-
cmd = "console --singleline"
38-
spawn_command(cmd, replica)
39-
assert_output(">", primary)
40-
ensure
41-
primary.puts "quit"
42-
end
43-
44-
def test_dbconsole_command_work_inside_engine
45-
skip "PTY unavailable" unless available_pty?
46-
47-
primary, replica = PTY.open
48-
spawn_command("dbconsole", replica)
49-
assert_output("sqlite>", primary)
50-
ensure
51-
primary.puts ".exit"
52-
end
33+
if available_pty?
34+
def test_console_command_work_inside_engine
35+
primary, replica = PTY.open
36+
cmd = "console --singleline"
37+
spawn_command(cmd, replica)
38+
assert_output(">", primary)
39+
ensure
40+
primary.puts "quit"
41+
end
5342

54-
def test_server_command_work_inside_engine
55-
skip "PTY unavailable" unless available_pty?
43+
def test_dbconsole_command_work_inside_engine
44+
primary, replica = PTY.open
45+
spawn_command("dbconsole", replica)
46+
assert_output("sqlite>", primary)
47+
ensure
48+
primary.puts ".exit"
49+
end
5650

57-
primary, replica = PTY.open
58-
pid = spawn_command("server", replica)
59-
assert_output("Listening on", primary)
60-
ensure
61-
kill(pid)
51+
def test_server_command_work_inside_engine
52+
primary, replica = PTY.open
53+
pid = spawn_command("server", replica)
54+
assert_output("Listening on", primary)
55+
ensure
56+
kill(pid)
57+
end
6258
end
6359

6460
private

0 commit comments

Comments
 (0)