appmap 0.35.1 → 0.38.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (185) hide show
  1. checksums.yaml +4 -4
  2. data/.dockerignore +1 -1
  3. data/.gitignore +2 -1
  4. data/.rubocop.yml +10 -0
  5. data/CHANGELOG.md +22 -0
  6. data/README.md +14 -8
  7. data/Rakefile +3 -2
  8. data/appmap.gemspec +2 -1
  9. data/appmap.yml +1 -7
  10. data/lib/appmap.rb +2 -2
  11. data/lib/appmap/class_map.rb +20 -6
  12. data/lib/appmap/config.rb +66 -22
  13. data/lib/appmap/event.rb +21 -6
  14. data/lib/appmap/hook/method.rb +18 -12
  15. data/lib/appmap/rails/request_handler.rb +8 -1
  16. data/lib/appmap/railtie.rb +1 -1
  17. data/lib/appmap/rspec.rb +1 -1
  18. data/lib/appmap/trace.rb +18 -7
  19. data/lib/appmap/version.rb +2 -2
  20. data/spec/abstract_controller4_base_spec.rb +27 -28
  21. data/spec/abstract_controller_base_spec.rb +73 -38
  22. data/spec/class_map_spec.rb +36 -0
  23. data/spec/fixtures/hook/exception_method.rb +44 -0
  24. data/spec/fixtures/hook/instance_method.rb +4 -0
  25. data/spec/fixtures/{rails_users_app → rails5_users_app}/.dockerignore +0 -0
  26. data/spec/fixtures/{rails_users_app → rails5_users_app}/.gitignore +0 -0
  27. data/spec/fixtures/{rails_users_app → rails5_users_app}/.rspec +0 -0
  28. data/{.ruby-version → spec/fixtures/rails5_users_app/.ruby-version} +0 -0
  29. data/spec/fixtures/{rails_users_app → rails5_users_app}/Dockerfile +0 -0
  30. data/spec/fixtures/{rails_users_app → rails5_users_app}/Dockerfile.pg +0 -0
  31. data/spec/fixtures/rails5_users_app/Gemfile +51 -0
  32. data/spec/fixtures/{rails_users_app → rails5_users_app}/Rakefile +0 -0
  33. data/spec/fixtures/{rails_users_app → rails5_users_app}/app/controllers/api/users_controller.rb +0 -0
  34. data/spec/fixtures/{rails_users_app → rails5_users_app}/app/controllers/application_controller.rb +0 -0
  35. data/spec/fixtures/{rails_users_app → rails5_users_app}/app/controllers/concerns/.keep +0 -0
  36. data/spec/fixtures/{rails_users_app → rails5_users_app}/app/controllers/health_controller.rb +0 -0
  37. data/spec/fixtures/{rails_users_app → rails5_users_app}/app/controllers/users_controller.rb +0 -0
  38. data/spec/fixtures/{rails_users_app → rails5_users_app}/app/models/activerecord/user.rb +0 -0
  39. data/spec/fixtures/{rails_users_app → rails5_users_app}/app/models/concerns/.keep +0 -0
  40. data/spec/fixtures/{rails_users_app → rails5_users_app}/app/models/sequel/user.rb +0 -0
  41. data/spec/fixtures/{rails_users_app → rails5_users_app}/app/views/layouts/application.html.haml +0 -0
  42. data/spec/fixtures/{rails_users_app → rails5_users_app}/app/views/users/index.html.haml +0 -0
  43. data/spec/fixtures/rails5_users_app/appmap.yml +4 -0
  44. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/appmap +0 -0
  45. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/byebug +0 -0
  46. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/gli +0 -0
  47. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/htmldiff +0 -0
  48. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/ldiff +0 -0
  49. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/nokogiri +0 -0
  50. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/rackup +0 -0
  51. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/rails +0 -0
  52. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/rake +0 -0
  53. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/rspec +0 -0
  54. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/ruby-parse +0 -0
  55. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/ruby-rewrite +0 -0
  56. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/sequel +0 -0
  57. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/setup +0 -0
  58. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/sprockets +0 -0
  59. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/thor +0 -0
  60. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/update +0 -0
  61. data/spec/fixtures/{rails_users_app → rails5_users_app}/config.ru +0 -0
  62. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/application.rb +0 -0
  63. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/boot.rb +0 -0
  64. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/credentials.yml.enc +0 -0
  65. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/database.yml +0 -0
  66. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/environment.rb +0 -0
  67. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/environments/development.rb +0 -0
  68. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/environments/production.rb +0 -0
  69. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/environments/test.rb +0 -0
  70. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/initializers/application_controller_renderer.rb +0 -0
  71. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/initializers/backtrace_silencers.rb +0 -0
  72. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/initializers/cors.rb +0 -0
  73. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/initializers/filter_parameter_logging.rb +0 -0
  74. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/initializers/inflections.rb +0 -0
  75. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/initializers/mime_types.rb +0 -0
  76. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/initializers/record_button.rb +0 -0
  77. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/initializers/wrap_parameters.rb +0 -0
  78. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/locales/en.yml +0 -0
  79. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/routes.rb +0 -0
  80. data/spec/fixtures/{rails_users_app → rails5_users_app}/create_app +0 -0
  81. data/spec/fixtures/{rails_users_app → rails5_users_app}/db/migrate/20190728211408_create_users.rb +0 -0
  82. data/spec/fixtures/{rails_users_app → rails5_users_app}/db/schema.rb +0 -0
  83. data/spec/fixtures/{rails_users_app → rails5_users_app}/docker-compose.yml +0 -0
  84. data/spec/fixtures/{rails_users_app → rails5_users_app}/features/api_users.feature +0 -0
  85. data/spec/fixtures/{rails_users_app → rails5_users_app}/features/support/env.rb +0 -0
  86. data/spec/fixtures/{rails_users_app → rails5_users_app}/features/support/hooks.rb +0 -0
  87. data/spec/fixtures/{rails_users_app → rails5_users_app}/features/support/steps.rb +0 -0
  88. data/spec/fixtures/{rails_users_app → rails5_users_app}/lib/tasks/.keep +0 -0
  89. data/spec/fixtures/{rails_users_app → rails5_users_app}/log/.keep +0 -0
  90. data/spec/fixtures/{rails_users_app → rails5_users_app}/public/robots.txt +0 -0
  91. data/spec/fixtures/{rails_users_app → rails5_users_app}/spec/controllers/users_controller_api_spec.rb +1 -1
  92. data/spec/fixtures/rails5_users_app/spec/controllers/users_controller_spec.rb +16 -0
  93. data/spec/fixtures/{rails_users_app → rails5_users_app}/spec/models/user_spec.rb +0 -0
  94. data/spec/fixtures/{rails_users_app → rails5_users_app}/spec/rails_helper.rb +0 -0
  95. data/spec/fixtures/{rails_users_app → rails5_users_app}/spec/spec_helper.rb +0 -0
  96. data/spec/fixtures/{rails_users_app → rails5_users_app}/users_app/.gitignore +0 -0
  97. data/spec/fixtures/rails6_users_app/.dockerignore +1 -0
  98. data/spec/fixtures/rails6_users_app/.gitignore +39 -0
  99. data/spec/fixtures/rails6_users_app/.rspec +1 -0
  100. data/spec/fixtures/{rails_users_app → rails6_users_app}/.ruby-version +0 -0
  101. data/spec/fixtures/rails6_users_app/Dockerfile +29 -0
  102. data/spec/fixtures/rails6_users_app/Dockerfile.pg +3 -0
  103. data/spec/fixtures/{rails_users_app → rails6_users_app}/Gemfile +1 -1
  104. data/spec/fixtures/rails6_users_app/Rakefile +6 -0
  105. data/spec/fixtures/rails6_users_app/app/controllers/api/users_controller.rb +27 -0
  106. data/spec/fixtures/rails6_users_app/app/controllers/application_controller.rb +2 -0
  107. data/spec/fixtures/rails6_users_app/app/controllers/concerns/.keep +0 -0
  108. data/spec/fixtures/rails6_users_app/app/controllers/health_controller.rb +5 -0
  109. data/spec/fixtures/rails6_users_app/app/controllers/users_controller.rb +5 -0
  110. data/spec/fixtures/rails6_users_app/app/models/activerecord/user.rb +18 -0
  111. data/spec/fixtures/rails6_users_app/app/models/concerns/.keep +0 -0
  112. data/spec/fixtures/rails6_users_app/app/models/sequel/user.rb +25 -0
  113. data/spec/fixtures/rails6_users_app/app/views/layouts/application.html.haml +7 -0
  114. data/spec/fixtures/rails6_users_app/app/views/users/index.html.haml +7 -0
  115. data/spec/fixtures/rails6_users_app/appmap.yml +5 -0
  116. data/spec/fixtures/rails6_users_app/bin/appmap +29 -0
  117. data/spec/fixtures/rails6_users_app/bin/byebug +29 -0
  118. data/spec/fixtures/rails6_users_app/bin/gli +29 -0
  119. data/spec/fixtures/rails6_users_app/bin/htmldiff +29 -0
  120. data/spec/fixtures/rails6_users_app/bin/ldiff +29 -0
  121. data/spec/fixtures/rails6_users_app/bin/nokogiri +29 -0
  122. data/spec/fixtures/rails6_users_app/bin/rackup +29 -0
  123. data/spec/fixtures/rails6_users_app/bin/rails +4 -0
  124. data/spec/fixtures/rails6_users_app/bin/rake +29 -0
  125. data/spec/fixtures/rails6_users_app/bin/rspec +29 -0
  126. data/spec/fixtures/rails6_users_app/bin/ruby-parse +29 -0
  127. data/spec/fixtures/rails6_users_app/bin/ruby-rewrite +29 -0
  128. data/spec/fixtures/rails6_users_app/bin/sequel +29 -0
  129. data/spec/fixtures/rails6_users_app/bin/setup +25 -0
  130. data/spec/fixtures/rails6_users_app/bin/sprockets +29 -0
  131. data/spec/fixtures/rails6_users_app/bin/thor +29 -0
  132. data/spec/fixtures/rails6_users_app/bin/update +25 -0
  133. data/spec/fixtures/rails6_users_app/config.ru +5 -0
  134. data/spec/fixtures/rails6_users_app/config/application.rb +51 -0
  135. data/spec/fixtures/rails6_users_app/config/boot.rb +3 -0
  136. data/spec/fixtures/rails6_users_app/config/credentials.yml.enc +1 -0
  137. data/spec/fixtures/rails6_users_app/config/database.yml +18 -0
  138. data/spec/fixtures/rails6_users_app/config/environment.rb +5 -0
  139. data/spec/fixtures/rails6_users_app/config/environments/development.rb +40 -0
  140. data/spec/fixtures/rails6_users_app/config/environments/production.rb +68 -0
  141. data/spec/fixtures/rails6_users_app/config/environments/test.rb +36 -0
  142. data/spec/fixtures/rails6_users_app/config/initializers/application_controller_renderer.rb +8 -0
  143. data/spec/fixtures/rails6_users_app/config/initializers/backtrace_silencers.rb +7 -0
  144. data/spec/fixtures/rails6_users_app/config/initializers/cors.rb +16 -0
  145. data/spec/fixtures/rails6_users_app/config/initializers/filter_parameter_logging.rb +4 -0
  146. data/spec/fixtures/rails6_users_app/config/initializers/inflections.rb +16 -0
  147. data/spec/fixtures/rails6_users_app/config/initializers/mime_types.rb +4 -0
  148. data/spec/fixtures/rails6_users_app/config/initializers/record_button.rb +3 -0
  149. data/spec/fixtures/rails6_users_app/config/initializers/wrap_parameters.rb +9 -0
  150. data/spec/fixtures/rails6_users_app/config/locales/en.yml +33 -0
  151. data/spec/fixtures/rails6_users_app/config/routes.rb +11 -0
  152. data/spec/fixtures/rails6_users_app/create_app +27 -0
  153. data/spec/fixtures/rails6_users_app/db/migrate/20190728211408_create_users.rb +9 -0
  154. data/spec/fixtures/rails6_users_app/db/schema.rb +23 -0
  155. data/spec/fixtures/rails6_users_app/docker-compose.yml +28 -0
  156. data/spec/fixtures/rails6_users_app/features/api_users.feature +13 -0
  157. data/spec/fixtures/rails6_users_app/features/support/env.rb +4 -0
  158. data/spec/fixtures/rails6_users_app/features/support/hooks.rb +11 -0
  159. data/spec/fixtures/rails6_users_app/features/support/steps.rb +18 -0
  160. data/spec/fixtures/rails6_users_app/lib/tasks/.keep +0 -0
  161. data/spec/fixtures/rails6_users_app/log/.keep +0 -0
  162. data/spec/fixtures/rails6_users_app/public/robots.txt +1 -0
  163. data/spec/fixtures/rails6_users_app/spec/controllers/users_controller_api_spec.rb +29 -0
  164. data/spec/fixtures/rails6_users_app/spec/controllers/users_controller_spec.rb +16 -0
  165. data/spec/fixtures/rails6_users_app/spec/models/user_spec.rb +39 -0
  166. data/spec/fixtures/rails6_users_app/spec/rails_helper.rb +66 -0
  167. data/spec/fixtures/rails6_users_app/spec/spec_helper.rb +96 -0
  168. data/spec/fixtures/rails6_users_app/users_app/.gitignore +20 -0
  169. data/spec/hook_spec.rb +225 -18
  170. data/spec/rails_spec_helper.rb +5 -5
  171. data/spec/railtie_spec.rb +31 -32
  172. data/spec/record_sql_rails4_pg_spec.rb +47 -48
  173. data/spec/record_sql_rails_pg_spec.rb +62 -63
  174. data/spec/remote_recording_spec.rb +90 -89
  175. data/spec/rspec_feature_metadata_spec.rb +17 -18
  176. data/test/expectations/openssl_test_key_sign1.json +55 -0
  177. data/test/expectations/openssl_test_key_sign2.json +58 -0
  178. data/test/fixtures/gem_test/Gemfile +6 -0
  179. data/test/fixtures/gem_test/appmap.yml +3 -0
  180. data/test/fixtures/gem_test/test/to_param_test.rb +14 -0
  181. data/test/gem_test.rb +34 -0
  182. data/test/minitest_test.rb +2 -2
  183. data/test/openssl_test.rb +10 -117
  184. metadata +173 -80
  185. data/spec/fixtures/rails_users_app/appmap.yml +0 -3
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env bash
2
+ set -e
3
+
4
+ # Just checking for a healthy container isn't enough, apparently. If
5
+ # we don't wait here, sometimes the database is inaccessible.
6
+ for i in {1..10}; do
7
+ psql -h pg -U postgres postgres -c 'select 1' >/dev/null 2>&1 && break
8
+ printf ' .'
9
+ sleep 1
10
+ done
11
+ echo
12
+ out="$(psql -h pg -U postgres postgres -c 'select 1' 2>&1)"
13
+ if [[ $? != 0 ]]; then
14
+ echo "Postgres didn't start in time:"
15
+ echo "$out"
16
+ exit 1
17
+ fi
18
+
19
+ psql -h pg -U postgres -c "create database app_development"
20
+ psql -h pg -U postgres -c "create database app_test"
21
+
22
+ set -e
23
+
24
+ RAILS_ENV=development ./bin/rake db:migrate
25
+ RAILS_ENV=test ./bin/rake db:migrate
26
+
27
+ echo "INSERT INTO users ( login ) VALUES ( 'admin' ) " | psql -h pg -U postgres app_development
@@ -0,0 +1,9 @@
1
+ Sequel.migration do
2
+ change do
3
+ create_table :users do
4
+ primary_key :id
5
+ text :login, null: false, unique: true
6
+ column :password_digest, :bytea
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,23 @@
1
+ Sequel.migration do
2
+ change do
3
+ create_table(:schema_migrations) do
4
+ column :filename, "text", :null=>false
5
+
6
+ primary_key [:filename]
7
+ end
8
+
9
+ create_table(:users) do
10
+ primary_key :id
11
+ column :login, "text", :null=>false
12
+ column :password_digest, "bytea"
13
+
14
+ index [:login], :name=>:users_login_key, :unique=>true
15
+ end
16
+ end
17
+ end
18
+ Sequel.migration do
19
+ change do
20
+ self << "SET search_path TO \"$user\", public"
21
+ self << "INSERT INTO \"schema_migrations\" (\"filename\") VALUES ('20190728211408_create_users.rb')"
22
+ end
23
+ end
@@ -0,0 +1,28 @@
1
+ version: "3"
2
+ services:
3
+ pg:
4
+ build:
5
+ context: .
6
+ dockerfile: Dockerfile.pg
7
+ ports:
8
+ - "5432"
9
+ environment:
10
+ POSTGRES_HOST_AUTH_METHOD: trust
11
+
12
+ app:
13
+ build:
14
+ context: .
15
+ dockerfile: Dockerfile
16
+ image: rails-app:${RUBY_VERSION}
17
+ command:
18
+ [ "./bin/rails", "server", "-b", "0.0.0.0", "webrick" ]
19
+ environment:
20
+ RAILS_ENV:
21
+ ORM_MODULE:
22
+ APPMAP:
23
+ volumes:
24
+ - .:/src/app
25
+ ports:
26
+ - "3000"
27
+ links:
28
+ - pg:pg
@@ -0,0 +1,13 @@
1
+ Feature: /api/users
2
+
3
+ @appmap-disable
4
+ Scenario: A user can be created
5
+ When I create a user
6
+ Then the response status should be 201
7
+
8
+ Scenario: When a user is created, it should be in the user list
9
+ Given I create a user
10
+ And the response status should be 201
11
+ When I list the users
12
+ Then the response status should be 200
13
+ And the response should include the user
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cucumber/rails'
4
+ require 'appmap/cucumber'
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ if AppMap::Cucumber.enabled?
4
+ Around('not @appmap-disable') do |scenario, block|
5
+ appmap = AppMap.record do
6
+ block.call
7
+ end
8
+
9
+ AppMap::Cucumber.write_scenario(scenario, appmap)
10
+ end
11
+ end
@@ -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,16 @@
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
+ 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
@@ -0,0 +1,66 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ require 'spec_helper'
3
+ ENV['RAILS_ENV'] ||= 'test'
4
+ require File.expand_path('../../config/environment', __FILE__)
5
+ # Prevent database truncation if the environment is production
6
+ abort("The Rails environment is running in production mode!") if Rails.env.production?
7
+ require 'rspec/rails'
8
+ # Add additional requires below this line. Rails is not loaded until this point!
9
+
10
+ require 'appmap/rspec'
11
+
12
+ # Requires supporting ruby files with custom matchers and macros, etc, in
13
+ # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
14
+ # run as spec files by default. This means that files in spec/support that end
15
+ # in _spec.rb will both be required and run as specs, causing the specs to be
16
+ # run twice. It is recommended that you do not name files matching this glob to
17
+ # end with _spec.rb. You can configure this pattern with the --pattern
18
+ # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
19
+ #
20
+ # The following line is provided for convenience purposes. It has the downside
21
+ # of increasing the boot-up time by auto-requiring all files in the support
22
+ # directory. Alternatively, in the individual `*_spec.rb` files, manually
23
+ # require only the support files necessary.
24
+ #
25
+ # Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f }
26
+
27
+ RSpec.configure do |config|
28
+ # RSpec Rails can automatically mix in different behaviours to your tests
29
+ # based on their file location, for example enabling you to call `get` and
30
+ # `post` in specs under `spec/controllers`.
31
+ #
32
+ # You can disable this behaviour by removing the line below, and instead
33
+ # explicitly tag your specs with their type, e.g.:
34
+ #
35
+ # RSpec.describe UsersController, :type => :controller do
36
+ # # ...
37
+ # end
38
+ #
39
+ # The different available types are documented in the features, such as in
40
+ # https://relishapp.com/rspec/rspec-rails/docs
41
+ config.infer_spec_type_from_file_location!
42
+
43
+ # Filter lines from Rails gems in backtraces.
44
+ config.filter_rails_from_backtrace!
45
+ # arbitrary gems may also be filtered via:
46
+ # config.filter_gems_from_backtrace("gem name")
47
+
48
+
49
+ DatabaseCleaner.allow_remote_database_url = true
50
+
51
+ config.before(:suite) do
52
+ DatabaseCleaner.strategy = :transaction
53
+ DatabaseCleaner.clean_with(:truncation)
54
+ end
55
+
56
+ config.around :each do |example|
57
+ # Enable the use of 'return' from a guard
58
+ -> {
59
+ return example.run unless %i[model controller].member?(example.metadata[:type])
60
+
61
+ DatabaseCleaner.cleaning do
62
+ example.run
63
+ end
64
+ }.call
65
+ end
66
+ end
@@ -0,0 +1,96 @@
1
+ # This file was generated by the `rails generate rspec:install` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
16
+ RSpec.configure do |config|
17
+ # rspec-expectations config goes here. You can use an alternate
18
+ # assertion/expectation library such as wrong or the stdlib/minitest
19
+ # assertions if you prefer.
20
+ config.expect_with :rspec do |expectations|
21
+ # This option will default to `true` in RSpec 4. It makes the `description`
22
+ # and `failure_message` of custom matchers include text for helper methods
23
+ # defined using `chain`, e.g.:
24
+ # be_bigger_than(2).and_smaller_than(4).description
25
+ # # => "be bigger than 2 and smaller than 4"
26
+ # ...rather than:
27
+ # # => "be bigger than 2"
28
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
29
+ end
30
+
31
+ # rspec-mocks config goes here. You can use an alternate test double
32
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
33
+ config.mock_with :rspec do |mocks|
34
+ # Prevents you from mocking or stubbing a method that does not exist on
35
+ # a real object. This is generally recommended, and will default to
36
+ # `true` in RSpec 4.
37
+ mocks.verify_partial_doubles = true
38
+ end
39
+
40
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
41
+ # have no way to turn it off -- the option exists only for backwards
42
+ # compatibility in RSpec 3). It causes shared context metadata to be
43
+ # inherited by the metadata hash of host groups and examples, rather than
44
+ # triggering implicit auto-inclusion in groups with matching metadata.
45
+ config.shared_context_metadata_behavior = :apply_to_host_groups
46
+
47
+ # The settings below are suggested to provide a good initial experience
48
+ # with RSpec, but feel free to customize to your heart's content.
49
+ =begin
50
+ # This allows you to limit a spec run to individual examples or groups
51
+ # you care about by tagging them with `:focus` metadata. When nothing
52
+ # is tagged with `:focus`, all examples get run. RSpec also provides
53
+ # aliases for `it`, `describe`, and `context` that include `:focus`
54
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
55
+ config.filter_run_when_matching :focus
56
+
57
+ # Allows RSpec to persist some state between runs in order to support
58
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
59
+ # you configure your source control system to ignore this file.
60
+ config.example_status_persistence_file_path = "spec/examples.txt"
61
+
62
+ # Limits the available syntax to the non-monkey patched syntax that is
63
+ # recommended. For more details, see:
64
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
65
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
66
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
67
+ config.disable_monkey_patching!
68
+
69
+ # Many RSpec users commonly either run the entire suite or an individual
70
+ # file, and it's useful to allow more verbose output when running an
71
+ # individual spec file.
72
+ if config.files_to_run.one?
73
+ # Use the documentation formatter for detailed output,
74
+ # unless a formatter has already been configured
75
+ # (e.g. via a command-line flag).
76
+ config.default_formatter = "doc"
77
+ end
78
+
79
+ # Print the 10 slowest examples and example groups at the
80
+ # end of the spec run, to help surface which specs are running
81
+ # particularly slow.
82
+ config.profile_examples = 10
83
+
84
+ # Run specs in random order to surface order dependencies. If you find an
85
+ # order dependency and want to debug it, you can fix the order by providing
86
+ # the seed, which is printed after each run.
87
+ # --seed 1234
88
+ config.order = :random
89
+
90
+ # Seed global randomization in this process using the `--seed` CLI option.
91
+ # Setting this allows you to use `--seed` to deterministically reproduce
92
+ # test failures related to randomization by passing the same `--seed` value
93
+ # as the one that triggered the failure.
94
+ Kernel.srand config.seed
95
+ =end
96
+ end
@@ -0,0 +1,20 @@
1
+ # See https://help.github.com/articles/ignoring-files for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile '~/.gitignore_global'
6
+
7
+ # Ignore bundler config.
8
+ /.bundle
9
+
10
+ # Ignore all logfiles and tempfiles.
11
+ /log/*
12
+ /tmp/*
13
+ !/log/.keep
14
+ !/tmp/.keep
15
+
16
+
17
+ .byebug_history
18
+
19
+ # Ignore master key for decrypting credentials and more.
20
+ /config/master.key
@@ -27,7 +27,7 @@ describe 'AppMap class Hooking', docker: false do
27
27
 
28
28
  def invoke_test_file(file, setup: nil, &block)
29
29
  AppMap.configuration = nil
30
- package = AppMap::Config::Package.new(file)
30
+ package = AppMap::Config::Package.build_from_path(file)
31
31
  config = AppMap::Config.new('hook_spec', [ package ])
32
32
  AppMap.configuration = config
33
33
  tracer = nil
@@ -52,9 +52,9 @@ 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
@@ -112,6 +112,10 @@ describe 'AppMap class Hooking', docker: false do
112
112
  :type: function
113
113
  :location: spec/fixtures/hook/instance_method.rb:8
114
114
  :static: false
115
+ :source: |2
116
+ def say_default
117
+ 'default'
118
+ end
115
119
  YAML
116
120
  end
117
121
 
@@ -177,8 +181,8 @@ describe 'AppMap class Hooking', docker: false do
177
181
  :static: false
178
182
  :parameters:
179
183
  - :name: :kw
180
- :class: Hash
181
- :value: '{:kw=>"kw"}'
184
+ :class: String
185
+ :value: kw
182
186
  :kind: :key
183
187
  :receiver:
184
188
  :class: InstanceMethod
@@ -225,6 +229,48 @@ describe 'AppMap class Hooking', docker: false do
225
229
  end
226
230
  end
227
231
 
232
+ it 'hooks an instance method that takes keyword arguments' do
233
+ events_yaml = <<~YAML
234
+ ---
235
+ - :id: 1
236
+ :event: :call
237
+ :defined_class: InstanceMethod
238
+ :method_id: say_kws
239
+ :path: spec/fixtures/hook/instance_method.rb
240
+ :lineno: 20
241
+ :static: false
242
+ :parameters:
243
+ - :name: :args
244
+ :class: Array
245
+ :value: "[4, 5]"
246
+ :kind: :rest
247
+ - :name: :kw1
248
+ :class: String
249
+ :value: one
250
+ :kind: :keyreq
251
+ - :name: :kw2
252
+ :class: Integer
253
+ :value: '2'
254
+ :kind: :key
255
+ - :name: :kws
256
+ :class: Hash
257
+ :value: "{:kw3=>:three}"
258
+ :kind: :keyrest
259
+ :receiver:
260
+ :class: InstanceMethod
261
+ :value: Instance Method fixture
262
+ - :id: 2
263
+ :event: :return
264
+ :parent_id: 1
265
+ :return_value:
266
+ :class: String
267
+ :value: one2{:kw3=>:three}45
268
+ YAML
269
+ test_hook_behavior 'spec/fixtures/hook/instance_method.rb', events_yaml do
270
+ expect(InstanceMethod.new.say_kws(4, 5, kw1: 'one', kw2: 2, kw3: :three)).to eq('one2{:kw3=>:three}45')
271
+ end
272
+ end
273
+
228
274
  it 'hooks an instance method that takes a block argument' do
229
275
  events_yaml = <<~YAML
230
276
  ---
@@ -233,7 +279,7 @@ describe 'AppMap class Hooking', docker: false do
233
279
  :defined_class: InstanceMethod
234
280
  :method_id: say_block
235
281
  :path: spec/fixtures/hook/instance_method.rb
236
- :lineno: 20
282
+ :lineno: 24
237
283
  :static: false
238
284
  :parameters:
239
285
  - :name: :block
@@ -401,7 +447,7 @@ describe 'AppMap class Hooking', docker: false do
401
447
 
402
448
  # Verify the native extension works as expected
403
449
  expect(AppMap::Hook.singleton_method_owner_name(say_instance_defined)).to eq('SingletonMethod')
404
-
450
+
405
451
  expect(s.say_instance_defined).to eq('defined for an instance')
406
452
  end
407
453
  end
@@ -432,7 +478,7 @@ describe 'AppMap class Hooking', docker: false do
432
478
  expect(SingletonMethod::STRUCT_TEST.say_struct_singleton).to eq('singleton for a struct')
433
479
  end
434
480
  end
435
-
481
+
436
482
  it 'Reports exceptions' do
437
483
  events_yaml = <<~YAML
438
484
  ---
@@ -465,6 +511,132 @@ describe 'AppMap class Hooking', docker: false do
465
511
  end
466
512
  end
467
513
 
514
+ context 'string conversions works for the receiver when' do
515
+
516
+ it 'is missing #to_s' do
517
+ events_yaml = <<~YAML
518
+ ---
519
+ - :id: 1
520
+ :event: :call
521
+ :defined_class: NoToSMethod
522
+ :method_id: respond_to?
523
+ :path: spec/fixtures/hook/exception_method.rb
524
+ :lineno: 24
525
+ :static: false
526
+ :parameters:
527
+ - :name: :args
528
+ :class: Array
529
+ :value: "[:to_s]"
530
+ :kind: :rest
531
+ :receiver:
532
+ :class: Class
533
+ :value: NoToSMethod
534
+ - :id: 2
535
+ :event: :return
536
+ :parent_id: 1
537
+ - :id: 3
538
+ :event: :call
539
+ :defined_class: NoToSMethod
540
+ :method_id: say_hello
541
+ :path: spec/fixtures/hook/exception_method.rb
542
+ :lineno: 32
543
+ :static: false
544
+ :parameters: []
545
+ :receiver:
546
+ :class: Class
547
+ :value: NoToSMethod
548
+ - :id: 4
549
+ :event: :return
550
+ :parent_id: 3
551
+ :return_value:
552
+ :class: String
553
+ :value: hello
554
+ YAML
555
+
556
+ test_hook_behavior 'spec/fixtures/hook/exception_method.rb', events_yaml do
557
+ inst = NoToSMethod.new
558
+ # sanity check
559
+ expect(inst).not_to respond_to(:to_s)
560
+ inst.say_hello
561
+ end
562
+ end
563
+
564
+ it 'it is missing #to_s and it raises an exception in #inspect' do
565
+ events_yaml = <<~YAML
566
+ ---
567
+ - :id: 1
568
+ :event: :call
569
+ :defined_class: NoToSMethod
570
+ :method_id: respond_to?
571
+ :path: spec/fixtures/hook/exception_method.rb
572
+ :lineno: 24
573
+ :static: false
574
+ :parameters:
575
+ - :name: :args
576
+ :class: Array
577
+ :value: "[:to_s]"
578
+ :kind: :rest
579
+ :receiver:
580
+ :class: Class
581
+ :value: "*Error inspecting variable*"
582
+ - :id: 2
583
+ :event: :return
584
+ :parent_id: 1
585
+ - :id: 3
586
+ :event: :call
587
+ :defined_class: InspectRaises
588
+ :method_id: say_hello
589
+ :path: spec/fixtures/hook/exception_method.rb
590
+ :lineno: 42
591
+ :static: false
592
+ :parameters: []
593
+ :receiver:
594
+ :class: Class
595
+ :value: "*Error inspecting variable*"
596
+ - :id: 4
597
+ :event: :return
598
+ :parent_id: 3
599
+ :return_value:
600
+ :class: String
601
+ :value: hello
602
+ YAML
603
+
604
+ test_hook_behavior 'spec/fixtures/hook/exception_method.rb', events_yaml do
605
+ inst = InspectRaises.new
606
+ # sanity check
607
+ expect(inst).not_to respond_to(:to_s)
608
+ inst.say_hello
609
+ end
610
+ end
611
+
612
+ it 'it raises an exception in #to_s' do
613
+ events_yaml = <<~YAML
614
+ ---
615
+ - :id: 1
616
+ :event: :call
617
+ :defined_class: ToSRaises
618
+ :method_id: say_hello
619
+ :path: spec/fixtures/hook/exception_method.rb
620
+ :lineno: 52
621
+ :static: false
622
+ :parameters: []
623
+ :receiver:
624
+ :class: ToSRaises
625
+ :value: "*Error inspecting variable*"
626
+ - :id: 2
627
+ :event: :return
628
+ :parent_id: 1
629
+ :return_value:
630
+ :class: String
631
+ :value: hello
632
+ YAML
633
+
634
+ test_hook_behavior 'spec/fixtures/hook/exception_method.rb', events_yaml do
635
+ ToSRaises.new.say_hello
636
+ end
637
+ end
638
+ end
639
+
468
640
  it 're-raises exceptions' do
469
641
  RSpec::Expectations.configuration.on_potential_false_positives = :nothing
470
642
 
@@ -523,8 +695,8 @@ describe 'AppMap class Hooking', docker: false do
523
695
  :static: false
524
696
  :parameters:
525
697
  - :name: arg
526
- :class: String
527
- :value: string
698
+ :class: Array
699
+ :value: '["string"]'
528
700
  :kind: :rest
529
701
  :receiver:
530
702
  :class: Digest::SHA256
@@ -543,8 +715,8 @@ describe 'AppMap class Hooking', docker: false do
543
715
  :static: false
544
716
  :parameters:
545
717
  - :name: arg
546
- :class: String
547
- :value: string
718
+ :class: Array
719
+ :value: '["string"]'
548
720
  :kind: :rest
549
721
  :receiver:
550
722
  :class: Digest::SHA256
@@ -569,9 +741,33 @@ describe 'AppMap class Hooking', docker: false do
569
741
  :value: 'true'
570
742
  YAML
571
743
 
572
- test_hook_behavior 'spec/fixtures/hook/compare.rb', events_yaml do
744
+ _, _, events = test_hook_behavior 'spec/fixtures/hook/compare.rb', nil do
573
745
  expect(Compare.compare('string', 'string')).to be_truthy
574
746
  end
747
+ secure_compare_event = YAML.load(events).find { |evt| evt[:defined_class] == 'ActiveSupport::SecurityUtils' }
748
+ secure_compare_event.delete(:lineno)
749
+
750
+ expect(Diffy::Diff.new(<<~YAML, secure_compare_event.to_yaml).to_s).to eq('')
751
+ ---
752
+ :id: 2
753
+ :event: :call
754
+ :defined_class: ActiveSupport::SecurityUtils
755
+ :method_id: secure_compare
756
+ :path: lib/active_support/security_utils.rb
757
+ :static: true
758
+ :parameters:
759
+ - :name: :a
760
+ :class: String
761
+ :value: string
762
+ :kind: :req
763
+ - :name: :b
764
+ :class: String
765
+ :value: string
766
+ :kind: :req
767
+ :receiver:
768
+ :class: Module
769
+ :value: ActiveSupport::SecurityUtils
770
+ YAML
575
771
  end
576
772
 
577
773
  it 'gets labeled in the classmap' do
@@ -587,6 +783,10 @@ describe 'AppMap class Hooking', docker: false do
587
783
  :type: function
588
784
  :location: spec/fixtures/hook/compare.rb:4
589
785
  :static: true
786
+ :source: |2
787
+ def self.compare(s1, s2)
788
+ ActiveSupport::SecurityUtils.secure_compare(s1, s2)
789
+ end
590
790
  - :name: active_support
591
791
  :type: package
592
792
  :children:
@@ -603,6 +803,15 @@ describe 'AppMap class Hooking', docker: false do
603
803
  :labels:
604
804
  - security
605
805
  - crypto
806
+ :comment: |
807
+ # Constant time string comparison, for variable length strings.
808
+ #
809
+ # The values are first processed by SHA256, so that we don't leak length info
810
+ # via timing attacks.
811
+ :source: |2
812
+ def secure_compare(a, b)
813
+ fixed_length_secure_compare(::Digest::SHA256.digest(a), ::Digest::SHA256.digest(b)) && a == b
814
+ end
606
815
  - :name: openssl
607
816
  :type: package
608
817
  :children:
@@ -621,16 +830,14 @@ describe 'AppMap class Hooking', docker: false do
621
830
  - crypto
622
831
  YAML
623
832
 
624
- config, tracer = invoke_test_file 'spec/fixtures/hook/compare.rb' do
833
+ _, tracer = invoke_test_file 'spec/fixtures/hook/compare.rb' do
625
834
  expect(Compare.compare('string', 'string')).to be_truthy
626
835
  end
627
836
  cm = AppMap::Util.sanitize_paths(AppMap::ClassMap.build_from_methods(tracer.event_methods))
628
837
  entry = cm[1][:children][0][:children][0][:children][0]
629
838
  # Sanity check, make sure we got the right one
630
839
  expect(entry[:name]).to eq('secure_compare')
631
- spec = Gem::Specification.find_by_name('activesupport')
632
- entry[:location].gsub!(spec.base_dir + '/', '')
633
- expect(Diffy::Diff.new(classmap_yaml, cm.to_yaml).to_s).to eq('')
840
+ expect(entry[:labels]).to eq(%w[security crypto])
634
841
  end
635
842
  end
636
843
 
@@ -642,7 +849,7 @@ describe 'AppMap class Hooking', docker: false do
642
849
  :defined_class: InstanceMethod
643
850
  :method_id: say_the_time
644
851
  :path: spec/fixtures/hook/instance_method.rb
645
- :lineno: 24
852
+ :lineno: 28
646
853
  :static: false
647
854
  :parameters: []
648
855
  :receiver: