Skip to content

Commit 27efd93

Browse files
committed
test improvements
1 parent c90c766 commit 27efd93

File tree

9 files changed

+52
-11
lines changed

9 files changed

+52
-11
lines changed

.github/copilot-instructions.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,21 @@ script/bootstrap
1717
Ensure all unit tests pass by running the following:
1818

1919
```bash
20-
script/test
20+
script/test # needs to pass and meet the coverage requirements
21+
script/integration # just needs to pass
22+
script/acceptance # just needs to pass
2123
```
2224

23-
This project **requires 100% test coverage** of code, not including:
25+
This project **requires X% test coverage** of code, not including:
2426

2527
- dependencies or their bin scripts
2628
- tests
2729
- scripts in `script/`
2830
- contents of directories that begin with a dot (`.`)
2931

30-
Tests are powered by Ruby's `rspec`. By running `script/test`, the tool `simplecov` will be automatically used and will exit with a non-zero code if the coverage is below 100%.
32+
Tests are powered by Ruby's `rspec`. By running `script/test`, the tool `simplecov` will be automatically used and will exit with a non-zero code if the coverage is below X%.
33+
34+
> The percent coverage required is defined in the `spec/unit/spec_helper.rb` file.
3135
3236
## Linting
3337

@@ -95,5 +99,8 @@ The linter is powered by `rubocop` with its config file located at `.rubocop.yml
9599
- `config/` - Configuration files for the project.
96100
- `lib/` - Main code for the project. This is where the main application/service code lives.
97101
- `spec/` - Tests for the project. This is where the unit tests and acceptance tests live.
102+
- `spec/acceptance/` - Acceptance tests for the project.
103+
- `spec/unit/` - Unit tests for the project.
104+
- `spec/integration/` - Integration tests for the project.
98105
- `vendor/cache` - Vendored dependencies (Ruby Gems).
99106
- `vendor/gems` - Location to which bundler should install the Ruby Gems sourced from `vendor/cache`.

script/integration

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#! /usr/bin/env bash
2+
3+
set -e # prevent any kind of script failures
4+
5+
source script/env "$@"
6+
7+
echo -e "${PURPLE}[#]${OFF} ${BLUE}Running acceptance tests${OFF}"
8+
bundle exec bin/rspec spec/integration && rspec_exit=$? || rspec_exit=$?
9+
echo ""
10+
echo "---------------------------------------"
11+
echo "📊 Summary Results"
12+
echo "---------------------------------------"
13+
echo ""
14+
15+
if [[ $rspec_exit == 0 ]]; then
16+
echo -e "${GREEN}rspec: exitcode=${rspec_exit}${OFF}"
17+
else
18+
echo -e "${RED}rspec: exitcode=${rspec_exit}${OFF}"
19+
fi
20+
21+
[ "$rspec_exit" -gt 0 ] && exit 1
22+
23+
exit 0

script/test

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,23 @@ source script/env "$@"
77
# run tests
88
echo -e "\n🧪 ${BLUE}Running tests: $(date "+%H:%M:%S")${OFF}\n"
99

10-
bundle exec bin/rspec spec && rspec_exit=$? || rspec_exit=$?
10+
bundle exec bin/rspec spec/unit && rspec_exit=$? || rspec_exit=$?
1111

1212
total_coverage=$(cat "$DIR/coverage/total-coverage.txt")
1313

14-
if grep -q "100.0" "$DIR/coverage/total-coverage.txt"; then
14+
# Extract required coverage percentage from the Ruby file
15+
required_coverage=$(grep "REQUIRED_COVERAGE_PERCENTAGE" "$DIR/spec/unit/required_coverage_percentage.rb" | grep -o '[0-9]\+')
16+
17+
# Extract current coverage percentage (remove % sign if present)
18+
current_coverage=$(echo "$total_coverage" | grep -o '[0-9]\+\(\.[0-9]\+\)\?')
19+
20+
# Compare coverage percentages
21+
if (( $(echo "$current_coverage >= $required_coverage" | bc -l) )); then
1522
cov_exit=0
16-
echo -e "\n✅ Total Coverage: ${GREEN}$total_coverage${OFF}"
23+
echo -e "\n✅ Total Coverage: ${GREEN}$total_coverage${OFF} (required: ${required_coverage}%)"
1724
else
1825
cov_exit=1
19-
echo -e "\n❌ Total Coverage: ${RED}$total_coverage${OFF}"
26+
echo -e "\n❌ Total Coverage: ${RED}$total_coverage${OFF} (required: ${required_coverage}%)"
2027
fi
2128

2229
echo ""

spec/lib/hooks/plugins/request_validator/hmac_spec.rb renamed to spec/unit/lib/hooks/plugins/request_validator/hmac_spec.rb

File renamed without changes.
File renamed without changes.
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+
REQUIRED_COVERAGE_PERCENTAGE = 46
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
require "simplecov-erb"
55
require "rspec"
66
require "time"
7+
require_relative "required_coverage_percentage"
78

89
TIME_MOCK = "2025-01-01T00:00:00Z"
910
FAKE_HMAC_SECRET = "octoawesome-secret"
@@ -12,12 +13,12 @@
1213
ENV["GITHUB_WEBHOOK_SECRET"] = FAKE_HMAC_SECRET
1314
ENV["ALT_WEBHOOK_SECRET"] = FAKE_ALT_HMAC_SECRET
1415

15-
COV_DIR = File.expand_path("../coverage", File.dirname(__FILE__))
16+
COV_DIR = File.expand_path("../../coverage", File.dirname(__FILE__))
1617

17-
SimpleCov.root File.expand_path("..", File.dirname(__FILE__))
18+
SimpleCov.root File.expand_path("../..", File.dirname(__FILE__))
1819
SimpleCov.coverage_dir COV_DIR
1920

20-
SimpleCov.minimum_coverage 100
21+
SimpleCov.minimum_coverage REQUIRED_COVERAGE_PERCENTAGE
2122

2223
SimpleCov.at_exit do
2324
File.write("#{COV_DIR}/total-coverage.txt", SimpleCov.result.covered_percent)
@@ -31,7 +32,7 @@
3132
end
3233

3334
# Require all Ruby files in the lib directory
34-
Dir.glob(File.expand_path("../lib/**/*.rb", __dir__)).each do |file|
35+
Dir.glob(File.expand_path("../../lib/**/*.rb", __dir__)).each do |file|
3536
require file
3637
end
3738

0 commit comments

Comments
 (0)