From 20ad6953e59175cabab083dd49ecfd6d5ef0c24b Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Mon, 4 Jun 2018 14:03:08 +0200 Subject: [PATCH] Test: custom assertion assert_just_now --- test/chexpire_assertions.rb | 5 +++++ test/jobs/whois_sync_job_test.rb | 4 ---- test/test_helper.rb | 2 ++ test/test_mocks_helper.rb | 4 ++-- 4 files changed, 9 insertions(+), 6 deletions(-) create mode 100644 test/chexpire_assertions.rb diff --git a/test/chexpire_assertions.rb b/test/chexpire_assertions.rb new file mode 100644 index 0000000..453fe79 --- /dev/null +++ b/test/chexpire_assertions.rb @@ -0,0 +1,5 @@ +module ChexpireAssertions + def assert_just_now(expected) + assert_in_delta expected.to_i, Time.now.to_i, 1.0 + end +end diff --git a/test/jobs/whois_sync_job_test.rb b/test/jobs/whois_sync_job_test.rb index 6f649f6..a20089e 100644 --- a/test/jobs/whois_sync_job_test.rb +++ b/test/jobs/whois_sync_job_test.rb @@ -55,8 +55,4 @@ class WhoisSyncJobTest < ActiveJob::TestCase def whois_response(domain) file_fixture("whois/#{domain}.txt").read end - - def assert_just_now(expected) - assert_in_delta expected.to_i, Time.now.to_i, 1.0 - end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 39e0d21..3b99eb7 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -15,6 +15,7 @@ require "rails/test_help" require "minitest/mock" require_relative "test_mocks_helper" +require_relative "chexpire_assertions" class ActiveSupport::TestCase # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. @@ -27,6 +28,7 @@ class ActiveSupport::TestCase include ActiveJob::TestHelper include FactoryBot::Syntax::Methods include TestMocksHelper + include ChexpireAssertions end # Capybara configuration diff --git a/test/test_mocks_helper.rb b/test/test_mocks_helper.rb index 0c931d6..33a7ebb 100644 --- a/test/test_mocks_helper.rb +++ b/test/test_mocks_helper.rb @@ -9,7 +9,7 @@ module TestMocksHelper mock = Minitest::Mock.new mock.expect :execute, result - fussy = lambda { |actual_program, actual_args, _logger| + assert_stub = lambda { |actual_program, actual_args, _logger| assert_equal program, actual_program, "SystemCommand was not initialized with the expected program name" @@ -19,7 +19,7 @@ module TestMocksHelper mock } - SystemCommand.stub :new, fussy do + SystemCommand.stub :new, assert_stub do yield end