-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtest_app.sh
executable file
·77 lines (68 loc) · 2.34 KB
/
test_app.sh
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
#!/bin/bash
#
# Copyright (C) 2021 Sutou Kouhei <[email protected]>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
set -eux
set -o pipefail
export MAKEFLAGS=-j$(nproc)
rails new todo
cd todo
export PATH=$PWD/bin:$PATH
cat >> Gemfile <<GEMFILE
group :development, :test do
gem "test-unit-rails", path: "/source/"
end
GEMFILE
if [[ "${RAILS_VERSION}" =~ ^4 ]]; then
cat >> Gemfile <<GEMFILE
gem 'loofah', '< 2.21.0'
GEMFILE
fi
# For Rails 5 Gemfile
sed -i'' -e "s/gem 'chromedriver-helper'/gem 'webdrivers'/" Gemfile
# Rails 4.x and 5.0 doesn't work with sqlite >= 1.4
if [ $(echo "${RAILS_VERSION} < 5.1" | bc) -eq 1 ]; then
sed -i'' -e "s/gem 'sqlite3'/gem 'sqlite3', '~> 1.3.6'/" Gemfile
fi
# Installing rubygems that includes bundler 1 that is required by Rails 4
if [[ "${RAILS_VERSION}" =~ ^4 ]]; then
gem update --system 3.0.9
# Ruby 2.7's bundled rubygems is so buggy that it ignores required_ruby_version limitation
elif ruby -v | grep -qF 'ruby 2.7.'; then
gem update --system 3.4.22
fi
bundle update
sed -i'' -e 's,rails/test_help,test/unit/rails/test_help,g' test/test_helper.rb
# TODO: Implement.
sed -i'' -e 's/parallelize/# parallelize/g' test/test_helper.rb
if [[ "${RAILS_VERSION}" =~ ^6 ]]; then
rails webpacker:install
fi
rails generate model item name:string
sed -i'' -e 's/# //g' test/models/item_test.rb
rake db:migrate
if [ $(echo "${RAILS_VERSION} >= 5.1" | bc) -eq 1 ]; then
# Test with `rails test` command
rails test -v | tee test.log
grep models: test.log
grep assertions test.log
else
# Test with legacy `rake test` task
rake test:models -v | tee test.log
grep "1 assertions" test.log
rake test -v | tee test.log
grep assertions test.log
fi