-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrails_tests.sh
More file actions
executable file
·91 lines (73 loc) · 2.98 KB
/
rails_tests.sh
File metadata and controls
executable file
·91 lines (73 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
TEST_APP_DIR="$PROJECT_ROOT/rails_test_app/logstruct_test_app"
CREATE_APP_SCRIPT="$PROJECT_ROOT/rails_test_app/create_app.rb"
VERSION_FILE="$TEST_APP_DIR/.rails_version"
RAILS_VERSION="${RAILS_VERSION:-"7.1.6"}"
FORCE_RECREATE="${FORCE_RECREATE:-false}"
# Show what we're testing
echo "Testing LogStruct with Rails ${RAILS_VERSION}"
# Check if bundler is installed for current Ruby
if ! gem list -i "^bundler$" > /dev/null 2>&1; then
echo "Installing bundler..."
gem install bundler --no-document
fi
# Check if Rails version file doesn't exist or version has changed
if [ -d "$TEST_APP_DIR" ]; then
if [ ! -f "$VERSION_FILE" ]; then
echo "Rails version file not found. Forcing recreation of test app..."
FORCE_RECREATE="true"
else
PREVIOUS_VERSION=$(cat "$VERSION_FILE")
if [ "$PREVIOUS_VERSION" != "$RAILS_VERSION" ]; then
echo "Rails version changed (${PREVIOUS_VERSION} -> ${RAILS_VERSION})"
echo "Forcing recreation of test app..."
FORCE_RECREATE="true"
fi
fi
fi
# Only recreate the app if FORCE_RECREATE is set or the app doesn't exist
if [ "$FORCE_RECREATE" = "true" ] && [ -d "$TEST_APP_DIR" ]; then
echo "Removing existing test app: $TEST_APP_DIR"
rm -rf "$TEST_APP_DIR"
fi
# Create the test app if it doesn't exist
if [ ! -d "$TEST_APP_DIR" ]; then
echo "Creating Rails test app..."
# Make sure the create_app.rb script exists
if [ ! -f "$CREATE_APP_SCRIPT" ]; then
echo "Error: Create app script not found at $CREATE_APP_SCRIPT"
echo "Make sure all template files are in place before running this script."
exit 1
fi
# Create the test app with the specified Rails version
RAILS_VERSION="$RAILS_VERSION" ruby "$CREATE_APP_SCRIPT"
else
echo "Using existing test app at $TEST_APP_DIR"
# Still copy templates to ensure latest code is used
echo "Updating template files..."
RAILS_VERSION="$RAILS_VERSION" SKIP_APP_CREATION="true" ruby "$CREATE_APP_SCRIPT"
# Make sure the version file is up to date
echo "$RAILS_VERSION" > "$VERSION_FILE"
echo "Updated Rails version file to $RAILS_VERSION"
fi
# Run the tests in the test app
echo "Running integration tests in Rails test app..."
cd "$TEST_APP_DIR"
# Ensure we are not leaking the parent Bundler context into the test app
unset BUNDLE_GEMFILE BUNDLE_PATH BUNDLE_WITH BUNDLE_WITHOUT RUBYOPT GEM_HOME GEM_PATH
export RUBYOPT="-W0"
# Set CI=true so LogStruct is enabled for integration tests
export CI=true
# Install gems locally to avoid issues with world-writable system gem directories on CI
# (Ruby 4.0 bundler rejects reinstalling gems in world-writable directories for security)
export BUNDLE_PATH="$TEST_APP_DIR/vendor/bundle"
# Install gems for the test app under the selected Ruby
bundle install
# Make sure the database is set up
bundle exec rails db:migrate
# Run the tests
bundle exec rails test
echo "All Rails integration tests completed!"