Skip to content

Commit

Permalink
Covert Rails tests to RSpec (#846)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcotc committed Dec 10, 2019
1 parent 97e8e0d commit f64a90c
Show file tree
Hide file tree
Showing 26 changed files with 791 additions and 864 deletions.
12 changes: 0 additions & 12 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ elsif Gem::Version.new('2.2.0') <= Gem::Version.new(RUBY_VERSION) \
appraise 'rails5-postgres-redis-activesupport' do
gem 'rails', '~> 5.2.1'
gem 'pg', '< 1.0', platform: :ruby
gem 'redis-rails'
gem 'redis'
gem 'sprockets', '< 4'
end
Expand Down Expand Up @@ -471,7 +470,6 @@ elsif Gem::Version.new('2.3.0') <= Gem::Version.new(RUBY_VERSION) \
appraise 'rails5-postgres-redis-activesupport' do
gem 'rails', '~> 5.2.1'
gem 'pg', '< 1.0', platform: :ruby
gem 'redis-rails'
gem 'redis'
gem 'sprockets', '< 4'
end
Expand Down Expand Up @@ -538,15 +536,13 @@ elsif Gem::Version.new('2.4.0') <= Gem::Version.new(RUBY_VERSION) \
appraise 'rails5-postgres-redis' do
gem 'rails', '~> 5.2.1'
gem 'pg', '< 1.0', platform: :ruby
gem 'redis-rails'
gem 'redis'
gem 'sprockets', '< 4'
end

appraise 'rails5-postgres-redis-activesupport' do
gem 'rails', '~> 5.2.1'
gem 'pg', '< 1.0', platform: :ruby
gem 'redis-rails'
gem 'redis'
gem 'sprockets', '< 4'
end
Expand Down Expand Up @@ -613,15 +609,13 @@ elsif Gem::Version.new('2.5.0') <= Gem::Version.new(RUBY_VERSION) \
appraise 'rails5-postgres-redis' do
gem 'rails', '~> 5.2.1'
gem 'pg', '< 1.0', platform: :ruby
gem 'redis-rails'
gem 'redis'
gem 'sprockets', '< 4'
end

appraise 'rails5-postgres-redis-activesupport' do
gem 'rails', '~> 5.2.1'
gem 'pg', '< 1.0', platform: :ruby
gem 'redis-rails'
gem 'redis'
gem 'sprockets', '< 4'
end
Expand Down Expand Up @@ -649,15 +643,13 @@ elsif Gem::Version.new('2.5.0') <= Gem::Version.new(RUBY_VERSION) \
appraise 'rails6-postgres-redis' do
gem 'rails', '~> 6.0.0'
gem 'pg', '< 1.0', platform: :ruby
gem 'redis-rails'
gem 'redis'
gem 'sprockets', '< 4'
end

appraise 'rails6-postgres-redis-activesupport' do
gem 'rails', '~> 6.0.0'
gem 'pg', '< 1.0', platform: :ruby
gem 'redis-rails'
gem 'redis'
gem 'sprockets', '< 4'
end
Expand Down Expand Up @@ -723,15 +715,13 @@ elsif Gem::Version.new('2.6.0') <= Gem::Version.new(RUBY_VERSION)
appraise 'rails5-postgres-redis' do
gem 'rails', '~> 5.2.1'
gem 'pg', '< 1.0', platform: :ruby
gem 'redis-rails'
gem 'redis'
gem 'sprockets', '< 4'
end

appraise 'rails5-postgres-redis-activesupport' do
gem 'rails', '~> 5.2.1'
gem 'pg', '< 1.0', platform: :ruby
gem 'redis-rails'
gem 'redis'
gem 'sprockets', '< 4'
end
Expand Down Expand Up @@ -759,15 +749,13 @@ elsif Gem::Version.new('2.6.0') <= Gem::Version.new(RUBY_VERSION)
appraise 'rails6-postgres-redis' do
gem 'rails', '~> 6.0.0'
gem 'pg', '< 1.0', platform: :ruby
gem 'redis-rails'
gem 'redis'
gem 'sprockets', '< 4'
end

appraise 'rails6-postgres-redis-activesupport' do
gem 'rails', '~> 6.0.0'
gem 'pg', '< 1.0', platform: :ruby
gem 'redis-rails'
gem 'redis'
gem 'sprockets', '< 4'
end
Expand Down
147 changes: 52 additions & 95 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ desc 'Run RSpec'
# rubocop:disable Metrics/BlockLength
namespace :spec do
task all: [:main,
:rails, :railsredis, :railssidekiq, :railsactivejob,
:rails, :railsredis, :railsactivejob,
:elasticsearch, :http, :redis, :sidekiq, :sinatra]

RSpec::Core::RakeTask.new(:main) do |t, args|
Expand All @@ -28,7 +28,7 @@ namespace :spec do

RSpec::Core::RakeTask.new(:rails) do |t, args|
t.pattern = 'spec/ddtrace/contrib/rails/**/*_spec.rb'
t.exclude_pattern = 'spec/ddtrace/contrib/rails/**/*{sidekiq,active_job,disable_env}*_spec.rb'
t.exclude_pattern = 'spec/ddtrace/contrib/rails/**/*{active_job,disable_env,redis_cache}*_spec.rb'
t.rspec_opts = args.to_a.join(' ')
end

Expand All @@ -37,11 +37,6 @@ namespace :spec do
t.rspec_opts = args.to_a.join(' ')
end

RSpec::Core::RakeTask.new(:railssidekiq) do |t, args|
t.pattern = 'spec/ddtrace/contrib/rails/**/*sidekiq*_spec.rb'
t.rspec_opts = args.to_a.join(' ')
end

RSpec::Core::RakeTask.new(:railsactivejob) do |t, args|
t.pattern = 'spec/ddtrace/contrib/rails/**/*active_job*_spec.rb'
t.rspec_opts = args.to_a.join(' ')
Expand Down Expand Up @@ -99,7 +94,7 @@ end

namespace :test do
task all: [:main,
:rails, :railsredis, :railssidekiq, :railsactivejob,
:rails,
:sidekiq, :monkey]

Rake::TestTask.new(:main) do |t|
Expand All @@ -114,32 +109,7 @@ namespace :test do

Rake::TestTask.new(:rails) do |t|
t.libs << %w[test lib]
t.test_files = FileList['test/contrib/rails/**/*_test.rb'].reject do |path|
path.include?('redis') ||
path.include?('sidekiq') ||
path.include?('active_job') ||
path.include?('disable_env')
end
end

Rake::TestTask.new(:railsredis) do |t|
t.libs << %w[test lib]
t.test_files = FileList['test/contrib/rails/**/*redis*_test.rb']
end

Rake::TestTask.new(:railssidekiq) do |t|
t.libs << %w[test lib]
t.test_files = FileList['test/contrib/rails/**/*sidekiq*_test.rb']
end

Rake::TestTask.new(:railsactivejob) do |t|
t.libs << %w[test lib]
t.test_files = FileList['test/contrib/rails/**/*active_job*_test.rb']
end

Rake::TestTask.new(:railsdisableenv) do |t|
t.libs << %w[test lib]
t.test_files = FileList['test/contrib/rails/**/*disable_env*_test.rb']
t.test_files = FileList['test/contrib/rails/**/*_test.rb']
end

[
Expand Down Expand Up @@ -227,13 +197,11 @@ task :ci do
sh 'bundle exec appraisal contrib-old rake spec:ethon'
# Rails minitests
sh 'bundle exec appraisal rails30-postgres rake test:rails'
sh 'bundle exec appraisal rails30-postgres rake test:railsdisableenv'
sh 'bundle exec appraisal rails30-postgres rake spec:railsdisableenv'
sh 'bundle exec appraisal rails32-mysql2 rake test:rails'
sh 'bundle exec appraisal rails32-postgres rake test:rails'
sh 'bundle exec appraisal rails32-postgres-redis rake test:railsredis'
sh 'bundle exec appraisal rails32-postgres rake test:railsdisableenv'
sh 'bundle exec appraisal rails30-postgres-sidekiq rake test:railssidekiq'
sh 'bundle exec appraisal rails32-postgres-sidekiq rake test:railssidekiq'
sh 'bundle exec appraisal rails32-postgres-redis rake spec:railsredis'
sh 'bundle exec appraisal rails32-postgres rake spec:railsdisableenv'
# Rails specs
sh 'bundle exec appraisal rails30-postgres rake spec:rails'
sh 'bundle exec appraisal rails32-mysql2 rake spec:rails'
Expand Down Expand Up @@ -281,17 +249,15 @@ task :ci do
sh 'bundle exec appraisal contrib-old rake spec:ethon'
# Rails minitests
sh 'bundle exec appraisal rails30-postgres rake test:rails'
sh 'bundle exec appraisal rails30-postgres rake test:railsdisableenv'
sh 'bundle exec appraisal rails30-postgres rake spec:railsdisableenv'
sh 'bundle exec appraisal rails32-mysql2 rake test:rails'
sh 'bundle exec appraisal rails32-postgres rake test:rails'
sh 'bundle exec appraisal rails32-postgres-redis rake test:railsredis'
sh 'bundle exec appraisal rails32-postgres rake test:railsdisableenv'
sh 'bundle exec appraisal rails32-postgres-redis rake spec:railsredis'
sh 'bundle exec appraisal rails32-postgres rake spec:railsdisableenv'
sh 'bundle exec appraisal rails4-mysql2 rake test:rails'
sh 'bundle exec appraisal rails4-postgres rake test:rails'
sh 'bundle exec appraisal rails4-postgres-redis rake test:railsredis'
sh 'bundle exec appraisal rails4-postgres rake test:railsdisableenv'
sh 'bundle exec appraisal rails30-postgres-sidekiq rake test:railssidekiq'
sh 'bundle exec appraisal rails32-postgres-sidekiq rake test:railssidekiq'
sh 'bundle exec appraisal rails4-postgres-redis rake spec:railsredis'
sh 'bundle exec appraisal rails4-postgres rake spec:railsdisableenv'
# Rails specs
sh 'bundle exec appraisal rails30-postgres rake spec:rails'
sh 'bundle exec appraisal rails32-mysql2 rake spec:rails'
Expand Down Expand Up @@ -347,24 +313,22 @@ task :ci do
sh 'bundle exec appraisal contrib rake spec:ethon'
# Rails minitests
sh 'bundle exec appraisal rails30-postgres rake test:rails'
sh 'bundle exec appraisal rails30-postgres rake test:railsdisableenv'
sh 'bundle exec appraisal rails30-postgres rake spec:railsdisableenv'
sh 'bundle exec appraisal rails32-mysql2 rake test:rails'
sh 'bundle exec appraisal rails32-postgres rake test:rails'
sh 'bundle exec appraisal rails32-postgres-redis rake test:railsredis'
sh 'bundle exec appraisal rails32-postgres rake test:railsdisableenv'
sh 'bundle exec appraisal rails32-postgres-redis rake spec:railsredis'
sh 'bundle exec appraisal rails32-postgres rake spec:railsdisableenv'
sh 'bundle exec appraisal rails4-mysql2 rake test:rails'
sh 'bundle exec appraisal rails4-postgres rake test:rails'
sh 'bundle exec appraisal rails4-postgres-redis rake test:railsredis'
sh 'bundle exec appraisal rails4-postgres rake test:railsdisableenv'
sh 'bundle exec appraisal rails4-postgres-sidekiq rake test:railssidekiq'
sh 'bundle exec appraisal rails4-postgres-sidekiq rake test:railsactivejob'
sh 'bundle exec appraisal rails4-postgres-redis rake spec:railsredis'
sh 'bundle exec appraisal rails4-postgres rake spec:railsdisableenv'
sh 'bundle exec appraisal rails4-postgres-sidekiq rake spec:railsactivejob'
sh 'bundle exec appraisal rails5-mysql2 rake test:rails'
sh 'bundle exec appraisal rails5-postgres rake test:rails'
sh 'bundle exec appraisal rails5-postgres-redis rake test:railsredis'
sh 'bundle exec appraisal rails5-postgres-redis-activesupport rake test:railsredis'
sh 'bundle exec appraisal rails5-postgres-sidekiq rake test:railssidekiq'
sh 'bundle exec appraisal rails5-postgres-sidekiq rake test:railsactivejob'
sh 'bundle exec appraisal rails5-postgres rake test:railsdisableenv'
sh 'bundle exec appraisal rails5-postgres-redis rake spec:railsredis'
sh 'bundle exec appraisal rails5-postgres-redis-activesupport rake spec:railsredis'
sh 'bundle exec appraisal rails5-postgres-sidekiq rake spec:railsactivejob'
sh 'bundle exec appraisal rails5-postgres rake spec:railsdisableenv'
# Rails specs
sh 'bundle exec appraisal rails30-postgres rake spec:rails'
sh 'bundle exec appraisal rails32-mysql2 rake spec:rails'
Expand Down Expand Up @@ -417,24 +381,22 @@ task :ci do
sh 'bundle exec appraisal contrib rake spec:ethon'
# Rails minitests
sh 'bundle exec appraisal rails30-postgres rake test:rails'
sh 'bundle exec appraisal rails30-postgres rake test:railsdisableenv'
sh 'bundle exec appraisal rails30-postgres rake spec:railsdisableenv'
sh 'bundle exec appraisal rails32-mysql2 rake test:rails'
sh 'bundle exec appraisal rails32-postgres rake test:rails'
sh 'bundle exec appraisal rails32-postgres-redis rake test:railsredis'
sh 'bundle exec appraisal rails32-postgres rake test:railsdisableenv'
sh 'bundle exec appraisal rails32-postgres-redis rake spec:railsredis'
sh 'bundle exec appraisal rails32-postgres rake spec:railsdisableenv'
sh 'bundle exec appraisal rails4-mysql2 rake test:rails'
sh 'bundle exec appraisal rails4-postgres rake test:rails'
sh 'bundle exec appraisal rails4-postgres-redis rake test:railsredis'
sh 'bundle exec appraisal rails4-postgres rake test:railsdisableenv'
sh 'bundle exec appraisal rails4-postgres-sidekiq rake test:railssidekiq'
sh 'bundle exec appraisal rails4-postgres-sidekiq rake test:railsactivejob'
sh 'bundle exec appraisal rails4-postgres-redis rake spec:railsredis'
sh 'bundle exec appraisal rails4-postgres rake spec:railsdisableenv'
sh 'bundle exec appraisal rails4-postgres-sidekiq rake spec:railsactivejob'
sh 'bundle exec appraisal rails5-mysql2 rake test:rails'
sh 'bundle exec appraisal rails5-postgres rake test:rails'
sh 'bundle exec appraisal rails5-postgres-redis rake test:railsredis'
sh 'bundle exec appraisal rails5-postgres-redis-activesupport rake test:railsredis'
sh 'bundle exec appraisal rails5-postgres-sidekiq rake test:railssidekiq'
sh 'bundle exec appraisal rails5-postgres-sidekiq rake test:railsactivejob'
sh 'bundle exec appraisal rails5-postgres rake test:railsdisableenv'
sh 'bundle exec appraisal rails5-postgres-redis rake spec:railsredis'
sh 'bundle exec appraisal rails5-postgres-redis-activesupport rake spec:railsredis'
sh 'bundle exec appraisal rails5-postgres-sidekiq rake spec:railsactivejob'
sh 'bundle exec appraisal rails5-postgres rake spec:railsdisableenv'
# Rails specs
sh 'bundle exec appraisal rails30-postgres rake spec:rails'
sh 'bundle exec appraisal rails32-mysql2 rake spec:rails'
Expand Down Expand Up @@ -491,11 +453,10 @@ task :ci do
# We only test Rails 5+ because older versions require Bundler < 2.0
sh 'bundle exec appraisal rails5-mysql2 rake test:rails'
sh 'bundle exec appraisal rails5-postgres rake test:rails'
sh 'bundle exec appraisal rails5-postgres-redis rake test:railsredis'
sh 'bundle exec appraisal rails5-postgres-redis-activesupport rake test:railsredis'
sh 'bundle exec appraisal rails5-postgres-sidekiq rake test:railssidekiq'
sh 'bundle exec appraisal rails5-postgres-sidekiq rake test:railsactivejob'
sh 'bundle exec appraisal rails5-postgres rake test:railsdisableenv'
sh 'bundle exec appraisal rails5-postgres-redis rake spec:railsredis'
sh 'bundle exec appraisal rails5-postgres-redis-activesupport rake spec:railsredis'
sh 'bundle exec appraisal rails5-postgres-sidekiq rake spec:railsactivejob'
sh 'bundle exec appraisal rails5-postgres rake spec:railsdisableenv'
# Rails specs
sh 'bundle exec appraisal rails5-mysql2 rake spec:rails'
sh 'bundle exec appraisal rails5-postgres rake spec:rails'
Expand Down Expand Up @@ -547,18 +508,16 @@ task :ci do
# We only test Rails 5+ because older versions require Bundler < 2.0
sh 'bundle exec appraisal rails5-mysql2 rake test:rails'
sh 'bundle exec appraisal rails5-postgres rake test:rails'
sh 'bundle exec appraisal rails5-postgres-redis rake test:railsredis'
sh 'bundle exec appraisal rails5-postgres-redis-activesupport rake test:railsredis'
sh 'bundle exec appraisal rails5-postgres-sidekiq rake test:railssidekiq'
sh 'bundle exec appraisal rails5-postgres-sidekiq rake test:railsactivejob'
sh 'bundle exec appraisal rails5-postgres rake test:railsdisableenv'
sh 'bundle exec appraisal rails5-postgres-redis rake spec:railsredis'
sh 'bundle exec appraisal rails5-postgres-redis-activesupport rake spec:railsredis'
sh 'bundle exec appraisal rails5-postgres-sidekiq rake spec:railsactivejob'
sh 'bundle exec appraisal rails5-postgres rake spec:railsdisableenv'
sh 'bundle exec appraisal rails6-mysql2 rake test:rails'
sh 'bundle exec appraisal rails6-postgres rake test:rails'
sh 'bundle exec appraisal rails6-postgres-redis rake test:railsredis'
sh 'bundle exec appraisal rails6-postgres-redis-activesupport rake test:railsredis'
sh 'bundle exec appraisal rails6-postgres-sidekiq rake test:railssidekiq'
sh 'bundle exec appraisal rails6-postgres-sidekiq rake test:railsactivejob'
sh 'bundle exec appraisal rails6-postgres rake test:railsdisableenv'
sh 'bundle exec appraisal rails6-postgres-redis rake spec:railsredis'
sh 'bundle exec appraisal rails6-postgres-redis-activesupport rake spec:railsredis'
sh 'bundle exec appraisal rails6-postgres-sidekiq rake spec:railsactivejob'
sh 'bundle exec appraisal rails6-postgres rake spec:railsdisableenv'
# Rails specs
sh 'bundle exec appraisal rails5-mysql2 rake spec:rails'
sh 'bundle exec appraisal rails5-postgres rake spec:rails'
Expand Down Expand Up @@ -611,18 +570,16 @@ task :ci do
# We only test Rails 5+ because older versions require Bundler < 2.0
sh 'bundle exec appraisal rails5-mysql2 rake test:rails'
sh 'bundle exec appraisal rails5-postgres rake test:rails'
sh 'bundle exec appraisal rails5-postgres-redis rake test:railsredis'
sh 'bundle exec appraisal rails5-postgres-redis-activesupport rake test:railsredis'
sh 'bundle exec appraisal rails5-postgres-sidekiq rake test:railssidekiq'
sh 'bundle exec appraisal rails5-postgres-sidekiq rake test:railsactivejob'
sh 'bundle exec appraisal rails5-postgres rake test:railsdisableenv'
sh 'bundle exec appraisal rails5-postgres-redis rake spec:railsredis'
sh 'bundle exec appraisal rails5-postgres-redis-activesupport rake spec:railsredis'
sh 'bundle exec appraisal rails5-postgres-sidekiq rake spec:railsactivejob'
sh 'bundle exec appraisal rails5-postgres rake spec:railsdisableenv'
sh 'bundle exec appraisal rails6-mysql2 rake test:rails'
sh 'bundle exec appraisal rails6-postgres rake test:rails'
sh 'bundle exec appraisal rails6-postgres-redis rake test:railsredis'
sh 'bundle exec appraisal rails6-postgres-redis-activesupport rake test:railsredis'
sh 'bundle exec appraisal rails6-postgres-sidekiq rake test:railssidekiq'
sh 'bundle exec appraisal rails6-postgres-sidekiq rake test:railsactivejob'
sh 'bundle exec appraisal rails6-postgres rake test:railsdisableenv'
sh 'bundle exec appraisal rails6-postgres-redis rake spec:railsredis'
sh 'bundle exec appraisal rails6-postgres-redis-activesupport rake spec:railsredis'
sh 'bundle exec appraisal rails6-postgres-sidekiq rake spec:railsactivejob'
sh 'bundle exec appraisal rails6-postgres rake spec:railsdisableenv'
# Rails specs
sh 'bundle exec appraisal rails5-mysql2 rake spec:rails'
sh 'bundle exec appraisal rails5-postgres rake spec:rails'
Expand Down
8 changes: 4 additions & 4 deletions spec/ddtrace/contrib/rails/action_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
require 'ddtrace/contrib/rails/rails_helper'

RSpec.describe 'ActionController tracing' do
RSpec.describe 'Rails ActionController' do
let(:tracer) { get_test_tracer }
let(:rails_options) { { tracer: tracer } }

before(:each) do
before do
Datadog.configure do |c|
c.use :rails, rails_options
# Manually activate ActionPack to trigger patching.
Expand Down Expand Up @@ -55,7 +55,7 @@ def index
let(:headers) { double('headers') }
let(:body) { double('body') }

before(:each) do
before do
expect_any_instance_of(controller).to receive(:response)
.at_least(:once)
.and_wrap_original do |m, *args|
Expand All @@ -81,7 +81,7 @@ def index
)
end

before(:each) do
before do
expect_any_instance_of(controller).to receive(:response)
.at_least(:once)
.and_wrap_original do |m, *args|
Expand Down
Loading

0 comments on commit f64a90c

Please sign in to comment.