Skip to content

Commit

Permalink
Update spec/shared to current master (#4907)
Browse files Browse the repository at this point in the history
* Update spec/shared to current master

* RUBY-2428 use shared spec organizer & child process helper

Co-authored-by: Oleg Pudeyev <[email protected]>
  • Loading branch information
p-mongo and p authored Nov 4, 2020
1 parent 55e8aa5 commit fee0cfe
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 226 deletions.
32 changes: 28 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ require "bundler"
require "bundler/gem_tasks"
Bundler.setup

ROOT = File.expand_path(File.join(File.dirname(__FILE__)))

$: << File.join(ROOT, 'spec/shared/lib')

require "rake"
require "rspec/core/rake_task"
require 'mrss/spec_organizer'

$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
require "mongoid/version"
Expand Down Expand Up @@ -38,11 +43,30 @@ RSpec::Core::RakeTask.new('spec:progress') do |spec|
spec.pattern = "spec/**/*_spec.rb"
end

task :ci do
$LOAD_PATH.push File.expand_path("../spec", __FILE__)
require 'support/spec_organizer'
CLASSIFIERS = [
[%r,^mongoid/attribute,, :attributes],
[%r,^mongoid/association/[or],, :associations_referenced],
[%r,^mongoid/association,, :associations],
[%r,^mongoid,, :unit],
[%r,^integration,, :integration],
[%r,^rails,, :rails],
]

RUN_PRIORITY = %i(
unit attributes associations_referenced associations
integration rails
)

def spec_organizer
Mrss::SpecOrganizer.new(
root: ROOT,
classifiers: CLASSIFIERS,
priority_order: RUN_PRIORITY,
)
end

SpecOrganizer.new.run
task :ci do
spec_organizer.run
end

task :default => :spec
Expand Down
24 changes: 12 additions & 12 deletions spec/integration/app_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
end

require 'fileutils'
require 'support/child_process_helper'
require 'mrss/child_process_helper'
require 'open-uri'

FileUtils.mkdir_p(TMP_BASE)
Expand Down Expand Up @@ -91,19 +91,19 @@
['~> 5.1.0', '~> 5.2.0', '~> 6.0.0'].each do |rails_version|
context "with rails #{rails_version}" do
it 'creates' do
ChildProcessHelper.check_call(%w(gem uni rails -a))
ChildProcessHelper.check_call(%w(gem install rails --no-document -v) + [rails_version])
Mrss::ChildProcessHelper.check_call(%w(gem uni rails -a))
Mrss::ChildProcessHelper.check_call(%w(gem install rails --no-document -v) + [rails_version])

Dir.chdir(TMP_BASE) do
FileUtils.rm_rf('mongoid-test')
ChildProcessHelper.check_call(%w(rails new mongoid-test --skip-spring --skip-active-record), env: clean_env)
Mrss::ChildProcessHelper.check_call(%w(rails new mongoid-test --skip-spring --skip-active-record), env: clean_env)

Dir.chdir('mongoid-test') do
adjust_app_gemfile
ChildProcessHelper.check_call(%w(bundle install), env: clean_env)
Mrss::ChildProcessHelper.check_call(%w(bundle install), env: clean_env)

ChildProcessHelper.check_call(%w(rails g model post), env: clean_env)
ChildProcessHelper.check_call(%w(rails g model comment post:belongs_to), env: clean_env)
Mrss::ChildProcessHelper.check_call(%w(rails g model post), env: clean_env)
Mrss::ChildProcessHelper.check_call(%w(rails g model comment post:belongs_to), env: clean_env)

# https://jira.mongodb.org/browse/MONGOID-4885
comment_text = File.read('app/models/comment.rb')
Expand Down Expand Up @@ -136,7 +136,7 @@
before do
Dir.chdir(APP_PATH) do
remove_bundler_req
ChildProcessHelper.check_call(%w(bundle install), env: env)
Mrss::ChildProcessHelper.check_call(%w(bundle install), env: env)
write_mongoid_yml
end

Expand All @@ -150,7 +150,7 @@
end
index.should be nil

ChildProcessHelper.check_call(%w(rake db:mongoid:create_indexes),
Mrss::ChildProcessHelper.check_call(%w(rake db:mongoid:create_indexes),
cwd: APP_PATH, env: env)

index = client['posts'].indexes.detect do |index|
Expand All @@ -168,10 +168,10 @@
def clone_application(repo_url, subdir: nil, rails_version: nil)
Dir.chdir(TMP_BASE) do
FileUtils.rm_rf(File.basename(repo_url))
ChildProcessHelper.check_call(%w(git clone) + [repo_url])
Mrss::ChildProcessHelper.check_call(%w(git clone) + [repo_url])
Dir.chdir(File.join(*[File.basename(repo_url), subdir].compact)) do
adjust_app_gemfile(rails_version: rails_version)
ChildProcessHelper.check_call(%w(bundle install), env: clean_env)
Mrss::ChildProcessHelper.check_call(%w(bundle install), env: clean_env)
puts `git diff`

write_mongoid_yml
Expand Down Expand Up @@ -230,7 +230,7 @@ def remove_spring
# in `initialize': too long unix socket path (126bytes given but 108bytes max) (ArgumentError)
# Is it trying to create unix sockets in current directory?
# https://stackoverflow.com/questions/30302021/rails-runner-without-spring
ChildProcessHelper.check_call(%w(bin/spring binstub --remove --all), env: clean_env)
Mrss::ChildProcessHelper.check_call(%w(bin/spring binstub --remove --all), env: clean_env)
end

def clean_env
Expand Down
2 changes: 1 addition & 1 deletion spec/shared
79 changes: 0 additions & 79 deletions spec/support/child_process_helper.rb

This file was deleted.

130 changes: 0 additions & 130 deletions spec/support/spec_organizer.rb

This file was deleted.

0 comments on commit fee0cfe

Please sign in to comment.