Skip to content

Commit a7ecd9f

Browse files
authored
Merge pull request #154 from rsim/feature/minitest
Migrate from RSpec to Minitest
2 parents c61f571 + 147cedc commit a7ecd9f

27 files changed

Lines changed: 1475 additions & 1476 deletions

.github/workflows/clickhouse/download.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ set -ev
66
# Check https://github.com/ClickHouse/clickhouse-java/releases for latest version
77
CLICKHOUSE_JDBC_VERSION=0.9.6
88
wget https://repo1.maven.org/maven2/com/clickhouse/clickhouse-jdbc/${CLICKHOUSE_JDBC_VERSION}/clickhouse-jdbc-${CLICKHOUSE_JDBC_VERSION}-all.jar
9-
cp clickhouse-jdbc-${CLICKHOUSE_JDBC_VERSION}-all.jar spec/support/jars/
9+
cp clickhouse-jdbc-${CLICKHOUSE_JDBC_VERSION}-all.jar test/support/jars/
1010

1111
# Download SLF4J dependencies (required for ClickHouse JDBC driver logging)
1212
SLF4J_VERSION=2.0.17
1313
wget https://repo1.maven.org/maven2/org/slf4j/slf4j-api/${SLF4J_VERSION}/slf4j-api-${SLF4J_VERSION}.jar
1414
wget https://repo1.maven.org/maven2/org/slf4j/slf4j-simple/${SLF4J_VERSION}/slf4j-simple-${SLF4J_VERSION}.jar
15-
cp slf4j-api-${SLF4J_VERSION}.jar spec/support/jars/
16-
cp slf4j-simple-${SLF4J_VERSION}.jar spec/support/jars/
15+
cp slf4j-api-${SLF4J_VERSION}.jar test/support/jars/
16+
cp slf4j-simple-${SLF4J_VERSION}.jar test/support/jars/
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
wget https://download.microsoft.com/download/4/D/C/4DCD85FA-0041-4D2E-8DD9-833C1873978C/sqljdbc_7.2.2.0_enu.tar.gz
22
tar xzf sqljdbc_7.2.2.0_enu.tar.gz
3-
cp sqljdbc_7.2/enu/mssql-jdbc-7.2.2.jre8.jar spec/support/jars
3+
cp sqljdbc_7.2/enu/mssql-jdbc-7.2.2.jre8.jar test/support/jars

.github/workflows/tests.yml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ env:
1111
JRUBY_OPTS: -W0
1212

1313
jobs:
14-
rspec:
14+
test:
1515
runs-on: ubuntu-24.04
1616
strategy:
1717
fail-fast: false
@@ -23,9 +23,8 @@ jobs:
2323
JAVA_VERSION: 11
2424
- JRUBY_VERSION: 9.4.14.0
2525
JAVA_VERSION: 17
26-
# Tests on JRuby 10 are failing due to https://github.com/jruby/jruby/issues/8987
27-
# - JRUBY_VERSION: 10.0.2.0
28-
# JAVA_VERSION: 21
26+
- JRUBY_VERSION: 10.0.4.0
27+
JAVA_VERSION: 21
2928
env:
3029
JRUBY_VERSION: ${{ matrix.JRUBY_VERSION }}
3130
JAVA_VERSION: ${{ matrix.JAVA_VERSION }}
@@ -98,15 +97,15 @@ jobs:
9897
- name: Run Tests
9998
run: |
10099
for driver in mysql postgresql oracle sqlserver; do
101-
MONDRIAN_DRIVER=$driver bundle exec rake spec
100+
MONDRIAN_DRIVER=$driver bundle exec rake test
102101
done
103102
- name: Export test data and run ClickHouse tests
104103
run: |
105104
MONDRIAN_DRIVER=mysql bundle exec rake db:export_data
106105
MONDRIAN_DRIVER=clickhouse bundle exec rake db:create_data
107-
MONDRIAN_DRIVER=clickhouse bundle exec rake spec
106+
MONDRIAN_DRIVER=clickhouse bundle exec rake test
108107
109-
windows-rspec:
108+
windows-test:
110109
runs-on: windows-2025
111110
strategy:
112111
fail-fast: false
@@ -118,8 +117,8 @@ jobs:
118117
JAVA_VERSION: 11
119118
- JRUBY_VERSION: 9.4.14.0
120119
JAVA_VERSION: 17
121-
# - JRUBY_VERSION: 10.0.2.0
122-
# JAVA_VERSION: 21
120+
- JRUBY_VERSION: 10.0.4.0
121+
JAVA_VERSION: 21
123122
env:
124123
JRUBY_VERSION: ${{ matrix.JRUBY_VERSION }}
125124
JAVA_VERSION: ${{ matrix.JAVA_VERSION }}
@@ -150,7 +149,7 @@ jobs:
150149
run: |
151150
Invoke-WebRequest -Uri "https://download.microsoft.com/download/4/D/C/4DCD85FA-0041-4D2E-8DD9-833C1873978C/sqljdbc_7.2.1.0_enu.exe" -OutFile "sqljdbc_7.2.1.0_enu.exe"
152151
7z x sqljdbc_7.2.1.0_enu.exe -y > nul
153-
Copy-Item -Path "sqljdbc_7.2\enu\mssql-jdbc-7.2.1.jre8.jar" -Destination "spec\support\jars\"
152+
Copy-Item -Path "sqljdbc_7.2\enu\mssql-jdbc-7.2.1.jre8.jar" -Destination "test\support\jars\"
154153
- name: Setup Ruby and install gems
155154
uses: ruby/setup-ruby@v1
156155
with:
@@ -164,4 +163,4 @@ jobs:
164163
- name: Create Database Data
165164
run: bundle exec rake db:create_data
166165
- name: Run Tests
167-
run: bundle exec rake spec:sqlserver
166+
run: bundle exec rake test:sqlserver

.rspec

Lines changed: 0 additions & 2 deletions
This file was deleted.

AGENTS.md

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,18 @@ mondrian-olap is a JRuby gem for performing multidimensional queries of relation
3636

3737
### Making Changes
3838

39-
1. **Adding new schema features** - Modify `lib/mondrian/olap/schema.rb` and add corresponding specs in
40-
`spec/schema_definition_spec.rb`
41-
2. **Extending query capabilities** - Update `lib/mondrian/olap/query.rb` and test in `spec/query_spec.rb`
42-
3. **Connection enhancements** - Change `lib/mondrian/olap/connection.rb` with tests in `spec/connection_spec.rb`
43-
4. **Cube operations** - Modify `lib/mondrian/olap/cube.rb` and add specs in `spec/cube_spec.rb`
39+
1. **Adding new schema features** - Modify `lib/mondrian/olap/schema.rb` and add corresponding tests in
40+
`test/schema_definition_test.rb`
41+
2. **Extending query capabilities** - Update `lib/mondrian/olap/query.rb` and test in `test/query_test.rb`
42+
3. **Connection enhancements** - Change `lib/mondrian/olap/connection.rb` with tests in `test/connection_test.rb`
43+
4. **Cube operations** - Modify `lib/mondrian/olap/cube.rb` and add tests in `test/cube_test.rb`
4444

4545
### Testing Changes
4646

47-
1. Write or update RSpec tests for the changed functionality.
48-
2. Run specific test file: `rspec spec/cube_spec.rb`.
49-
3. Run all tests with default database: `rake spec`.
50-
4. Test with specific databases: `rake spec:postgresql`, `rake spec:mysql`, etc.
47+
1. Write or update Minitest tests for the changed functionality.
48+
2. Run specific test file: `ruby -Itest test/cube_test.rb`.
49+
3. Run all tests with default database: `rake test` (with the default `mysql` database).
50+
4. Test with specific databases: `rake test:mysql`, `rake test:postgresql`, `rake test:sqlserver`, `rake test:oracle`.
5151
5. Ensure tests pass with multiple database backends before finalizing changes.
5252

5353
## Technology Stack
@@ -56,7 +56,7 @@ mondrian-olap is a JRuby gem for performing multidimensional queries of relation
5656
- **Java** 8 or later LTS version
5757
- **Mondrian OLAP** Java library from a fork https://github.com/rsim/mondrian-olap-java
5858
- **Databases**: PostgreSQL, MySQL, Oracle, Microsoft SQL Server, ClickHouse or other JDBC compatible databases
59-
- **Testing**: RSpec
59+
- **Testing**: Minitest (with minitest-hooks)
6060

6161
### JRuby-Specific Considerations
6262

@@ -101,16 +101,28 @@ mondrian-olap is a JRuby gem for performing multidimensional queries of relation
101101
### mise
102102

103103
- mise might be used to manage Ruby and Java versions.
104-
- If mise is available then prefix ruby, rspec, rake, java calls with `mise exec --` to initialize the correct environment.
104+
- If mise is available then prefix ruby, rake, java calls with `mise exec --` to initialize the correct environment.
105105

106106
### Testing
107107

108-
- Use RSpec for Ruby testing.
109-
- Run individual RSpec test file with e.g. `rspec spec/cube_spec.rb`.
110-
- Run all RSpec tests with `rake spec` (with the default `mysql` database).
108+
- Use Minitest for Ruby testing with the minitest-hooks gem for lifecycle hooks.
109+
- Run individual test file with e.g. `ruby -Itest test/cube_test.rb`.
110+
- Run all tests with `rake test` (with the default `mysql` database).
111111
- Run all tests with a specified database:
112-
`rake spec:mysql`, `rake spec:postgresql`, `rake spec:sqlserver`, `rake spec:oracle`
113-
- In most cases use RSpec should syntax and not expect syntax, for example, `result.should == expected`.
114-
- Use RSpec expect syntax only for block expectations, for example, `expect { action }.to raise_error(SomeError)`.
115-
- Test data is located in `spec/support/data/` directory.
116-
- Database-specific schema fixtures are in `spec/fixtures/` directory.
112+
`rake test:mysql`, `rake test:postgresql`, `rake test:sqlserver`, `rake test:oracle`.
113+
- Use Minitest Spec-style syntax with `describe` and `it` blocks. Nest `describe` blocks for logical grouping.
114+
- Use `before` and `after` hooks for per-test setup and teardown.
115+
- Use `before(:all)` and `after(:all)` hooks (from minitest-hooks) for expensive setup shared across all tests
116+
in a `describe` block, such as establishing database connections or defining schemas.
117+
- Use standard Minitest assertions: `assert_equal`, `assert_nil`, `assert_empty`, `assert_kind_of`, `assert_match`.
118+
- Use `assert_raises` with a block for exception testing, for example,
119+
`error = assert_raises(Mondrian::OLAP::Error) { action }`.
120+
- Use `refute` and `refute_nil` for negation assertions.
121+
- Prefer `assert_equal true, method?` and `assert_equal false, method?` for boolean methods
122+
instead of simple `assert` and `refute` assertions.
123+
- Use the custom `assert_like` matcher for comparing XML strings with normalized whitespace.
124+
- Use instance variables (`@olap`, `@schema`, `@cube`) for shared state between hooks and tests.
125+
- Conditionally skip tests for specific database drivers using `unless` guards, for example,
126+
`unless %w(vertica snowflake clickhouse).include?(MONDRIAN_DRIVER)`.
127+
- Test files are located in `test/` directory and follow the naming pattern `*_test.rb`.
128+
- Test helper and database configuration are in `test/test_helper.rb`.

Gemfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,23 @@ source 'https://rubygems.org'
33
ruby RUBY_VERSION, engine: 'jruby', engine_version: JRUBY_VERSION
44

55
gemspec
6+
7+
gem 'rake', '~> 13.3.0'
8+
gem 'minitest', '~> 5.25'
9+
gem 'minitest-hooks', '~> 1.5'
10+
gem 'minitest-reporters', '~> 1.7'
11+
gem 'rdoc', '~> 6.14.0'
12+
gem 'jdbc-mysql', '~> 8.0.30'
13+
gem 'jdbc-postgres', '~> 42.7.8'
14+
gem 'activerecord', '~> 6.1.7.10'
15+
gem 'activerecord-jdbc-adapter', '~> 61.3'
16+
gem 'activerecord-oracle_enhanced-adapter', '~> 6.1.6'
17+
gem 'pry', '~> 0.14.1'
18+
19+
if JRUBY_VERSION.to_i >= 10
20+
gem 'mutex_m'
21+
gem 'base64'
22+
gem 'bigdecimal'
23+
gem 'drb'
24+
gem 'csv'
25+
end

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ where('[Time].[2010].[Q1]').
181181
execute
182182
```
183183

184-
See more examples of queries in `spec/query_spec.rb`.
184+
See more examples of queries in `test/query_test.rb`.
185185

186186
Currently there are query builder methods just for most frequently used MDX functions, there will be new query builder methods in next releases of mondrian-olap gem.
187187

@@ -210,7 +210,7 @@ cube.member('[Customers].[USA]').descendants_at_level('City')
210210
# => get all descendants of member in specified hierarchy level
211211
```
212212

213-
See more examples of dimension and member queries in `spec/cube_spec.rb`.
213+
See more examples of dimension and member queries in `test/cube_test.rb`.
214214

215215
### Cache control
216216

@@ -237,7 +237,7 @@ cube.flush_region_cache_with_segments(
237237

238238
The `flush_region_cache_with_segments` method is particularly useful for partial cache clearing when you know which specific dimension members have changed data, avoiding the need to flush the entire cache.
239239

240-
See more examples of cache control in `spec/cube_cache_control_spec.rb`.
240+
See more examples of cache control in `test/cube_cache_control_test.rb`.
241241

242242
### Query timeout
243243

@@ -372,7 +372,7 @@ schema = Mondrian::OLAP::Schema.define do
372372
end
373373
```
374374

375-
See more examples of user defined functions in `spec/schema_definition_spec.rb`.
375+
See more examples of user defined functions in `test/schema_definition_test.rb`.
376376

377377
### Data access roles
378378

@@ -397,7 +397,7 @@ schema = Mondrian::OLAP::Schema.define do
397397
end
398398
```
399399

400-
See more examples of data access roles in `spec/connection_role_spec.rb`.
400+
See more examples of data access roles in `test/connection_role_test.rb`.
401401

402402
### Drill through
403403

@@ -453,7 +453,7 @@ drill_through = olap.from('Sales').
453453
)
454454
```
455455

456-
See more examples of drill through in `spec/query_spec.rb`.
456+
See more examples of drill through in `test/query_test.rb`.
457457

458458
### Additional schema options
459459

@@ -483,7 +483,8 @@ end
483483
REQUIREMENTS
484484
------------
485485

486-
mondrian-olap gem is compatible with JRuby versions 9.3.x and 9.4.x, JVM 8, 11, and 17. mondrian-olap works only with JRuby and not with other Ruby implementations as it includes Mondrian OLAP Java libraries.
486+
mondrian-olap gem is compatible with JRuby versions 9.4 and 10, Java 8 (deprecated), 11, 17, 21, 25.
487+
mondrian-olap works only with JRuby and not with other Ruby implementations as it includes Mondrian OLAP Java libraries.
487488

488489
mondrian-olap supports MySQL, PostgreSQL, Oracle, Microsoft SQL Server, Vertica, Snowflake, and ClickHouse databases as well as other databases that are supported by Mondrian OLAP engine (using jdbc_driver and jdbc_url connection parameters). When using MySQL or PostgreSQL databases then install jdbc-mysql or jdbc-postgres gem and require "jdbc/mysql" or "jdbc/postgres" to load the corresponding JDBC database driver. When using Oracle then require Oracle JDBC driver `ojdbc*.jar`. When using MS SQL Server you then use the Microsoft JDBC driver `mssql-jdbc-*.jar`. When using Vertica, Snowflake, or ClickHouse then require corresponding JDBC drivers.
489490

RUNNING_TESTS.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Creating test database
2+
3+
By default unit tests use MySQL database but PostgreSQL, Oracle and SQL Server databases are supported as well. Set `MONDRIAN_DRIVER` environment variable to `mysql` (default), `postgresql`, `oracle`, `sqlserver` (Microsoft JDBC), `vertica`, `snowflake`, `clickhouse`, `mariadb` to specify database driver that should be used.
4+
5+
If using a MySQL, PostgreSQL or MS SQL Server database then create database user `mondrian_test` with password `mondrian_test`, create database `mondrian_test` and grant full access to this database for `mondrian_test` user. By default it is assumed that database is located on localhost (can be overridden with `DATABASE_HOST` environment variable).
6+
7+
If using Oracle database then create database user `mondrian_test` with password `mondrian_test`. By default it is assumed that database `orcl` is located on localhost (can be overridden with `DATABASE_NAME` and `DATABASE_HOST` environment variables).
8+
9+
If using Vertica then specify environment variables `VERTICA_DATABASE_HOST`, `VERTICA_DATABASE_NAME`, `VERTICA_DATABASE_USER`, `VERTICA_DATABASE_PASSWORD` and create the `mondrian_test` schema.
10+
11+
If using Snowflake then create `MONDRIAN_TEST` user, database and schema and specify environment variables `SNOWFLAKE_DATABASE_HOST` and `SNOWFLAKE_DATABASE_PASSWORD`.
12+
13+
If using ClickHouse then create database user `mondrian_test` with password `mondrian_test`, create database `mondrian_test` and grant full access to this database for `mondrian_test` user. Specify environment variable `CLICKHOUSE_DATABASE_HOST`. Download the latest `clickhouse-jdbc-*-all.jar` and copy to `test/support/jars`.
14+
15+
If using MariaDB ColumnStore then create database user `mondrian_test` with password `mondrian_test`, create database `mondrian_test` and grant full access to this database for `mondrian_test` user. Specify environment variable `MARIADB_DATABASE_HOST`. Download `mariadb-java-client-*.jar` and copy to `test/support/jars`.
16+
17+
See `test/test_helper.rb` for details of default connection parameters and how to override them.
18+
19+
# Creating test data
20+
21+
Install necessary gems with
22+
23+
bundle install
24+
25+
Create tables with test data using
26+
27+
rake db:create_data
28+
29+
or specify which database driver to use
30+
31+
rake db:create_data MONDRIAN_DRIVER=mysql
32+
rake db:create_data MONDRIAN_DRIVER=postgresql
33+
rake db:create_data MONDRIAN_DRIVER=oracle
34+
rake db:create_data MONDRIAN_DRIVER=sqlserver
35+
36+
In case of Vertica, Snowflake, ClickHouse, MariaDB ColumnStore at first create test data in MySQL and export test data into CSV files and then import CSV files into the analytical database (because inserting individual records into these analytical databases is very slow):
37+
38+
rake db:export_data MONDRIAN_DRIVER=mysql
39+
rake db:create_data MONDRIAN_DRIVER=vertica
40+
rake db:create_data MONDRIAN_DRIVER=snowflake
41+
rake db:create_data MONDRIAN_DRIVER=clickhouse
42+
rake db:create_data MONDRIAN_DRIVER=mariadb
43+
44+
# Running tests
45+
46+
Run tests with
47+
48+
rake test
49+
50+
or specify which database driver to use
51+
52+
rake test MONDRIAN_DRIVER=mysql
53+
rake test MONDRIAN_DRIVER=postgresql
54+
rake test MONDRIAN_DRIVER=oracle
55+
rake test MONDRIAN_DRIVER=sqlserver
56+
rake test MONDRIAN_DRIVER=vertica
57+
rake test MONDRIAN_DRIVER=snowflake
58+
rake test MONDRIAN_DRIVER=clickhouse
59+
rake test MONDRIAN_DRIVER=mariadb
60+
61+
or also alternatively with
62+
63+
rake test:mysql
64+
rake test:postgresql
65+
rake test:oracle
66+
rake test:sqlserver
67+
rake test:vertica
68+
rake test:snowflake
69+
rake test:clickhouse
70+
rake test:mariadb
71+
72+
You can also run all tests on all standard databases (mysql jdbc_mysql postgresql oracle sqlserver) with
73+
74+
rake test:all
75+
76+
# JRuby versions
77+
78+
It is recommended to use mise to run tests with different JRuby implementations. mondrian-olap is being tested with latest versions of JRuby 9.4 and 10 on Java 8 (deprecated), 11, 17, 21, and 25.

0 commit comments

Comments
 (0)