From 1ccab9477398f8b68808662fd83a2ee822184217 Mon Sep 17 00:00:00 2001 From: Tobias Kraze Date: Thu, 7 Nov 2024 11:25:30 +0100 Subject: [PATCH] test interoperability for shoulda-matchers --- .github/workflows/test.yml | 23 ++++++++++ Gemfile | 2 +- Gemfile.7.2.sqlite3 | 1 + Gemfile.7.2.sqlite3.lock | 3 ++ Gemfile.lock | 2 +- Rakefile | 44 ++++--------------- .../shoulda_matchers/validation_spec.rb | 38 ++++++++++++++++ 7 files changed, 76 insertions(+), 37 deletions(-) create mode 100644 spec/interoperability/shoulda_matchers/validation_spec.rb diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a904559..9650f63 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -132,3 +132,26 @@ jobs: bundler-cache: true - name: Run tests run: bundle exec rake spec + + test_interoperability: + runs-on: ubuntu-20.04 + + strategy: + fail-fast: false + matrix: + include: + - ruby: "3.2.0" + gemfile: Gemfile.7.2.sqlite3 + name: 'shoulda_matchers' + env: + BUNDLE_GEMFILE: ${{ matrix.gemfile }} + + steps: + - uses: actions/checkout@v3 + - name: Install ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + - name: Run tests + run: bundle exec rake spec:interoperability:${{ matrix.name }} diff --git a/Gemfile b/Gemfile index 027c099..812a804 120000 --- a/Gemfile +++ b/Gemfile @@ -1 +1 @@ -Gemfile.7.0.sqlite3 \ No newline at end of file +Gemfile.7.2.sqlite3 \ No newline at end of file diff --git a/Gemfile.7.2.sqlite3 b/Gemfile.7.2.sqlite3 index 7df5962..bfadacd 100644 --- a/Gemfile.7.2.sqlite3 +++ b/Gemfile.7.2.sqlite3 @@ -5,5 +5,6 @@ gem 'rspec', '~>3.4' gem 'sqlite3', '=1.6.0' gem 'rake' gem 'gemika' +gem 'shoulda-matchers' gem 'active_type', :path => '.' diff --git a/Gemfile.7.2.sqlite3.lock b/Gemfile.7.2.sqlite3.lock index fd80aef..0af6e9b 100644 --- a/Gemfile.7.2.sqlite3.lock +++ b/Gemfile.7.2.sqlite3.lock @@ -51,6 +51,8 @@ GEM rspec-support (~> 3.13.0) rspec-support (3.13.1) securerandom (0.3.1) + shoulda-matchers (6.4.0) + activesupport (>= 5.2.0) sqlite3 (1.6.0) mini_portile2 (~> 2.8.0) timeout (0.4.1) @@ -66,6 +68,7 @@ DEPENDENCIES gemika rake rspec (~> 3.4) + shoulda-matchers sqlite3 (= 1.6.0) BUNDLED WITH diff --git a/Gemfile.lock b/Gemfile.lock index 2e5414e..6b25dae 120000 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1 +1 @@ -Gemfile.7.0.sqlite3.lock \ No newline at end of file +Gemfile.7.2.sqlite3.lock \ No newline at end of file diff --git a/Rakefile b/Rakefile index 9a2e4b9..8a685b4 100644 --- a/Rakefile +++ b/Rakefile @@ -1,55 +1,29 @@ require 'rake' require 'bundler/gem_tasks' -begin - require 'gemika/tasks' -rescue LoadError - puts 'Run `gem install gemika` for additional tasks' -end - -task default: 'matrix:spec' +task default: 'spec:all' task :spec do - success = system("bundle exec rspec spec --exclude-pattern '**/isolated/**'") + success = system("bundle exec rspec spec --exclude-pattern 'spec/{isolated,interoperability}/**/*'") for_each_isolated_spec do |isolated_spec| success &= system("bundle exec rspec #{isolated_spec}") end fail "Tests failed" unless success end +namespace :spec do + task :all => [:spec, :"interoperability:spec:shoulda_matchers"] -# we have to override the matrix:spec task, since we need some specs to run in isolation - -Rake::Task["matrix:spec"].clear - -namespace :matrix do - - desc "Run specs for all Ruby #{RUBY_VERSION} gemfiles" - task :spec, :files do |t, options| - Gemika::Matrix.from_ci_config.each do |row| - options = options.to_hash.merge( - :gemfile => row.gemfile, - :fatal => false, - :bundle_exec => true, - ) - success = Gemika::RSpec.run_specs(options.merge( - :options => '--exclude-pattern "**/isolated/**"', - )) - - for_each_isolated_spec do |isolated_spec| - isolated_success = Gemika::RSpec.run_specs(options.merge( - :files => isolated_spec, - )) - success &&= isolated_success - end - - success + namespace :interoperability do + task :shoulda_matchers do + success = system("bundle exec rspec spec/interoperability") + fail "Tests failed" unless success end end - end + def for_each_isolated_spec Dir["spec/isolated/**/*_spec.rb"].sort.each do |isolated_spec| yield(isolated_spec) diff --git a/spec/interoperability/shoulda_matchers/validation_spec.rb b/spec/interoperability/shoulda_matchers/validation_spec.rb new file mode 100644 index 0000000..5ae2b08 --- /dev/null +++ b/spec/interoperability/shoulda_matchers/validation_spec.rb @@ -0,0 +1,38 @@ +require 'spec_helper' +require 'shoulda-matchers' + +Shoulda::Matchers.configure do |config| + config.integrate do |with| + with.test_framework :rspec + + # Keep as many of these lines as are necessary: + with.library :active_record + with.library :active_model + end +end + +module ShouldaMatchersSpec + class Record < ActiveType::Record + attribute :virtual_string, :string + + validates :persisted_string, numericality: true + validates :virtual_string, numericality: true + end + + class Object < ActiveType::Object + attribute :virtual_string, :string + + validates :virtual_string, numericality: true + end +end + +describe 'shoulda-matchers integration', type: :model do + it 'can test numericality validation on ActiveType::Record' do + expect(ShouldaMatchersSpec::Record.new).to validate_numericality_of(:persisted_string) + expect(ShouldaMatchersSpec::Record.new).to validate_numericality_of(:virtual_string) + end + + it 'can test numericality validation on ActiveType::User' do + expect(ShouldaMatchersSpec::Object.new).to validate_numericality_of(:virtual_string) + end +end