Skip to content

Commit

Permalink
Fix CI env variables
Browse files Browse the repository at this point in the history
  • Loading branch information
westonganger committed Aug 20, 2024
1 parent d81a122 commit f779579
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 13 deletions.
22 changes: 12 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,31 @@ jobs:
### TEST RUBY VERSIONS
- ruby: "2.7"
- ruby: "3.0"
db_gem_version: "~> 1.4" # fixes sqlite3 gem dependency issue
- ruby: "3.1"
- ruby: "3.2"
- ruby: "3.3"
### TEST RAILS VERSIONS
- ruby: "2.7"
env:
RAILS_VERSION: "6.0"
rails_version: "~> 6.0"
- ruby: "2.7"
env:
RAILS_VERSION: "6.1"
rails_version: "~> 6.1"
- ruby: "3.3"
env:
RAILS_VERSION: "7.0"
rails_version: "~> 7.0"
- ruby: "3.3"
env:
RAILS_VERSION: "7.1"
rails_version: "~> 7.1"
- ruby: "3.3"
env:
RAILS_VERSION: "7.2"
rails_version: "~> 7.2"

steps:
- uses: actions/checkout@v3

- name: Set env variables
run: |
echo "RAILS_VERSION=${{ matrix.rails_version }}" >> "$GITHUB_ENV"
echo "DB_GEM=${{ matrix.db_gem }}" >> "$GITHUB_ENV"
echo "DB_GEM_VERSION=${{ matrix.db_gem_version }}" >> "$GITHUB_ENV"
- name: Install ruby
uses: ruby/setup-ruby@v1
with:
Expand Down
5 changes: 2 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ end

gem "rails", get_env("RAILS_VERSION")

db_gem = get_env("DB_GEM") || "sqlite3"
gem db_gem, get_env("DB_GEM_VERSION")

if get_env("RAILS_VERSION").to_f >= 7.2
gem "activerecord-enhancedsqlite3-adapter"
gem "sqlite3", "~> 2.0"
else
gem "sqlite3", "~> 1.7"
end

group :development do
Expand Down
50 changes: 50 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,53 @@

config.filter_rails_from_backtrace!
end

if Rails::VERSION::MAJOR <= 6
ActiveSupport::Testing::Assertions.module_eval do
def assert_difference(expression, *args, &block)
expressions =
if expression.is_a?(Hash)
message = args[0]
expression
else
difference = args[0] || 1
message = args[1]
Array(expression).index_with(difference)
end

exps = expressions.keys.map { |e|
e.respond_to?(:call) ? e : lambda { eval(e, block.binding) }
}
before = exps.map(&:call)

retval = _assert_nothing_raised_or_warn("assert_difference", &block)

expressions.zip(exps, before) do |(code, diff), exp, before_value|
actual = exp.call
error = "#{code.inspect} didn't change by #{diff}, but by #{actual - before_value}"
error = "#{message}.\n#{error}" if message
assert_equal(before_value + diff, actual, error)
end

retval
end

private

def _assert_nothing_raised_or_warn(assertion, &block)
assert_nothing_raised(&block)
rescue Minitest::UnexpectedError => e
if tagged_logger && tagged_logger.warn?
warning = <<~MSG
#{self.class} - #{name}: #{e.error.class} raised.
If you expected this exception, use `assert_raises` as near to the code that raises as possible.
Other block based assertions (e.g. `#{assertion}`) can be used, as long as `assert_raises` is inside their block.
MSG
tagged_logger.warn warning
end

raise
end

end
end

0 comments on commit f779579

Please sign in to comment.