Skip to content

Commit 0510fd9

Browse files
committed
init unit tests
1 parent 5735d55 commit 0510fd9

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

spec/hooks_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "spec_helper"

spec/lib/hooks/version_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
describe Hooks::VERSION do
4+
it "has a version number" do
5+
expect(Hooks::VERSION).not_to be nil
6+
expect(Hooks::VERSION).to match(/^\d+\.\d+\.\d+$/)
7+
end
8+
end

spec/spec_helper.rb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# frozen_string_literal: true
2+
3+
require "simplecov"
4+
require "simplecov-erb"
5+
require "rspec"
6+
require "time"
7+
8+
TIME_MOCK = "2025-01-01T00:00:00Z"
9+
10+
COV_DIR = File.expand_path("../coverage", File.dirname(__FILE__))
11+
12+
SimpleCov.root File.expand_path("..", File.dirname(__FILE__))
13+
SimpleCov.coverage_dir COV_DIR
14+
15+
SimpleCov.minimum_coverage 100
16+
17+
SimpleCov.at_exit do
18+
File.write("#{COV_DIR}/total-coverage.txt", SimpleCov.result.covered_percent)
19+
SimpleCov.result.format!
20+
end
21+
22+
SimpleCov.start do
23+
add_filter "config/"
24+
add_filter "spec/"
25+
add_filter "vendor/gems/"
26+
end
27+
28+
# Require all Ruby files in the lib directory
29+
Dir.glob(File.expand_path("../lib/**/*.rb", __dir__)).each do |file|
30+
require file
31+
end
32+
33+
RSpec.configure do |config|
34+
config.before(:each) do
35+
fake_time = Time.parse(TIME_MOCK)
36+
allow(Time).to receive(:now).and_return(fake_time)
37+
allow(Time).to receive(:new).and_return(fake_time)
38+
allow(Time).to receive(:iso8601).and_return(fake_time)
39+
allow(fake_time).to receive(:utc).and_return(fake_time)
40+
allow(fake_time).to receive(:iso8601).and_return(TIME_MOCK)
41+
42+
allow(Kernel).to receive(:sleep)
43+
allow_any_instance_of(Kernel).to receive(:sleep)
44+
allow_any_instance_of(Object).to receive(:sleep)
45+
end
46+
end

0 commit comments

Comments
 (0)