appmap 0.78.0 → 0.80.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +4 -16
  3. data/CHANGELOG.md +30 -0
  4. data/{spec/fixtures/rails5_users_app/Dockerfile.pg → Dockerfile.pg} +0 -0
  5. data/README.md +14 -44
  6. data/README_CI.md +0 -7
  7. data/Rakefile +12 -150
  8. data/appmap.gemspec +3 -2
  9. data/docker-compose.yml +10 -0
  10. data/lib/appmap/agent.rb +8 -0
  11. data/lib/appmap/event.rb +26 -12
  12. data/lib/appmap/gem_hooks/actionpack.yml +6 -0
  13. data/lib/appmap/handler/rails/render_handler.rb +29 -0
  14. data/lib/appmap/handler/rails/request_handler.rb +13 -11
  15. data/lib/appmap/handler/rails/sql_handler.rb +43 -1
  16. data/lib/appmap/handler.rb +3 -0
  17. data/lib/appmap/hook/method.rb +0 -1
  18. data/lib/appmap/version.rb +1 -1
  19. data/spec/config_spec.rb +1 -1
  20. data/spec/depends/api_spec.rb +13 -5
  21. data/spec/depends/spec_helper.rb +0 -9
  22. data/spec/fixtures/database.yml +11 -0
  23. data/spec/fixtures/rails5_users_app/config/database.yml +1 -0
  24. data/spec/fixtures/rails6_users_app/Gemfile +1 -25
  25. data/spec/fixtures/rails6_users_app/config/database.yml +1 -0
  26. data/spec/fixtures/rails7_users_app/Gemfile +1 -25
  27. data/spec/fixtures/rails7_users_app/config/database.yml +1 -0
  28. data/spec/handler/eval_spec.rb +1 -1
  29. data/spec/hook_spec.rb +6 -1
  30. data/spec/rails_recording_spec.rb +7 -21
  31. data/spec/rails_spec_helper.rb +76 -63
  32. data/spec/rails_test_spec.rb +7 -17
  33. data/spec/railtie_spec.rb +4 -18
  34. data/spec/record_sql_rails_pg_spec.rb +44 -75
  35. data/spec/remote_recording_spec.rb +18 -30
  36. data/spec/spec_helper.rb +1 -0
  37. data/spec/swagger/swagger_spec.rb +1 -16
  38. data/spec/util_spec.rb +1 -1
  39. data/test/expectations/openssl_test_key_sign2-3.1.json +2 -1
  40. metadata +22 -21
  41. data/Dockerfile.appmap +0 -5
  42. data/spec/fixtures/rack_users_app/Dockerfile +0 -32
  43. data/spec/fixtures/rack_users_app/docker-compose.yml +0 -9
  44. data/spec/fixtures/rails5_users_app/Dockerfile +0 -29
  45. data/spec/fixtures/rails5_users_app/config/database.yml +0 -18
  46. data/spec/fixtures/rails5_users_app/create_app +0 -33
  47. data/spec/fixtures/rails5_users_app/docker-compose.yml +0 -31
  48. data/spec/fixtures/rails6_users_app/.ruby-version +0 -1
  49. data/spec/fixtures/rails6_users_app/Dockerfile +0 -44
  50. data/spec/fixtures/rails6_users_app/Dockerfile.pg +0 -3
  51. data/spec/fixtures/rails6_users_app/config/database.yml +0 -18
  52. data/spec/fixtures/rails6_users_app/create_app +0 -33
  53. data/spec/fixtures/rails6_users_app/docker-compose.yml +0 -31
  54. data/spec/fixtures/rails7_users_app/.ruby-version +0 -1
  55. data/spec/fixtures/rails7_users_app/Dockerfile +0 -30
  56. data/spec/fixtures/rails7_users_app/Dockerfile.pg +0 -3
  57. data/spec/fixtures/rails7_users_app/config/database.yml +0 -86
  58. data/spec/fixtures/rails7_users_app/create_app +0 -31
  59. data/spec/fixtures/rails7_users_app/docker-compose.yml +0 -31
@@ -5,6 +5,9 @@ require 'active_support/inflector/methods'
5
5
  module AppMap
6
6
  # Specific hook handler classes and general related utilities.
7
7
  module Handler
8
+ TEMPLATE_RENDER_FORMAT = 'appmap.handler.template.return_value_format'
9
+ TEMPLATE_RENDER_VALUE = 'appmap.handler.template.return_value'
10
+
8
11
  # Try to find handler module with a given name.
9
12
  #
10
13
  # If the module is not loaded, tries to require the appropriate file
@@ -24,7 +24,6 @@ module AppMap
24
24
  attr_reader :hook_package, :hook_class, :hook_method, :parameters, :arity
25
25
 
26
26
  HOOK_DISABLE_KEY = 'AppMap::Hook.disable'
27
- private_constant :HOOK_DISABLE_KEY
28
27
 
29
28
  def initialize(hook_package, hook_class, hook_method)
30
29
  @hook_package = hook_package
@@ -3,7 +3,7 @@
3
3
  module AppMap
4
4
  URL = 'https://github.com/applandinc/appmap-ruby'
5
5
 
6
- VERSION = '0.78.0'
6
+ VERSION = '0.80.1'
7
7
 
8
8
  APPMAP_FORMAT_VERSION = '1.5.1'
9
9
 
data/spec/config_spec.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  require 'rails_spec_helper'
4
4
  require 'appmap/config'
5
5
 
6
- describe AppMap::Config, docker: false do
6
+ describe AppMap::Config do
7
7
  it 'loads as expected' do
8
8
  config_data = {
9
9
  name: 'test',
@@ -33,7 +33,7 @@ module AppMap
33
33
  end
34
34
  end
35
35
  end
36
- end
36
+ end
37
37
 
38
38
  describe 'Depends API' do
39
39
  let(:api) { AppMap::Depends::API.new(ENV['DEBUG'] == 'true') }
@@ -112,12 +112,12 @@ describe 'Depends API' do
112
112
  around do |test|
113
113
  @minitest_test_command_method = AppMap.configuration.depends_config.minitest_test_command_method
114
114
  AppMap.configuration.depends_config.minitest_test_command_method = 'AppMap::Depends::APISpec.minitest_test_command'
115
-
115
+
116
116
  test.call
117
117
  ensure
118
118
  AppMap.configuration.depends_config.minitest_test_command_method = @minitest_test_command
119
119
  end
120
-
120
+
121
121
  it 'passes a smoke test' do
122
122
  run_tests
123
123
  end
@@ -175,10 +175,18 @@ describe 'Depends API' do
175
175
  # At this point, we would run tests to bring the AppMaps up to date
176
176
  # Then once the tests have finished, remove any AppMaps that weren't refreshed
177
177
  removed = api.remove_out_of_date_appmaps(since, appmap_dir: DEPENDS_TEST_DIR, base_dir: DEPENDS_BASE_DIR)
178
- expect(removed).to eq([ appmap_path.split('.')[0] ])
178
+ expect(removed).to eq([ appmap_path.split('.')[0] ])
179
179
  ensure
180
- File.write(appmap_path, appmap)
180
+ File.write(appmap_path, appmap)
181
181
  end
182
182
  end
183
183
  end
184
+
185
+ before do
186
+ Dir.glob("#{DEPENDS_TEST_DIR}/*.appmap.json").each { |fname| FileUtils.touch fname }
187
+ update_appmap_index
188
+
189
+ FileUtils.rm_rf 'spec/tmp'
190
+ FileUtils.mkdir_p 'spec/tmp'
191
+ end
184
192
  end
@@ -16,12 +16,3 @@ def update_appmap_index
16
16
  system cmd.join(' ') or raise "Failed to update AppMap index in #{DEPENDS_TEST_DIR}"
17
17
  end
18
18
 
19
- RSpec.configure do |rspec|
20
- rspec.before do
21
- Dir.glob("#{DEPENDS_TEST_DIR}/*.appmap.json").each { |fname| FileUtils.touch fname }
22
- update_appmap_index
23
-
24
- FileUtils.rm_rf 'spec/tmp'
25
- FileUtils.mkdir_p 'spec/tmp'
26
- end
27
- end
@@ -0,0 +1,11 @@
1
+ default: &default
2
+ url: <%= ENV['DATABASE_URL'] %>
3
+ adapter: postgresql
4
+ database: <%= ENV['TEST_DATABASE'] || 'appland-rails6-test' %>
5
+
6
+ development:
7
+ <<: *default
8
+ test:
9
+ <<: *default
10
+ production:
11
+ <<: *default
@@ -0,0 +1 @@
1
+ ../../database.yml
@@ -11,32 +11,8 @@ gem 'sequel', '>= 5.43.0', require: false
11
11
  gem 'sequel-rails', require: false
12
12
  gem 'sequel_secure_password', require: false
13
13
 
14
- appmap_path = \
15
- # Support debugging inside the container with volume-mounted source
16
- if File.directory?('/src/appmap-ruby')
17
- '/src/appmap-ruby'
18
- elsif File.exist?('../../../appmap.gemspec')
19
- '../../..'
20
- end
21
-
22
- if appmap_path
23
- # Set the branch parameter, so that 'bundle config local.appmap' will work
24
- appmap_branch = Dir.chdir appmap_path do
25
- `git rev-parse --abbrev-ref HEAD`.strip
26
- end
27
- end
28
-
29
- appmap_options = \
30
- if appmap_path && appmap_branch
31
- { git: appmap_path, branch: appmap_branch }
32
- elsif appmap_path
33
- { path: appmap_path }
34
- else
35
- {}
36
- end.merge(require: %w[appmap])
37
-
38
14
  group :development, :test do
39
- gem 'appmap', appmap_options
15
+ gem 'appmap', path: '../../..'
40
16
  gem 'cucumber-rails', require: false
41
17
  gem 'rspec-rails'
42
18
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
@@ -0,0 +1 @@
1
+ ../../database.yml
@@ -69,31 +69,7 @@ group :test do
69
69
  gem "webdrivers"
70
70
  end
71
71
 
72
- appmap_path = \
73
- # Support debugging inside the container with volume-mounted source
74
- if File.directory?('/src/appmap-ruby')
75
- '/src/appmap-ruby'
76
- elsif File.exist?('../../../appmap.gemspec')
77
- '../../..'
78
- end
79
-
80
- if appmap_path
81
- # Set the branch parameter, so that 'bundle config local.appmap' will work
82
- appmap_branch = Dir.chdir appmap_path do
83
- `git rev-parse --abbrev-ref HEAD`.strip
84
- end
85
- end
86
-
87
- appmap_options = \
88
- if appmap_path && appmap_branch
89
- { git: appmap_path, branch: appmap_branch }
90
- elsif appmap_path
91
- { path: appmap_path }
92
- else
93
- {}
94
- end.merge(require: %w[appmap])
95
-
96
72
  group :development, :test do
97
- gem 'appmap', appmap_options
73
+ gem 'appmap', path: '../../..'
98
74
  gem 'pry-byebug', '>=0', '< 99'
99
75
  end
@@ -0,0 +1 @@
1
+ ../../database.yml
@@ -32,7 +32,7 @@ describe 'AppMap::Handler::Eval' do
32
32
  expect(events[0]).to match hash_including \
33
33
  defined_class: 'Kernel',
34
34
  method_id: 'eval',
35
- parameters: [{ class: 'Array', kind: :rest, name: 'arg', value: '[12]' }]
35
+ parameters: [{ class: 'Array', kind: :rest, name: 'arg', size: 1, value: '[12]' }]
36
36
  end
37
37
 
38
38
  # a la Ruby 2.6.3 ruby-token.rb
data/spec/hook_spec.rb CHANGED
@@ -16,7 +16,7 @@ module ShowYamlNulls
16
16
  end
17
17
  Psych::Visitors::YAMLTree.prepend(ShowYamlNulls)
18
18
 
19
- describe 'AppMap class Hooking', docker: false do
19
+ describe 'AppMap class Hooking' do
20
20
  include_context 'collect events'
21
21
 
22
22
  def invoke_test_file(file, setup: nil, packages: nil)
@@ -491,6 +491,7 @@ describe 'AppMap class Hooking', docker: false do
491
491
  :class: Array
492
492
  :value: "[4, 5]"
493
493
  :kind: :rest
494
+ :size: 2
494
495
  - :name: :kw1
495
496
  :class: String
496
497
  :value: one
@@ -503,6 +504,7 @@ describe 'AppMap class Hooking', docker: false do
503
504
  :class: Hash
504
505
  :value: "{:kw3=>:three}"
505
506
  :kind: :keyrest
507
+ :size: 1
506
508
  :receiver:
507
509
  :class: InstanceMethod
508
510
  :value: Instance Method fixture
@@ -1139,6 +1141,7 @@ describe 'AppMap class Hooking', docker: false do
1139
1141
  :class: Array
1140
1142
  :value: "[foo]"
1141
1143
  :kind: :rest
1144
+ :size: 1
1142
1145
  - :name: :kw1
1143
1146
  :class: String
1144
1147
  :value: kw1
@@ -1151,6 +1154,7 @@ describe 'AppMap class Hooking', docker: false do
1151
1154
  :class: Hash
1152
1155
  :value: "{}"
1153
1156
  :kind: :keyrest
1157
+ :size: 0
1154
1158
  :receiver:
1155
1159
  :class: ReportParameters
1156
1160
  :value: ReportParameters
@@ -1160,6 +1164,7 @@ describe 'AppMap class Hooking', docker: false do
1160
1164
  :return_value:
1161
1165
  :class: Array
1162
1166
  :value: "[[:rest, :args], [:keyreq, :kw1], [:key, :kw2], [:keyrest, :kws]]"
1167
+ :size: 4
1163
1168
  YAML
1164
1169
  parameters = [[:rest, :args], [:keyreq, :kw1], [:key, :kw2], [:keyrest, :kws]]
1165
1170
  test_hook_behavior 'spec/fixtures/hook/report_parameters.rb', events do
@@ -15,14 +15,6 @@ describe 'Rails' do
15
15
  include_context 'Rails app pg database', "spec/fixtures/rails#{rails_major_version}_users_app" unless use_existing_data?
16
16
  include_context 'rails integration test setup'
17
17
 
18
- def run_spec(spec_name)
19
- cmd = <<~CMD.gsub "\n", ' '
20
- docker-compose run --rm -e RAILS_ENV=test -e APPMAP=true
21
- -v #{File.absolute_path tmpdir}:/app/tmp app ./bin/rspec #{spec_name}
22
- CMD
23
- run_cmd cmd, chdir: fixture_dir
24
- end
25
-
26
18
  describe 'an API route' do
27
19
  describe 'creating an object' do
28
20
  let(:appmap_json_file) do
@@ -62,7 +54,8 @@ describe 'Rails' do
62
54
  'http_server_response' => hash_including(
63
55
  'status_code' => 201,
64
56
  'headers' => hash_including('Content-Type' => 'application/json; charset=utf-8'),
65
- )
57
+ ),
58
+ 'return_value' => hash_including('class' => 'Hash', 'object_id' => Integer, 'properties' => include({'name' => 'login', 'class' => 'String'})),
66
59
  )
67
60
  )
68
61
  end
@@ -80,6 +73,7 @@ describe 'Rails' do
80
73
  'name' => 'params',
81
74
  'class' => 'ActiveSupport::HashWithIndifferentAccess',
82
75
  'object_id' => Integer,
76
+ 'size' => 1,
83
77
  'value' => '{login=>alice}',
84
78
  'kind' => 'req'
85
79
  ),
@@ -123,7 +117,7 @@ describe 'Rails' do
123
117
  )
124
118
  )
125
119
  )
126
- )
120
+ )
127
121
  end
128
122
  end
129
123
  end
@@ -201,7 +195,7 @@ describe 'Rails' do
201
195
  'path_info' => '/users/alice',
202
196
  'normalized_path_info' => '/users/{id}',
203
197
  'headers' => {
204
- 'Host' => 'test.host',
198
+ 'Host' => 'test.host',
205
199
  'User-Agent' => 'Rails Testing'
206
200
  }
207
201
  }
@@ -236,7 +230,7 @@ describe 'Rails' do
236
230
  'defined_class' => 'inline_template',
237
231
  'method_id' => 'render'
238
232
  )
239
-
233
+
240
234
  expect(appmap['classMap']).to include hash_including(
241
235
  'name' => 'actionview',
242
236
  'children' => include(hash_including(
@@ -251,7 +245,7 @@ describe 'Rails' do
251
245
  ))
252
246
  ))
253
247
  )
254
- end
248
+ end
255
249
  end
256
250
  end
257
251
  end
@@ -261,14 +255,6 @@ describe 'Rails' do
261
255
  include_context 'Rails app pg database', "spec/fixtures/rails6_users_app" unless use_existing_data?
262
256
  include_context 'rails integration test setup'
263
257
 
264
- def run_spec(spec_name)
265
- cmd = <<~CMD.gsub "\n", ' '
266
- docker-compose run --rm -e RAILS_ENV=test -e APPMAP=true -e APPMAP_CONFIG_FILE=no/such/file
267
- -v #{File.absolute_path tmpdir}:/app/tmp app ./bin/rspec #{spec_name}
268
- CMD
269
- run_cmd cmd, chdir: fixture_dir
270
- end
271
-
272
258
  let(:appmap_json_file) do
273
259
  'Api_UsersController_POST_api_users_with_required_parameters_creates_a_user.appmap.json'
274
260
  end
@@ -1,93 +1,106 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'open3'
4
+
3
5
  require 'spec_helper'
4
6
  require 'active_support'
5
7
  require 'active_support/core_ext'
6
- require 'open3'
7
8
 
8
- # The RUBY_VERSION global variable indicates the version of the
9
- # runtime. The RUBY_VERSION environment variable is the version we're
10
- # testing, so it needs to be used to pick a fixture directory.
11
9
  def testing_ruby_2?
12
- ENV['RUBY_VERSION'].split('.')[0].to_i == 2
10
+ RUBY_VERSION.split('.')[0].to_i == 2
13
11
  end
14
12
 
15
- # docker compose v2 replaced the --filter flag with --status
16
- PS_CMD=`docker-compose --version` =~ /version v2/ ?
17
- "docker-compose ps -q --status running" :
18
- "docker-compose ps -q --filter health=healthy"
13
+ class TestRailsApp
14
+ def initialize(fixture_dir)
15
+ @fixture_dir = fixture_dir
16
+ end
19
17
 
20
- def wait_for_container(app_name)
21
- start_time = Time.now
22
- until `#{PS_CMD} #{app_name}`.strip != ''
23
- elapsed = Time.now - start_time
24
- raise "Timeout waiting for container #{app_name} to be ready" if elapsed > 10
18
+ attr_reader :fixture_dir
25
19
 
26
- $stderr.write '.' if elapsed > 3
27
- sleep 0.25
20
+ def run_cmd(cmd, env = {})
21
+ run_process method(:system), cmd, env, exception: true
28
22
  end
29
- end
30
23
 
31
- def run_cmd(*cmd, &failed)
32
- out, status = Open3.capture2e(*cmd)
33
- return [ out, status ] if status.success?
34
-
35
- warn <<~WARNING
36
- Command failed:
37
- #{cmd}
38
- <<< Output:
39
- #{out}
40
- >>> End of output
41
- WARNING
42
- failed&.call
43
- raise 'Command failed'
44
- end
24
+ def spawn_cmd(cmd, env = {})
25
+ puts "Spawning `#{cmd}` in #{fixture_dir}..."
26
+ run_process Process.method(:spawn), cmd, env
27
+ end
45
28
 
46
- shared_context 'Rails app pg database' do |fixture_dir|
47
- define_method(:fixture_dir) { fixture_dir }
29
+ def capture_cmd(cmd, env = {})
30
+ puts "Capturing `#{cmd}` in #{fixture_dir}..."
31
+ run_process(Open3.method(:capture2), cmd, env).first
32
+ end
48
33
 
49
- before(:all) do
50
- print_pg_logs = lambda do
51
- logs, = run_cmd 'docker-compose logs pg'
52
- puts "docker-compose logs for pg:"
53
- puts
54
- puts logs
55
- end
34
+ def database_name
35
+ # This is used locally too, so make the name nice and unique.
36
+ @database_name ||= "appland-rails-test-#{Random.bytes(8).unpack1('h*')}"
37
+ end
56
38
 
57
- Dir.chdir fixture_dir do
58
- run_cmd 'docker-compose down -v'
59
- cmd = 'docker-compose up -d pg'
60
- run_cmd cmd
61
- wait_for_container 'pg'
39
+ def bundle
40
+ return if @bundled
62
41
 
63
- cmd = 'docker-compose run --rm app ./create_app'
64
- run_cmd cmd, &print_pg_logs
65
- end
42
+ run_cmd 'bundle'
43
+ @bundled = true
66
44
  end
67
45
 
68
- after(:all) do
69
- if ENV['NOKILL'] != 'true'
70
- cmd = 'docker-compose down -v'
71
- run_cmd cmd, chdir: fixture_dir
72
- end
46
+ def prepare_db
47
+ return if @db_prepared
48
+
49
+ bundle
50
+ run_cmd './bin/rake db:create db:schema:load'
51
+ @db_prepared = true
52
+ at_exit { drop_db }
53
+ end
54
+
55
+ def drop_db
56
+ return unless @db_prepared
57
+
58
+ run_cmd './bin/rake db:drop'
59
+ @db_prepared = false
73
60
  end
74
- end
75
61
 
76
- shared_context 'rails integration test setup' do
77
62
  def tmpdir
78
- 'tmp/spec/AbstractControllerBase'
63
+ @tmpdir ||= File.join(fixture_dir, 'tmp')
64
+ end
65
+
66
+ def run_specs
67
+ return if @specs_ran or use_existing_data?
68
+
69
+ prepare_db
70
+ FileUtils.rm_rf tmpdir
71
+ run_cmd \
72
+ './bin/rspec spec/controllers/users_controller_spec.rb spec/controllers/users_controller_api_spec.rb',
73
+ 'APPMAP' => 'true'
74
+ @specs_ran = true
75
+ end
76
+
77
+ def self.for_fixture(fixture_dir)
78
+ @apps ||= {}
79
+ @apps[fixture_dir] ||= TestRailsApp.new fixture_dir
79
80
  end
80
81
 
81
- unless use_existing_data?
82
- before(:all) do
83
- FileUtils.rm_rf tmpdir
84
- FileUtils.mkdir_p tmpdir
85
- run_spec 'spec/controllers/users_controller_spec.rb'
86
- run_spec 'spec/controllers/users_controller_api_spec.rb'
82
+ protected
83
+
84
+ def run_process(method, cmd, env, options = {})
85
+ Bundler.with_clean_env do
86
+ method.call \
87
+ env.merge('TEST_DATABASE' => database_name),
88
+ cmd,
89
+ options.merge(chdir: fixture_dir)
87
90
  end
88
91
  end
92
+ end
93
+
94
+ shared_context 'Rails app pg database' do |dir|
95
+ before(:all) { @app = TestRailsApp.for_fixture dir }
96
+ let(:app) { @app }
97
+ end
98
+
99
+ shared_context 'rails integration test setup' do
100
+ let(:tmpdir) { app.tmpdir }
101
+
102
+ before(:all) { @app.run_specs } unless use_existing_data?
89
103
 
90
- let(:appmap) { JSON.parse File.read File.join tmpdir, 'appmap/rspec', appmap_json_file }
91
104
  let(:appmap_json_path) { File.join(tmpdir, 'appmap/rspec', appmap_json_file) }
92
105
  let(:appmap) { JSON.parse File.read(appmap_json_path) }
93
106
  let(:events) { appmap['events'] }
@@ -3,7 +3,7 @@ require 'rails_spec_helper'
3
3
  # Rails5 doesn't work with Ruby 3.x, Rails 7 doesn't work with Ruby < 2.7.
4
4
  def default_rails_versions
5
5
  if testing_ruby_2?
6
- if Gem::Requirement.create('>= 2.7') =~ Gem::Version.new(ENV['RUBY_VERSION'])
6
+ if Gem::Requirement.create('>= 2.7') =~ Gem::Version.new(RUBY_VERSION)
7
7
  [ 5, 6, 7 ]
8
8
  else
9
9
  [ 5, 6 ]
@@ -21,24 +21,14 @@ describe 'Rails' do
21
21
  rails_versions.each do |rails_major_version| # rubocop:disable Metrics/BlockLength
22
22
  context "#{rails_major_version}" do
23
23
  include_context 'Rails app pg database', "spec/fixtures/rails#{rails_major_version}_users_app" unless use_existing_data?
24
- def tmpdir
25
- 'tmp/spec/rails_test_spec'
26
- end
27
- before(:all) do
28
- FileUtils.rm_rf tmpdir
29
- FileUtils.mkdir_p tmpdir
30
- end
31
-
32
- def run_tests
33
- cmd = <<~CMD.gsub "\n", ' '
34
- docker-compose run --rm -e RAILS_ENV=test -e APPMAP=true -e TEST_OPTS=--verbose
35
- -v #{File.absolute_path tmpdir}:/app/tmp app bundle exec rake
36
- CMD
37
- run_cmd cmd, chdir: fixture_dir
38
- end
39
24
 
40
25
  it 'runs tests with APPMAP=true' do
41
- run_tests
26
+ app.prepare_db
27
+ app.run_cmd \
28
+ 'bundle exec rake',
29
+ 'RAILS_ENV' => 'test',
30
+ 'APPMAP' => 'true',
31
+ 'TEST_OPTS' => '--verbose'
42
32
  end
43
33
  end
44
34
  end
data/spec/railtie_spec.rb CHANGED
@@ -1,27 +1,13 @@
1
1
  require 'rails_spec_helper'
2
2
 
3
3
  describe 'AppMap tracer via Railtie' do
4
- include_context 'Rails app pg database', 'spec/fixtures/rails6_users_app' do
4
+ include_context 'Rails app pg database', 'spec/fixtures/rails6_users_app' do
5
5
  let(:env) { {} }
6
6
 
7
- let(:cmd) { %(docker-compose run --rm -e RAILS_ENV=development -e APPMAP app ./bin/rails r "puts AppMap.instance_variable_get('@configuration').nil?") }
8
- let(:command_capture2) do
9
- require 'open3'
10
- Open3.capture3(env, cmd, chdir: fixture_dir).tap do |result|
11
- unless result[2] == 0
12
- warn <<~STDERR
13
- Failed to run rails6_users_app container
14
- <<< Output:
15
- #{result[0]}
16
- #{result[1]}
17
- >>> End of output
18
- STDERR
19
- raise 'Failed to run rails6_users_app container'
20
- end
21
- end
7
+ let(:command_output) do
8
+ app.prepare_db
9
+ app.capture_cmd(%{./bin/rails r "puts AppMap.instance_variable_get('@configuration').nil?"}, env).strip
22
10
  end
23
- let(:command_output) { command_capture2[0].strip }
24
- let(:command_result) { command_capture2[2] }
25
11
 
26
12
  describe 'with APPMAP=false' do
27
13
  let(:env) { { 'APPMAP' => 'false' } }