Skip to content

Commit

Permalink
test interoperability for shoulda-matchers
Browse files Browse the repository at this point in the history
  • Loading branch information
kratob committed Nov 7, 2024
1 parent ab4f576 commit 21e56ca
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 37 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
2 changes: 1 addition & 1 deletion Gemfile
1 change: 1 addition & 0 deletions Gemfile.7.2.sqlite3
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ gem 'rspec', '~>3.4'
gem 'sqlite3', '=1.6.0'
gem 'rake'
gem 'gemika'
gem 'shoulda-matchers'

gem 'active_type', :path => '.'
3 changes: 3 additions & 0 deletions Gemfile.7.2.sqlite3.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -66,6 +68,7 @@ DEPENDENCIES
gemika
rake
rspec (~> 3.4)
shoulda-matchers
sqlite3 (= 1.6.0)

BUNDLED WITH
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
45 changes: 10 additions & 35 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,53 +1,28 @@
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"]
end

# 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
namespace :spec 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
Expand Down
38 changes: 38 additions & 0 deletions spec/interoperability/shoulda_matchers/validation_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 21e56ca

Please sign in to comment.