appmap 0.37.0 → 0.40.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (211) hide show
  1. checksums.yaml +4 -4
  2. data/.dockerignore +1 -1
  3. data/.rubocop.yml +12 -1
  4. data/.travis.yml +2 -23
  5. data/CHANGELOG.md +24 -0
  6. data/CONTRIBUTING.md +22 -0
  7. data/README.md +79 -50
  8. data/Rakefile +3 -3
  9. data/lib/appmap/class_map.rb +25 -8
  10. data/lib/appmap/config.rb +22 -10
  11. data/lib/appmap/event.rb +16 -1
  12. data/lib/appmap/hook.rb +11 -3
  13. data/lib/appmap/hook/method.rb +18 -12
  14. data/lib/appmap/rails/request_handler.rb +25 -4
  15. data/lib/appmap/railtie.rb +1 -5
  16. data/lib/appmap/trace.rb +18 -7
  17. data/lib/appmap/version.rb +2 -2
  18. data/spec/abstract_controller_base_spec.rb +132 -67
  19. data/spec/fixtures/hook/instance_method.rb +4 -0
  20. data/spec/fixtures/hook/labels.rb +6 -0
  21. data/spec/fixtures/{rails_users_app → rails5_users_app}/.dockerignore +0 -0
  22. data/spec/fixtures/{rails_users_app → rails5_users_app}/.gitignore +0 -0
  23. data/spec/fixtures/{rails_users_app → rails5_users_app}/.rspec +0 -0
  24. data/spec/fixtures/{rails_users_app → rails5_users_app}/.ruby-version +0 -0
  25. data/spec/fixtures/{rails_users_app → rails5_users_app}/Dockerfile +0 -0
  26. data/spec/fixtures/{rails_users_app → rails5_users_app}/Dockerfile.pg +0 -0
  27. data/spec/fixtures/rails5_users_app/Gemfile +50 -0
  28. data/spec/fixtures/{rails_users_app → rails5_users_app}/Rakefile +0 -0
  29. data/spec/fixtures/{rails_users_app → rails5_users_app}/app/controllers/api/users_controller.rb +0 -0
  30. data/spec/fixtures/{rails_users_app → rails5_users_app}/app/controllers/application_controller.rb +0 -0
  31. data/spec/fixtures/{rails4_users_app/app/assets/images → rails5_users_app/app/controllers/concerns}/.keep +0 -0
  32. data/spec/fixtures/{rails_users_app → rails5_users_app}/app/controllers/health_controller.rb +0 -0
  33. data/spec/fixtures/rails5_users_app/app/controllers/users_controller.rb +13 -0
  34. data/spec/fixtures/{rails4_users_app/app/models → rails5_users_app/app/models/activerecord}/user.rb +0 -0
  35. data/spec/fixtures/{rails4_users_app/app/controllers → rails5_users_app/app/models}/concerns/.keep +0 -0
  36. data/spec/fixtures/{rails_users_app → rails5_users_app}/app/models/sequel/user.rb +0 -0
  37. data/spec/fixtures/{rails4_users_app → rails5_users_app}/app/views/layouts/application.html.haml +0 -0
  38. data/spec/fixtures/{rails4_users_app → rails5_users_app}/app/views/users/index.html.haml +0 -0
  39. data/spec/fixtures/rails5_users_app/appmap.yml +4 -0
  40. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/appmap +0 -0
  41. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/byebug +0 -0
  42. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/gli +0 -0
  43. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/htmldiff +0 -0
  44. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/ldiff +0 -0
  45. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/nokogiri +0 -0
  46. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/rackup +0 -0
  47. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/rails +0 -0
  48. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/rake +0 -0
  49. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/rspec +0 -0
  50. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/ruby-parse +0 -0
  51. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/ruby-rewrite +0 -0
  52. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/sequel +0 -0
  53. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/setup +0 -0
  54. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/sprockets +0 -0
  55. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/thor +0 -0
  56. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/update +0 -0
  57. data/spec/fixtures/{rails_users_app → rails5_users_app}/config.ru +0 -0
  58. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/application.rb +2 -0
  59. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/boot.rb +0 -0
  60. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/credentials.yml.enc +0 -0
  61. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/database.yml +0 -0
  62. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/environment.rb +0 -0
  63. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/environments/development.rb +0 -0
  64. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/environments/production.rb +0 -0
  65. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/environments/test.rb +0 -0
  66. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/initializers/application_controller_renderer.rb +0 -0
  67. data/spec/fixtures/{rails4_users_app → rails5_users_app}/config/initializers/backtrace_silencers.rb +0 -0
  68. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/initializers/cors.rb +0 -0
  69. data/spec/fixtures/{rails4_users_app → rails5_users_app}/config/initializers/filter_parameter_logging.rb +0 -0
  70. data/spec/fixtures/{rails4_users_app → rails5_users_app}/config/initializers/inflections.rb +0 -0
  71. data/spec/fixtures/{rails4_users_app → rails5_users_app}/config/initializers/mime_types.rb +0 -0
  72. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/initializers/record_button.rb +0 -0
  73. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/initializers/wrap_parameters.rb +0 -0
  74. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/locales/en.yml +0 -0
  75. data/spec/fixtures/{rails4_users_app → rails5_users_app}/config/routes.rb +1 -2
  76. data/spec/fixtures/{rails_users_app → rails5_users_app}/create_app +0 -0
  77. data/spec/fixtures/{rails_users_app → rails5_users_app}/db/migrate/20190728211408_create_users.rb +0 -0
  78. data/spec/fixtures/{rails_users_app → rails5_users_app}/db/schema.rb +0 -0
  79. data/spec/fixtures/{rails_users_app → rails5_users_app}/docker-compose.yml +0 -0
  80. data/spec/fixtures/{rails_users_app → rails5_users_app}/features/api_users.feature +0 -0
  81. data/spec/fixtures/{rails_users_app → rails5_users_app}/features/support/env.rb +0 -0
  82. data/spec/fixtures/{rails_users_app → rails5_users_app}/features/support/hooks.rb +0 -0
  83. data/spec/fixtures/{rails_users_app → rails5_users_app}/features/support/steps.rb +0 -0
  84. data/spec/fixtures/{rails4_users_app/app/mailers → rails5_users_app/lib/tasks}/.keep +0 -0
  85. data/spec/fixtures/{rails4_users_app/app/models → rails5_users_app/log}/.keep +0 -0
  86. data/spec/fixtures/{rails_users_app → rails5_users_app}/public/robots.txt +0 -0
  87. data/spec/fixtures/{rails_users_app → rails5_users_app}/spec/controllers/users_controller_api_spec.rb +1 -1
  88. data/spec/fixtures/rails5_users_app/spec/controllers/users_controller_spec.rb +27 -0
  89. data/spec/fixtures/{rails_users_app → rails5_users_app}/spec/models/user_spec.rb +0 -0
  90. data/spec/fixtures/{rails_users_app → rails5_users_app}/spec/rails_helper.rb +0 -0
  91. data/spec/fixtures/{rails4_users_app → rails5_users_app}/spec/spec_helper.rb +0 -0
  92. data/spec/fixtures/{rails_users_app → rails5_users_app}/users_app/.gitignore +0 -0
  93. data/spec/fixtures/rails6_users_app/.dockerignore +1 -0
  94. data/spec/fixtures/rails6_users_app/.gitignore +39 -0
  95. data/spec/fixtures/rails6_users_app/.rspec +1 -0
  96. data/spec/fixtures/rails6_users_app/.ruby-version +1 -0
  97. data/spec/fixtures/{rails4_users_app → rails6_users_app}/Dockerfile +3 -4
  98. data/spec/fixtures/{rails4_users_app → rails6_users_app}/Dockerfile.pg +1 -1
  99. data/spec/fixtures/{rails_users_app → rails6_users_app}/Gemfile +3 -4
  100. data/spec/fixtures/{rails4_users_app → rails6_users_app}/Rakefile +1 -1
  101. data/spec/fixtures/{rails4_users_app → rails6_users_app}/app/controllers/api/users_controller.rb +1 -1
  102. data/spec/fixtures/rails6_users_app/app/controllers/application_controller.rb +2 -0
  103. data/spec/fixtures/{rails4_users_app/app/models → rails6_users_app/app/controllers}/concerns/.keep +0 -0
  104. data/spec/fixtures/{rails4_users_app → rails6_users_app}/app/controllers/health_controller.rb +1 -1
  105. data/spec/fixtures/rails6_users_app/app/controllers/users_controller.rb +13 -0
  106. data/spec/fixtures/{rails_users_app → rails6_users_app}/app/models/activerecord/user.rb +0 -0
  107. data/spec/fixtures/{rails4_users_app/lib/assets → rails6_users_app/app/models/concerns}/.keep +0 -0
  108. data/spec/fixtures/rails6_users_app/app/models/sequel/user.rb +25 -0
  109. data/spec/fixtures/{rails_users_app → rails6_users_app}/app/views/layouts/application.html.haml +0 -0
  110. data/spec/fixtures/{rails_users_app → rails6_users_app}/app/views/users/index.html.haml +0 -0
  111. data/spec/fixtures/rails6_users_app/appmap.yml +5 -0
  112. data/spec/fixtures/rails6_users_app/bin/appmap +29 -0
  113. data/spec/fixtures/rails6_users_app/bin/byebug +29 -0
  114. data/spec/fixtures/rails6_users_app/bin/gli +29 -0
  115. data/spec/fixtures/rails6_users_app/bin/htmldiff +29 -0
  116. data/spec/fixtures/rails6_users_app/bin/ldiff +29 -0
  117. data/spec/fixtures/rails6_users_app/bin/nokogiri +29 -0
  118. data/spec/fixtures/rails6_users_app/bin/rackup +29 -0
  119. data/spec/fixtures/rails6_users_app/bin/rails +4 -0
  120. data/spec/fixtures/rails6_users_app/bin/rake +29 -0
  121. data/spec/fixtures/rails6_users_app/bin/rspec +29 -0
  122. data/spec/fixtures/rails6_users_app/bin/ruby-parse +29 -0
  123. data/spec/fixtures/rails6_users_app/bin/ruby-rewrite +29 -0
  124. data/spec/fixtures/rails6_users_app/bin/sequel +29 -0
  125. data/spec/fixtures/rails6_users_app/bin/setup +25 -0
  126. data/spec/fixtures/rails6_users_app/bin/sprockets +29 -0
  127. data/spec/fixtures/rails6_users_app/bin/thor +29 -0
  128. data/spec/fixtures/rails6_users_app/bin/update +25 -0
  129. data/spec/fixtures/{rails4_users_app → rails6_users_app}/config.ru +2 -1
  130. data/spec/fixtures/rails6_users_app/config/application.rb +53 -0
  131. data/spec/fixtures/rails6_users_app/config/boot.rb +3 -0
  132. data/spec/fixtures/rails6_users_app/config/credentials.yml.enc +1 -0
  133. data/spec/fixtures/{rails4_users_app → rails6_users_app}/config/database.yml +2 -2
  134. data/spec/fixtures/{rails4_users_app → rails6_users_app}/config/environment.rb +1 -1
  135. data/spec/fixtures/rails6_users_app/config/environments/development.rb +40 -0
  136. data/spec/fixtures/{rails4_users_app → rails6_users_app}/config/environments/production.rb +19 -30
  137. data/spec/fixtures/{rails4_users_app → rails6_users_app}/config/environments/test.rb +5 -11
  138. data/spec/fixtures/rails6_users_app/config/initializers/application_controller_renderer.rb +8 -0
  139. data/spec/fixtures/{rails_users_app → rails6_users_app}/config/initializers/backtrace_silencers.rb +0 -0
  140. data/spec/fixtures/rails6_users_app/config/initializers/cors.rb +16 -0
  141. data/spec/fixtures/{rails_users_app → rails6_users_app}/config/initializers/filter_parameter_logging.rb +0 -0
  142. data/spec/fixtures/{rails_users_app → rails6_users_app}/config/initializers/inflections.rb +0 -0
  143. data/spec/fixtures/{rails_users_app → rails6_users_app}/config/initializers/mime_types.rb +0 -0
  144. data/spec/fixtures/rails6_users_app/config/initializers/record_button.rb +3 -0
  145. data/spec/fixtures/{rails4_users_app → rails6_users_app}/config/initializers/wrap_parameters.rb +1 -6
  146. data/spec/fixtures/{rails4_users_app → rails6_users_app}/config/locales/en.yml +10 -0
  147. data/spec/fixtures/{rails_users_app → rails6_users_app}/config/routes.rb +1 -1
  148. data/spec/fixtures/{rails4_users_app → rails6_users_app}/create_app +7 -3
  149. data/spec/fixtures/rails6_users_app/db/migrate/20190728211408_create_users.rb +9 -0
  150. data/spec/fixtures/rails6_users_app/db/schema.rb +23 -0
  151. data/spec/fixtures/{rails4_users_app → rails6_users_app}/docker-compose.yml +3 -1
  152. data/spec/fixtures/rails6_users_app/features/api_users.feature +13 -0
  153. data/spec/fixtures/rails6_users_app/features/support/env.rb +4 -0
  154. data/spec/fixtures/rails6_users_app/features/support/hooks.rb +11 -0
  155. data/spec/fixtures/rails6_users_app/features/support/steps.rb +18 -0
  156. data/spec/fixtures/{rails4_users_app → rails6_users_app}/lib/tasks/.keep +0 -0
  157. data/spec/fixtures/{rails4_users_app → rails6_users_app}/log/.keep +0 -0
  158. data/spec/fixtures/rails6_users_app/public/robots.txt +1 -0
  159. data/spec/fixtures/rails6_users_app/spec/controllers/users_controller_api_spec.rb +29 -0
  160. data/spec/fixtures/rails6_users_app/spec/controllers/users_controller_spec.rb +27 -0
  161. data/spec/fixtures/rails6_users_app/spec/models/user_spec.rb +39 -0
  162. data/spec/fixtures/{rails4_users_app → rails6_users_app}/spec/rails_helper.rb +3 -32
  163. data/spec/fixtures/{rails_users_app → rails6_users_app}/spec/spec_helper.rb +0 -0
  164. data/spec/fixtures/{rails4_users_app → rails6_users_app/users_app}/.gitignore +8 -1
  165. data/spec/hook_spec.rb +111 -57
  166. data/spec/rails_spec_helper.rb +5 -5
  167. data/spec/railtie_spec.rb +31 -32
  168. data/spec/record_sql_rails_pg_spec.rb +62 -63
  169. data/spec/remote_recording_spec.rb +90 -89
  170. data/spec/rspec_feature_metadata_spec.rb +17 -18
  171. data/spec/spec_helper.rb +1 -0
  172. metadata +148 -139
  173. data/spec/abstract_controller4_base_spec.rb +0 -67
  174. data/spec/fixtures/rails4_users_app/.rbenv-gemsets +0 -2
  175. data/spec/fixtures/rails4_users_app/.ruby-version +0 -1
  176. data/spec/fixtures/rails4_users_app/Gemfile +0 -77
  177. data/spec/fixtures/rails4_users_app/README.rdoc +0 -28
  178. data/spec/fixtures/rails4_users_app/app/assets/javascripts/application.js +0 -16
  179. data/spec/fixtures/rails4_users_app/app/assets/stylesheets/application.css +0 -15
  180. data/spec/fixtures/rails4_users_app/app/controllers/application_controller.rb +0 -5
  181. data/spec/fixtures/rails4_users_app/app/controllers/users_controller.rb +0 -5
  182. data/spec/fixtures/rails4_users_app/app/helpers/application_helper.rb +0 -2
  183. data/spec/fixtures/rails4_users_app/appmap.yml +0 -3
  184. data/spec/fixtures/rails4_users_app/bin/rails +0 -9
  185. data/spec/fixtures/rails4_users_app/bin/setup +0 -29
  186. data/spec/fixtures/rails4_users_app/bin/spring +0 -17
  187. data/spec/fixtures/rails4_users_app/config/application.rb +0 -26
  188. data/spec/fixtures/rails4_users_app/config/boot.rb +0 -3
  189. data/spec/fixtures/rails4_users_app/config/environments/development.rb +0 -41
  190. data/spec/fixtures/rails4_users_app/config/initializers/assets.rb +0 -11
  191. data/spec/fixtures/rails4_users_app/config/initializers/cookies_serializer.rb +0 -3
  192. data/spec/fixtures/rails4_users_app/config/initializers/session_store.rb +0 -3
  193. data/spec/fixtures/rails4_users_app/config/initializers/to_time_preserves_timezone.rb +0 -10
  194. data/spec/fixtures/rails4_users_app/config/secrets.yml +0 -22
  195. data/spec/fixtures/rails4_users_app/db/migrate/20191127112304_create_users.rb +0 -10
  196. data/spec/fixtures/rails4_users_app/db/schema.rb +0 -26
  197. data/spec/fixtures/rails4_users_app/db/seeds.rb +0 -7
  198. data/spec/fixtures/rails4_users_app/public/404.html +0 -67
  199. data/spec/fixtures/rails4_users_app/public/422.html +0 -67
  200. data/spec/fixtures/rails4_users_app/public/500.html +0 -66
  201. data/spec/fixtures/rails4_users_app/public/favicon.ico +0 -0
  202. data/spec/fixtures/rails4_users_app/public/robots.txt +0 -5
  203. data/spec/fixtures/rails4_users_app/spec/controllers/users_controller_api_spec.rb +0 -49
  204. data/spec/fixtures/rails4_users_app/test/fixtures/users.yml +0 -9
  205. data/spec/fixtures/rails_users_app/app/controllers/concerns/.keep +0 -0
  206. data/spec/fixtures/rails_users_app/app/controllers/users_controller.rb +0 -5
  207. data/spec/fixtures/rails_users_app/app/models/concerns/.keep +0 -0
  208. data/spec/fixtures/rails_users_app/appmap.yml +0 -3
  209. data/spec/fixtures/rails_users_app/lib/tasks/.keep +0 -0
  210. data/spec/fixtures/rails_users_app/log/.keep +0 -0
  211. data/spec/record_sql_rails4_pg_spec.rb +0 -76
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ When 'I create a user' do
4
+ @response = post '/api/users', login: 'alice'
5
+ end
6
+
7
+ Then(/the response status should be (\d+)/) do |status|
8
+ expect(@response.status).to eq(status.to_i)
9
+ end
10
+
11
+ When 'I list the users' do
12
+ @response = get '/api/users'
13
+ @users = JSON.parse(@response.body)
14
+ end
15
+
16
+ Then 'the response should include the user' do
17
+ expect(@users.map { |u| u['login'] }).to include('alice')
18
+ end
@@ -0,0 +1 @@
1
+ # See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
@@ -0,0 +1,29 @@
1
+ require 'rails_helper'
2
+ require 'rack/test'
3
+
4
+ RSpec.describe Api::UsersController, feature_group: 'Users', type: :controller, appmap: true do
5
+ describe 'POST /api/users', feature: 'Create a user' do
6
+ describe 'with required parameters' do
7
+ it 'creates a user' do
8
+ post :create, params: { login: 'alice', password: 'foobar' }
9
+ expect(response.status).to eq(201)
10
+ end
11
+ end
12
+ describe 'with a missing parameter' do
13
+ it 'reports error 422' do
14
+ post :create, params: {}
15
+ expect(response.status).to eq(422)
16
+ end
17
+ end
18
+ end
19
+ describe 'GET /api/users', feature: 'List users' do
20
+ before do
21
+ post :create, params: { login: 'alice' }
22
+ end
23
+ it 'lists the users' do
24
+ get :index, params: {}
25
+ users = JSON.parse(response.body)
26
+ expect(users.map { |r| r['login'] }).to include('alice')
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,27 @@
1
+ require 'rails_helper'
2
+ require 'rack/test'
3
+
4
+ RSpec.describe UsersController, type: :controller do
5
+ render_views
6
+
7
+ describe 'GET /users', feature: 'Show all users' do
8
+ before do
9
+ User.create login: 'alice'
10
+ end
11
+ it 'lists the users' do
12
+ get :index
13
+ expect(response).to be_ok
14
+ end
15
+ end
16
+
17
+ describe 'GET /users/:login', feature: 'Show a user' do
18
+ before do
19
+ User.create login: 'alice'
20
+ end
21
+
22
+ it 'shows the user' do
23
+ get :show, params: { id: 'alice' }
24
+ expect(response).to be_ok
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,39 @@
1
+ require 'rails_helper'
2
+
3
+ describe User, feature_group: 'User', appmap: true do
4
+ # TODO: appmap/rspec doesn't handle shared_examples_for 100% correctly yet.
5
+ # In my tests, only one of these two tests will be emitted as an appmap.
6
+ shared_examples_for 'creates the user' do |username|
7
+ let(:login) { username }
8
+ let(:user) { User.new(login: login) }
9
+ it "creates #{username.inspect}" do
10
+ expect(user.save(raise_on_failure: true)).to be_truthy
11
+ end
12
+ end
13
+
14
+ describe 'creation', feature: 'Create a user' do
15
+ context 'using shared_examples_for' do
16
+ # AppMap.
17
+ # context "with username 'alice'" do
18
+ # it_should_behave_like 'creates the user', 'alice'
19
+ # end
20
+ # context "with username 'bob'" do
21
+ # it_should_behave_like 'creates the user', 'bob'
22
+ # end
23
+ end
24
+
25
+ # So, instead of shared_examples_for, let's go with a simple method
26
+ # containing the assertions. The method can be called from within an example.
27
+ def save_and_verify
28
+ expect(user.save(raise_on_failure: true)).to be_truthy
29
+ end
30
+
31
+ context do
32
+ let(:login) { 'charles' }
33
+ let(:user) { User.new(login: login) }
34
+ it "creates 'charles'" do
35
+ save_and_verify
36
+ end
37
+ end
38
+ end
39
+ end
@@ -1,31 +1,12 @@
1
- STDERR.puts "rails4_users_app rails_helper"
2
1
  # This file is copied to spec/ when you run 'rails generate rspec:install'
3
2
  require 'spec_helper'
4
3
  ENV['RAILS_ENV'] ||= 'test'
5
-
6
- require File.expand_path('../config/environment', __dir__)
7
-
4
+ require File.expand_path('../../config/environment', __FILE__)
8
5
  # Prevent database truncation if the environment is production
9
6
  abort("The Rails environment is running in production mode!") if Rails.env.production?
10
7
  require 'rspec/rails'
11
8
  # Add additional requires below this line. Rails is not loaded until this point!
12
9
 
13
- # The issue this hack works around is discussed here
14
- # https://github.com/rails/rails/issues/34790, with the comment that
15
- # it won't be fixed here:
16
- # https://github.com/rails/rails/issues/34790#issuecomment-450036849
17
- if RUBY_VERSION >= '2.6.0'
18
- class ActionController::TestResponse < ActionDispatch::TestResponse
19
- def recycle!
20
- # hack to avoid MonitorMixin double-initialize error:
21
- @mon_mutex_owner_object_id = nil
22
- @mon_mutex = nil
23
- initialize
24
- end
25
- end
26
- end
27
-
28
-
29
10
  require 'appmap/rspec'
30
11
 
31
12
  # Requires supporting ruby files with custom matchers and macros, etc, in
@@ -43,18 +24,7 @@ require 'appmap/rspec'
43
24
  #
44
25
  # Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f }
45
26
 
46
- # Checks for pending migrations and applies them before tests are run.
47
- # If you are not using ActiveRecord, you can remove these lines.
48
- begin
49
- ActiveRecord::Migration.maintain_test_schema!
50
- rescue ActiveRecord::PendingMigrationError => e
51
- puts e.to_s.strip
52
- exit 1
53
- end
54
27
  RSpec.configure do |config|
55
- # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
56
- config.fixture_path = "#{::Rails.root}/spec/fixtures"
57
-
58
28
  # RSpec Rails can automatically mix in different behaviours to your tests
59
29
  # based on their file location, for example enabling you to call `get` and
60
30
  # `post` in specs under `spec/controllers`.
@@ -75,6 +45,8 @@ RSpec.configure do |config|
75
45
  # arbitrary gems may also be filtered via:
76
46
  # config.filter_gems_from_backtrace("gem name")
77
47
 
48
+
49
+ DatabaseCleaner.allow_remote_database_url = true
78
50
 
79
51
  config.before(:suite) do
80
52
  DatabaseCleaner.strategy = :transaction
@@ -91,5 +63,4 @@ RSpec.configure do |config|
91
63
  end
92
64
  }.call
93
65
  end
94
-
95
66
  end
@@ -9,5 +9,12 @@
9
9
 
10
10
  # Ignore all logfiles and tempfiles.
11
11
  /log/*
12
+ /tmp/*
12
13
  !/log/.keep
13
- /tmp
14
+ !/tmp/.keep
15
+
16
+
17
+ .byebug_history
18
+
19
+ # Ignore master key for decrypting credentials and more.
20
+ /config/master.key
@@ -52,15 +52,41 @@ describe 'AppMap class Hooking', docker: false do
52
52
 
53
53
  events = collect_events(tracer).to_yaml
54
54
 
55
- expect(Diffy::Diff.new(events_yaml, events).to_s).to eq('')
55
+ expect(Diffy::Diff.new(events_yaml, events).to_s).to eq('') if events_yaml
56
56
 
57
- [ config, tracer ]
57
+ [ config, tracer, events ]
58
58
  end
59
59
 
60
60
  after do
61
61
  AppMap.configuration = nil
62
62
  end
63
63
 
64
+ it 'parses labels from comments' do
65
+ _, tracer = invoke_test_file 'spec/fixtures/hook/labels.rb' do
66
+ ClassWithLabel.new.fn_with_label
67
+ end
68
+ class_map = AppMap.class_map(tracer.event_methods).to_yaml
69
+ expect(Diffy::Diff.new(<<~YAML, class_map).to_s).to eq('')
70
+ ---
71
+ - :name: spec/fixtures/hook/labels.rb
72
+ :type: package
73
+ :children:
74
+ - :name: ClassWithLabel
75
+ :type: class
76
+ :children:
77
+ - :name: fn_with_label
78
+ :type: function
79
+ :location: spec/fixtures/hook/labels.rb:4
80
+ :static: false
81
+ :labels:
82
+ - has-fn-label
83
+ :comment: "# @label has-fn-label\\n"
84
+ :source: |2
85
+ def fn_with_label
86
+ end
87
+ YAML
88
+ end
89
+
64
90
  it 'hooks an instance method that takes no arguments' do
65
91
  events_yaml = <<~YAML
66
92
  ---
@@ -181,8 +207,8 @@ describe 'AppMap class Hooking', docker: false do
181
207
  :static: false
182
208
  :parameters:
183
209
  - :name: :kw
184
- :class: Hash
185
- :value: '{:kw=>"kw"}'
210
+ :class: String
211
+ :value: kw
186
212
  :kind: :key
187
213
  :receiver:
188
214
  :class: InstanceMethod
@@ -229,6 +255,48 @@ describe 'AppMap class Hooking', docker: false do
229
255
  end
230
256
  end
231
257
 
258
+ it 'hooks an instance method that takes keyword arguments' do
259
+ events_yaml = <<~YAML
260
+ ---
261
+ - :id: 1
262
+ :event: :call
263
+ :defined_class: InstanceMethod
264
+ :method_id: say_kws
265
+ :path: spec/fixtures/hook/instance_method.rb
266
+ :lineno: 20
267
+ :static: false
268
+ :parameters:
269
+ - :name: :args
270
+ :class: Array
271
+ :value: "[4, 5]"
272
+ :kind: :rest
273
+ - :name: :kw1
274
+ :class: String
275
+ :value: one
276
+ :kind: :keyreq
277
+ - :name: :kw2
278
+ :class: Integer
279
+ :value: '2'
280
+ :kind: :key
281
+ - :name: :kws
282
+ :class: Hash
283
+ :value: "{:kw3=>:three}"
284
+ :kind: :keyrest
285
+ :receiver:
286
+ :class: InstanceMethod
287
+ :value: Instance Method fixture
288
+ - :id: 2
289
+ :event: :return
290
+ :parent_id: 1
291
+ :return_value:
292
+ :class: String
293
+ :value: one2{:kw3=>:three}45
294
+ YAML
295
+ test_hook_behavior 'spec/fixtures/hook/instance_method.rb', events_yaml do
296
+ expect(InstanceMethod.new.say_kws(4, 5, kw1: 'one', kw2: 2, kw3: :three)).to eq('one2{:kw3=>:three}45')
297
+ end
298
+ end
299
+
232
300
  it 'hooks an instance method that takes a block argument' do
233
301
  events_yaml = <<~YAML
234
302
  ---
@@ -237,7 +305,7 @@ describe 'AppMap class Hooking', docker: false do
237
305
  :defined_class: InstanceMethod
238
306
  :method_id: say_block
239
307
  :path: spec/fixtures/hook/instance_method.rb
240
- :lineno: 20
308
+ :lineno: 24
241
309
  :static: false
242
310
  :parameters:
243
311
  - :name: :block
@@ -405,7 +473,7 @@ describe 'AppMap class Hooking', docker: false do
405
473
 
406
474
  # Verify the native extension works as expected
407
475
  expect(AppMap::Hook.singleton_method_owner_name(say_instance_defined)).to eq('SingletonMethod')
408
-
476
+
409
477
  expect(s.say_instance_defined).to eq('defined for an instance')
410
478
  end
411
479
  end
@@ -436,7 +504,7 @@ describe 'AppMap class Hooking', docker: false do
436
504
  expect(SingletonMethod::STRUCT_TEST.say_struct_singleton).to eq('singleton for a struct')
437
505
  end
438
506
  end
439
-
507
+
440
508
  it 'Reports exceptions' do
441
509
  events_yaml = <<~YAML
442
510
  ---
@@ -475,24 +543,6 @@ describe 'AppMap class Hooking', docker: false do
475
543
  events_yaml = <<~YAML
476
544
  ---
477
545
  - :id: 1
478
- :event: :call
479
- :defined_class: NoToSMethod
480
- :method_id: respond_to?
481
- :path: spec/fixtures/hook/exception_method.rb
482
- :lineno: 24
483
- :static: false
484
- :parameters:
485
- - :name: :args
486
- :class: Symbol
487
- :value: to_s
488
- :kind: :rest
489
- :receiver:
490
- :class: Class
491
- :value: NoToSMethod
492
- - :id: 2
493
- :event: :return
494
- :parent_id: 1
495
- - :id: 3
496
546
  :event: :call
497
547
  :defined_class: NoToSMethod
498
548
  :method_id: say_hello
@@ -503,9 +553,9 @@ describe 'AppMap class Hooking', docker: false do
503
553
  :receiver:
504
554
  :class: Class
505
555
  :value: NoToSMethod
506
- - :id: 4
556
+ - :id: 2
507
557
  :event: :return
508
- :parent_id: 3
558
+ :parent_id: 1
509
559
  :return_value:
510
560
  :class: String
511
561
  :value: hello
@@ -523,24 +573,6 @@ describe 'AppMap class Hooking', docker: false do
523
573
  events_yaml = <<~YAML
524
574
  ---
525
575
  - :id: 1
526
- :event: :call
527
- :defined_class: NoToSMethod
528
- :method_id: respond_to?
529
- :path: spec/fixtures/hook/exception_method.rb
530
- :lineno: 24
531
- :static: false
532
- :parameters:
533
- - :name: :args
534
- :class: Symbol
535
- :value: to_s
536
- :kind: :rest
537
- :receiver:
538
- :class: Class
539
- :value: "*Error inspecting variable*"
540
- - :id: 2
541
- :event: :return
542
- :parent_id: 1
543
- - :id: 3
544
576
  :event: :call
545
577
  :defined_class: InspectRaises
546
578
  :method_id: say_hello
@@ -551,9 +583,9 @@ describe 'AppMap class Hooking', docker: false do
551
583
  :receiver:
552
584
  :class: Class
553
585
  :value: "*Error inspecting variable*"
554
- - :id: 4
586
+ - :id: 2
555
587
  :event: :return
556
- :parent_id: 3
588
+ :parent_id: 1
557
589
  :return_value:
558
590
  :class: String
559
591
  :value: hello
@@ -653,8 +685,8 @@ describe 'AppMap class Hooking', docker: false do
653
685
  :static: false
654
686
  :parameters:
655
687
  - :name: arg
656
- :class: String
657
- :value: string
688
+ :class: Array
689
+ :value: '["string"]'
658
690
  :kind: :rest
659
691
  :receiver:
660
692
  :class: Digest::SHA256
@@ -673,8 +705,8 @@ describe 'AppMap class Hooking', docker: false do
673
705
  :static: false
674
706
  :parameters:
675
707
  - :name: arg
676
- :class: String
677
- :value: string
708
+ :class: Array
709
+ :value: '["string"]'
678
710
  :kind: :rest
679
711
  :receiver:
680
712
  :class: Digest::SHA256
@@ -699,9 +731,33 @@ describe 'AppMap class Hooking', docker: false do
699
731
  :value: 'true'
700
732
  YAML
701
733
 
702
- test_hook_behavior 'spec/fixtures/hook/compare.rb', events_yaml do
734
+ _, _, events = test_hook_behavior 'spec/fixtures/hook/compare.rb', nil do
703
735
  expect(Compare.compare('string', 'string')).to be_truthy
704
736
  end
737
+ secure_compare_event = YAML.load(events).find { |evt| evt[:defined_class] == 'ActiveSupport::SecurityUtils' }
738
+ secure_compare_event.delete(:lineno)
739
+
740
+ expect(Diffy::Diff.new(<<~YAML, secure_compare_event.to_yaml).to_s).to eq('')
741
+ ---
742
+ :id: 2
743
+ :event: :call
744
+ :defined_class: ActiveSupport::SecurityUtils
745
+ :method_id: secure_compare
746
+ :path: lib/active_support/security_utils.rb
747
+ :static: true
748
+ :parameters:
749
+ - :name: :a
750
+ :class: String
751
+ :value: string
752
+ :kind: :req
753
+ - :name: :b
754
+ :class: String
755
+ :value: string
756
+ :kind: :req
757
+ :receiver:
758
+ :class: Module
759
+ :value: ActiveSupport::SecurityUtils
760
+ YAML
705
761
  end
706
762
 
707
763
  it 'gets labeled in the classmap' do
@@ -764,16 +820,14 @@ describe 'AppMap class Hooking', docker: false do
764
820
  - crypto
765
821
  YAML
766
822
 
767
- config, tracer = invoke_test_file 'spec/fixtures/hook/compare.rb' do
823
+ _, tracer = invoke_test_file 'spec/fixtures/hook/compare.rb' do
768
824
  expect(Compare.compare('string', 'string')).to be_truthy
769
825
  end
770
826
  cm = AppMap::Util.sanitize_paths(AppMap::ClassMap.build_from_methods(tracer.event_methods))
771
827
  entry = cm[1][:children][0][:children][0][:children][0]
772
828
  # Sanity check, make sure we got the right one
773
829
  expect(entry[:name]).to eq('secure_compare')
774
- spec = Gem::Specification.find_by_name('activesupport')
775
- entry[:location].gsub!(spec.base_dir + '/', '')
776
- expect(Diffy::Diff.new(classmap_yaml, cm.to_yaml).to_s).to eq('')
830
+ expect(entry[:labels]).to eq(%w[security crypto])
777
831
  end
778
832
  end
779
833
 
@@ -785,7 +839,7 @@ describe 'AppMap class Hooking', docker: false do
785
839
  :defined_class: InstanceMethod
786
840
  :method_id: say_the_time
787
841
  :path: spec/fixtures/hook/instance_method.rb
788
- :lineno: 24
842
+ :lineno: 28
789
843
  :static: false
790
844
  :parameters: []
791
845
  :receiver: