appmap 0.18.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (262) hide show
  1. checksums.yaml +7 -0
  2. data/.dockerignore +5 -0
  3. data/.gitignore +17 -0
  4. data/.rubocop.yml +18 -0
  5. data/.ruby-version +1 -0
  6. data/CHANGELOG.md +100 -0
  7. data/Dockerfile.appmap +5 -0
  8. data/Gemfile +5 -0
  9. data/LICENSE.txt +21 -0
  10. data/README.md +133 -0
  11. data/Rakefile +117 -0
  12. data/appmap.gemspec +41 -0
  13. data/appmap.yml +8 -0
  14. data/examples/install.rb +76 -0
  15. data/examples/mock_webapp/Gemfile +1 -0
  16. data/examples/mock_webapp/appmap.yml +2 -0
  17. data/examples/mock_webapp/exe/mock_webapp_request +12 -0
  18. data/examples/mock_webapp/lib/mock_webapp/controller.rb +23 -0
  19. data/examples/mock_webapp/lib/mock_webapp/request.rb +12 -0
  20. data/examples/mock_webapp/lib/mock_webapp/user.rb +18 -0
  21. data/exe/_appmap-record-self +49 -0
  22. data/exe/appmap +168 -0
  23. data/lib/appmap/algorithm/prune_class_map.rb +65 -0
  24. data/lib/appmap/command/inspect.rb +11 -0
  25. data/lib/appmap/command/record.rb +91 -0
  26. data/lib/appmap/command/upload.rb +103 -0
  27. data/lib/appmap/config/directory.rb +65 -0
  28. data/lib/appmap/config/file.rb +13 -0
  29. data/lib/appmap/config/named_function.rb +21 -0
  30. data/lib/appmap/config/package_dir.rb +52 -0
  31. data/lib/appmap/config/path.rb +25 -0
  32. data/lib/appmap/config.rb +65 -0
  33. data/lib/appmap/feature.rb +262 -0
  34. data/lib/appmap/inspect/inspector.rb +99 -0
  35. data/lib/appmap/inspect/parse_node.rb +170 -0
  36. data/lib/appmap/inspect/parser.rb +15 -0
  37. data/lib/appmap/inspect.rb +91 -0
  38. data/lib/appmap/middleware/remote_recording.rb +122 -0
  39. data/lib/appmap/parser.rb +60 -0
  40. data/lib/appmap/rails/action_handler.rb +77 -0
  41. data/lib/appmap/rails/sql_handler.rb +148 -0
  42. data/lib/appmap/railtie.rb +32 -0
  43. data/lib/appmap/rspec/parse_node.rb +41 -0
  44. data/lib/appmap/rspec/parser.rb +15 -0
  45. data/lib/appmap/rspec.rb +288 -0
  46. data/lib/appmap/trace/event_handler/rack_handler_webrick.rb +65 -0
  47. data/lib/appmap/trace/tracer.rb +347 -0
  48. data/lib/appmap/version.rb +5 -0
  49. data/lib/appmap.rb +26 -0
  50. data/lore/pages/2019-05-21-install-and-record/index.pug +51 -0
  51. data/lore/pages/2019-05-21-install-and-record/install_example_appmap.png +0 -0
  52. data/lore/pages/2019-05-21-install-and-record/metadata.yml +5 -0
  53. data/lore/pages/layout.pug +66 -0
  54. data/lore/public/lib/bootstrap-4.1.3/css/bootstrap-grid.css +1912 -0
  55. data/lore/public/lib/bootstrap-4.1.3/css/bootstrap-grid.css.map +1 -0
  56. data/lore/public/lib/bootstrap-4.1.3/css/bootstrap-grid.min.css +7 -0
  57. data/lore/public/lib/bootstrap-4.1.3/css/bootstrap-grid.min.css.map +1 -0
  58. data/lore/public/lib/bootstrap-4.1.3/css/bootstrap-reboot.css +331 -0
  59. data/lore/public/lib/bootstrap-4.1.3/css/bootstrap-reboot.css.map +1 -0
  60. data/lore/public/lib/bootstrap-4.1.3/css/bootstrap-reboot.min.css +8 -0
  61. data/lore/public/lib/bootstrap-4.1.3/css/bootstrap-reboot.min.css.map +1 -0
  62. data/lore/public/lib/bootstrap-4.1.3/css/bootstrap.css +9030 -0
  63. data/lore/public/lib/bootstrap-4.1.3/css/bootstrap.css.map +1 -0
  64. data/lore/public/lib/bootstrap-4.1.3/css/bootstrap.min.css +7 -0
  65. data/lore/public/lib/bootstrap-4.1.3/css/bootstrap.min.css.map +1 -0
  66. data/lore/public/stylesheets/style.css +8 -0
  67. data/package-lock.json +1066 -0
  68. data/package.json +24 -0
  69. data/spec/abstract_controller4_base_spec.rb +58 -0
  70. data/spec/abstract_controller_base_spec.rb +59 -0
  71. data/spec/fixtures/rack_users_app/.dockerignore +2 -0
  72. data/spec/fixtures/rack_users_app/.gitignore +2 -0
  73. data/spec/fixtures/rack_users_app/Dockerfile +32 -0
  74. data/spec/fixtures/rack_users_app/Gemfile +10 -0
  75. data/spec/fixtures/rack_users_app/appmap.yml +3 -0
  76. data/spec/fixtures/rack_users_app/config.ru +2 -0
  77. data/spec/fixtures/rack_users_app/docker-compose.yml +9 -0
  78. data/spec/fixtures/rack_users_app/lib/app.rb +36 -0
  79. data/spec/fixtures/rails4_users_app/.gitignore +13 -0
  80. data/spec/fixtures/rails4_users_app/.rbenv-gemsets +2 -0
  81. data/spec/fixtures/rails4_users_app/.ruby-version +1 -0
  82. data/spec/fixtures/rails4_users_app/Dockerfile +30 -0
  83. data/spec/fixtures/rails4_users_app/Dockerfile.pg +3 -0
  84. data/spec/fixtures/rails4_users_app/Gemfile +77 -0
  85. data/spec/fixtures/rails4_users_app/README.rdoc +28 -0
  86. data/spec/fixtures/rails4_users_app/Rakefile +6 -0
  87. data/spec/fixtures/rails4_users_app/app/assets/images/.keep +0 -0
  88. data/spec/fixtures/rails4_users_app/app/assets/javascripts/application.js +16 -0
  89. data/spec/fixtures/rails4_users_app/app/assets/stylesheets/application.css +15 -0
  90. data/spec/fixtures/rails4_users_app/app/controllers/api/users_controller.rb +27 -0
  91. data/spec/fixtures/rails4_users_app/app/controllers/application_controller.rb +5 -0
  92. data/spec/fixtures/rails4_users_app/app/controllers/concerns/.keep +0 -0
  93. data/spec/fixtures/rails4_users_app/app/controllers/health_controller.rb +5 -0
  94. data/spec/fixtures/rails4_users_app/app/controllers/users_controller.rb +5 -0
  95. data/spec/fixtures/rails4_users_app/app/helpers/application_helper.rb +2 -0
  96. data/spec/fixtures/rails4_users_app/app/mailers/.keep +0 -0
  97. data/spec/fixtures/rails4_users_app/app/models/.keep +0 -0
  98. data/spec/fixtures/rails4_users_app/app/models/concerns/.keep +0 -0
  99. data/spec/fixtures/rails4_users_app/app/models/user.rb +18 -0
  100. data/spec/fixtures/rails4_users_app/app/views/layouts/application.html.haml +7 -0
  101. data/spec/fixtures/rails4_users_app/app/views/users/index.html.haml +7 -0
  102. data/spec/fixtures/rails4_users_app/appmap.yml +3 -0
  103. data/spec/fixtures/rails4_users_app/bin/rails +9 -0
  104. data/spec/fixtures/rails4_users_app/bin/setup +29 -0
  105. data/spec/fixtures/rails4_users_app/bin/spring +17 -0
  106. data/spec/fixtures/rails4_users_app/config/application.rb +26 -0
  107. data/spec/fixtures/rails4_users_app/config/boot.rb +3 -0
  108. data/spec/fixtures/rails4_users_app/config/database.yml +17 -0
  109. data/spec/fixtures/rails4_users_app/config/environment.rb +5 -0
  110. data/spec/fixtures/rails4_users_app/config/environments/development.rb +41 -0
  111. data/spec/fixtures/rails4_users_app/config/environments/production.rb +79 -0
  112. data/spec/fixtures/rails4_users_app/config/environments/test.rb +42 -0
  113. data/spec/fixtures/rails4_users_app/config/initializers/assets.rb +11 -0
  114. data/spec/fixtures/rails4_users_app/config/initializers/backtrace_silencers.rb +7 -0
  115. data/spec/fixtures/rails4_users_app/config/initializers/cookies_serializer.rb +3 -0
  116. data/spec/fixtures/rails4_users_app/config/initializers/filter_parameter_logging.rb +4 -0
  117. data/spec/fixtures/rails4_users_app/config/initializers/inflections.rb +16 -0
  118. data/spec/fixtures/rails4_users_app/config/initializers/mime_types.rb +4 -0
  119. data/spec/fixtures/rails4_users_app/config/initializers/session_store.rb +3 -0
  120. data/spec/fixtures/rails4_users_app/config/initializers/to_time_preserves_timezone.rb +10 -0
  121. data/spec/fixtures/rails4_users_app/config/initializers/wrap_parameters.rb +14 -0
  122. data/spec/fixtures/rails4_users_app/config/locales/en.yml +23 -0
  123. data/spec/fixtures/rails4_users_app/config/routes.rb +12 -0
  124. data/spec/fixtures/rails4_users_app/config/secrets.yml +22 -0
  125. data/spec/fixtures/rails4_users_app/config.ru +4 -0
  126. data/spec/fixtures/rails4_users_app/create_app +23 -0
  127. data/spec/fixtures/rails4_users_app/db/migrate/20191127112304_create_users.rb +10 -0
  128. data/spec/fixtures/rails4_users_app/db/schema.rb +26 -0
  129. data/spec/fixtures/rails4_users_app/db/seeds.rb +7 -0
  130. data/spec/fixtures/rails4_users_app/docker-compose.yml +24 -0
  131. data/spec/fixtures/rails4_users_app/lib/assets/.keep +0 -0
  132. data/spec/fixtures/rails4_users_app/lib/tasks/.keep +0 -0
  133. data/spec/fixtures/rails4_users_app/log/.keep +0 -0
  134. data/spec/fixtures/rails4_users_app/public/404.html +67 -0
  135. data/spec/fixtures/rails4_users_app/public/422.html +67 -0
  136. data/spec/fixtures/rails4_users_app/public/500.html +66 -0
  137. data/spec/fixtures/rails4_users_app/public/favicon.ico +0 -0
  138. data/spec/fixtures/rails4_users_app/public/robots.txt +5 -0
  139. data/spec/fixtures/rails4_users_app/spec/controllers/users_controller_api_spec.rb +49 -0
  140. data/spec/fixtures/rails4_users_app/spec/rails_helper.rb +95 -0
  141. data/spec/fixtures/rails4_users_app/spec/spec_helper.rb +96 -0
  142. data/spec/fixtures/rails4_users_app/test/fixtures/users.yml +9 -0
  143. data/spec/fixtures/rails_users_app/.dockerignore +1 -0
  144. data/spec/fixtures/rails_users_app/.gitignore +39 -0
  145. data/spec/fixtures/rails_users_app/.rspec +1 -0
  146. data/spec/fixtures/rails_users_app/.ruby-version +1 -0
  147. data/spec/fixtures/rails_users_app/Dockerfile +29 -0
  148. data/spec/fixtures/rails_users_app/Dockerfile.pg +3 -0
  149. data/spec/fixtures/rails_users_app/Gemfile +51 -0
  150. data/spec/fixtures/rails_users_app/Rakefile +6 -0
  151. data/spec/fixtures/rails_users_app/app/controllers/api/users_controller.rb +27 -0
  152. data/spec/fixtures/rails_users_app/app/controllers/application_controller.rb +2 -0
  153. data/spec/fixtures/rails_users_app/app/controllers/concerns/.keep +0 -0
  154. data/spec/fixtures/rails_users_app/app/controllers/health_controller.rb +5 -0
  155. data/spec/fixtures/rails_users_app/app/controllers/users_controller.rb +5 -0
  156. data/spec/fixtures/rails_users_app/app/models/activerecord/user.rb +18 -0
  157. data/spec/fixtures/rails_users_app/app/models/concerns/.keep +0 -0
  158. data/spec/fixtures/rails_users_app/app/models/sequel/user.rb +25 -0
  159. data/spec/fixtures/rails_users_app/app/views/layouts/application.html.haml +7 -0
  160. data/spec/fixtures/rails_users_app/app/views/users/index.html.haml +7 -0
  161. data/spec/fixtures/rails_users_app/appmap.yml +3 -0
  162. data/spec/fixtures/rails_users_app/bin/_appmap-record-self +29 -0
  163. data/spec/fixtures/rails_users_app/bin/appmap +29 -0
  164. data/spec/fixtures/rails_users_app/bin/byebug +29 -0
  165. data/spec/fixtures/rails_users_app/bin/gli +29 -0
  166. data/spec/fixtures/rails_users_app/bin/htmldiff +29 -0
  167. data/spec/fixtures/rails_users_app/bin/ldiff +29 -0
  168. data/spec/fixtures/rails_users_app/bin/nokogiri +29 -0
  169. data/spec/fixtures/rails_users_app/bin/rackup +29 -0
  170. data/spec/fixtures/rails_users_app/bin/rails +4 -0
  171. data/spec/fixtures/rails_users_app/bin/rake +29 -0
  172. data/spec/fixtures/rails_users_app/bin/rspec +29 -0
  173. data/spec/fixtures/rails_users_app/bin/ruby-parse +29 -0
  174. data/spec/fixtures/rails_users_app/bin/ruby-rewrite +29 -0
  175. data/spec/fixtures/rails_users_app/bin/sequel +29 -0
  176. data/spec/fixtures/rails_users_app/bin/setup +25 -0
  177. data/spec/fixtures/rails_users_app/bin/sprockets +29 -0
  178. data/spec/fixtures/rails_users_app/bin/thor +29 -0
  179. data/spec/fixtures/rails_users_app/bin/update +25 -0
  180. data/spec/fixtures/rails_users_app/config/application.rb +51 -0
  181. data/spec/fixtures/rails_users_app/config/boot.rb +3 -0
  182. data/spec/fixtures/rails_users_app/config/credentials.yml.enc +1 -0
  183. data/spec/fixtures/rails_users_app/config/database.yml +17 -0
  184. data/spec/fixtures/rails_users_app/config/environment.rb +5 -0
  185. data/spec/fixtures/rails_users_app/config/environments/development.rb +40 -0
  186. data/spec/fixtures/rails_users_app/config/environments/production.rb +68 -0
  187. data/spec/fixtures/rails_users_app/config/environments/test.rb +36 -0
  188. data/spec/fixtures/rails_users_app/config/initializers/application_controller_renderer.rb +8 -0
  189. data/spec/fixtures/rails_users_app/config/initializers/backtrace_silencers.rb +7 -0
  190. data/spec/fixtures/rails_users_app/config/initializers/cors.rb +16 -0
  191. data/spec/fixtures/rails_users_app/config/initializers/filter_parameter_logging.rb +4 -0
  192. data/spec/fixtures/rails_users_app/config/initializers/inflections.rb +16 -0
  193. data/spec/fixtures/rails_users_app/config/initializers/mime_types.rb +4 -0
  194. data/spec/fixtures/rails_users_app/config/initializers/record_button.rb +3 -0
  195. data/spec/fixtures/rails_users_app/config/initializers/wrap_parameters.rb +9 -0
  196. data/spec/fixtures/rails_users_app/config/locales/en.yml +33 -0
  197. data/spec/fixtures/rails_users_app/config/routes.rb +11 -0
  198. data/spec/fixtures/rails_users_app/config.ru +5 -0
  199. data/spec/fixtures/rails_users_app/create_app +11 -0
  200. data/spec/fixtures/rails_users_app/db/migrate/20190728211408_create_users.rb +9 -0
  201. data/spec/fixtures/rails_users_app/db/schema.rb +23 -0
  202. data/spec/fixtures/rails_users_app/docker-compose.yml +24 -0
  203. data/spec/fixtures/rails_users_app/lib/tasks/.keep +0 -0
  204. data/spec/fixtures/rails_users_app/log/.keep +0 -0
  205. data/spec/fixtures/rails_users_app/public/robots.txt +1 -0
  206. data/spec/fixtures/rails_users_app/spec/controllers/users_controller_api_spec.rb +29 -0
  207. data/spec/fixtures/rails_users_app/spec/models/user_spec.rb +39 -0
  208. data/spec/fixtures/rails_users_app/spec/rails_helper.rb +66 -0
  209. data/spec/fixtures/rails_users_app/spec/spec_helper.rb +96 -0
  210. data/spec/fixtures/rails_users_app/users_app/.gitignore +20 -0
  211. data/spec/rack_handler_webrick_spec.rb +59 -0
  212. data/spec/rails_spec_helper.rb +34 -0
  213. data/spec/railtie_spec.rb +35 -0
  214. data/spec/record_sql_rails4_pg_spec.rb +76 -0
  215. data/spec/record_sql_rails_pg_spec.rb +68 -0
  216. data/spec/rspec_feature_metadata_spec.rb +30 -0
  217. data/spec/spec_helper.rb +6 -0
  218. data/test/cli_test.rb +81 -0
  219. data/test/config_test.rb +149 -0
  220. data/test/explict_inspect_test.rb +29 -0
  221. data/test/fixtures/active_record_like/active_record/aggregations.rb +4 -0
  222. data/test/fixtures/active_record_like/active_record/association.rb +4 -0
  223. data/test/fixtures/active_record_like/active_record/associations/join_dependency/join_base.rb +8 -0
  224. data/test/fixtures/active_record_like/active_record/associations/join_dependency/join_part.rb +8 -0
  225. data/test/fixtures/active_record_like/active_record/associations/join_dependency.rb +6 -0
  226. data/test/fixtures/active_record_like/active_record/caps/caps.rb +4 -0
  227. data/test/fixtures/active_record_like/active_record.rb +2 -0
  228. data/test/fixtures/cli_record_test/appmap.yml +2 -0
  229. data/test/fixtures/cli_record_test/lib/cli_record_test/main.rb +7 -0
  230. data/test/fixtures/ignore_non_ruby_file/class.rb +3 -0
  231. data/test/fixtures/ignore_non_ruby_file/non-ruby.txt +1 -0
  232. data/test/fixtures/includes_excludes/lib/a/a_1.rb +6 -0
  233. data/test/fixtures/includes_excludes/lib/a/a_2.rb +6 -0
  234. data/test/fixtures/includes_excludes/lib/a/x/x_1.rb +8 -0
  235. data/test/fixtures/includes_excludes/lib/b/b_1.rb +6 -0
  236. data/test/fixtures/includes_excludes/lib/root_1.rb +4 -0
  237. data/test/fixtures/inspect_multiple_subdirs/module_a/class_a.rb +5 -0
  238. data/test/fixtures/inspect_multiple_subdirs/module_a.rb +2 -0
  239. data/test/fixtures/inspect_multiple_subdirs/module_b/class_b.rb +5 -0
  240. data/test/fixtures/inspect_multiple_subdirs/module_b/class_c.rb +5 -0
  241. data/test/fixtures/inspect_multiple_subdirs/module_b.rb +2 -0
  242. data/test/fixtures/inspect_package/module_a/module_b/class_in_module.rb +6 -0
  243. data/test/fixtures/parse_file/defs_static_function.rb +96 -0
  244. data/test/fixtures/parse_file/function_within_class.rb +36 -0
  245. data/test/fixtures/parse_file/include_public_methods.rb +127 -0
  246. data/test/fixtures/parse_file/instance_function.rb +17 -0
  247. data/test/fixtures/parse_file/modules.rb +71 -0
  248. data/test/fixtures/parse_file/sclass_static_function.rb +88 -0
  249. data/test/fixtures/parse_file/toplevel_class.rb +13 -0
  250. data/test/fixtures/parse_file/toplevel_function.rb +14 -0
  251. data/test/fixtures/rspec_recorder/Gemfile +5 -0
  252. data/test/fixtures/rspec_recorder/appmap.yml +3 -0
  253. data/test/fixtures/rspec_recorder/lib/hello.rb +5 -0
  254. data/test/fixtures/rspec_recorder/spec/hello_spec.rb +9 -0
  255. data/test/fixtures/trace_test/trace_program_1.rb +44 -0
  256. data/test/implicit_inspect_test.rb +33 -0
  257. data/test/include_exclude_test.rb +48 -0
  258. data/test/prerecorded_trace_test.rb +76 -0
  259. data/test/rspec_test.rb +22 -0
  260. data/test/test_helper.rb +46 -0
  261. data/test/trace_test.rb +92 -0
  262. metadata +501 -0
@@ -0,0 +1,9 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # This file contains settings for ActionController::ParamsWrapper which
4
+ # is enabled by default.
5
+
6
+ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
+ ActiveSupport.on_load(:action_controller) do
8
+ wrap_parameters format: [:json]
9
+ end
@@ -0,0 +1,33 @@
1
+ # Files in the config/locales directory are used for internationalization
2
+ # and are automatically loaded by Rails. If you want to use locales other
3
+ # than English, add the necessary files in this directory.
4
+ #
5
+ # To use the locales, use `I18n.t`:
6
+ #
7
+ # I18n.t 'hello'
8
+ #
9
+ # In views, this is aliased to just `t`:
10
+ #
11
+ # <%= t('hello') %>
12
+ #
13
+ # To use a different locale, set it with `I18n.locale`:
14
+ #
15
+ # I18n.locale = :es
16
+ #
17
+ # This would use the information in config/locales/es.yml.
18
+ #
19
+ # The following keys must be escaped otherwise they will not be retrieved by
20
+ # the default I18n backend:
21
+ #
22
+ # true, false, on, off, yes, no
23
+ #
24
+ # Instead, surround them with single quotes.
25
+ #
26
+ # en:
27
+ # 'true': 'foo'
28
+ #
29
+ # To learn more, please read the Rails Internationalization guide
30
+ # available at http://guides.rubyonrails.org/i18n.html.
31
+
32
+ en:
33
+ hello: "Hello world"
@@ -0,0 +1,11 @@
1
+ Rails.application.routes.draw do
2
+ namespace :api do
3
+ resources :users, only: %i[index create]
4
+ end
5
+
6
+ resources :users, only: %i[index]
7
+
8
+ get 'health', to: 'health#show'
9
+
10
+ root 'users#index'
11
+ end
@@ -0,0 +1,5 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require_relative 'config/environment'
4
+
5
+ run Rails.application
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env bash
2
+
3
+ psql -h pg -U postgres -c "create database app_development"
4
+ psql -h pg -U postgres -c "create database app_test"
5
+
6
+ set -e
7
+
8
+ ./bin/rake db:migrate
9
+ RAILS_ENV=test ./bin/rake db:migrate
10
+
11
+ 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,24 @@
1
+ version: "3"
2
+ services:
3
+ pg:
4
+ build:
5
+ context: .
6
+ dockerfile: Dockerfile.pg
7
+ ports:
8
+ - "5432"
9
+
10
+ app:
11
+ build:
12
+ context: .
13
+ dockerfile: Dockerfile
14
+ image: rails-app:${RUBY_VERSION}
15
+ command:
16
+ [ "./bin/rails", "server", "-b", "0.0.0.0", "webrick" ]
17
+ environment:
18
+ RAILS_ENV:
19
+ volumes:
20
+ - .:/src/app
21
+ ports:
22
+ - "3000"
23
+ links:
24
+ - pg:pg
File without changes
File without changes
@@ -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
+ post :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,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
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
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'RackHandlerWebrick' do
4
+ around(:each) do |example|
5
+ FileUtils.mkdir_p tmpdir
6
+ FileUtils.rm_f appmap_json
7
+ cmd = "docker run -d -v #{File.absolute_path tmpdir}:/app/tmp -p 9292 rack-users-app:#{ENV['RUBY_VERSION']} bin/rackup -o 0.0.0.0 -s webrick"
8
+ container_id = `cd spec/fixtures/rack_users_app && #{cmd}`.strip
9
+ raise 'Failed to start rack_users_app container' unless $CHILD_STATUS.exitstatus == 0
10
+
11
+ begin
12
+ start_time = Time.now
13
+ until (cid = `docker ps -q -f id=#{container_id} -f health=healthy`.strip) != '' && container_id.include?(cid)
14
+ elapsed = Time.now - start_time
15
+ raise "Timeout waiting for container #{container_id} to be ready" if elapsed > 10
16
+
17
+ $stderr.write '.' if elapsed > 3
18
+ sleep 0.25
19
+ end
20
+ @container_id = container_id
21
+ example.run
22
+ ensure
23
+ if ENV['NOKILL'] != 'true'
24
+ `docker rm -f #{container_id}`
25
+ warn 'Failed to remove rack_users_app container' unless $CHILD_STATUS.exitstatus == 0
26
+ end
27
+ end
28
+ end
29
+
30
+ let(:tmpdir) { 'tmp/spec/RackHandlerWebrick' }
31
+ let(:appmap_json) { File.join(tmpdir, 'appmap.json') }
32
+ let(:users_app_host_and_port) { `docker port #{@container_id} 9292`.strip.split(':') }
33
+ let(:users_app_port) { users_app_host_and_port[1] }
34
+
35
+ describe 'POST /users' do
36
+ it 'HTTP request and response are recorded in the appmap' do
37
+ uri = URI("http://localhost:#{users_app_port}/users")
38
+ res = Net::HTTP.post(uri, { 'login' => 'alice', 'password' => 'foobar' }.to_json)
39
+ expect(res.code.to_i).to eq(201)
40
+
41
+ `docker stop #{@container_id}`
42
+
43
+ expect(File).to exist(appmap_json)
44
+ appmap = JSON.parse(File.read(appmap_json)).to_yaml
45
+
46
+ expect(appmap).to include(<<-WEB_REQUEST.strip)
47
+ http_server_request:
48
+ request_method: POST
49
+ path_info: "/users"
50
+ protocol: HTTP/1.1
51
+ WEB_REQUEST
52
+
53
+ expect(appmap).to include(<<-WEB_RESPONSE.strip)
54
+ http_server_response:
55
+ status: 201
56
+ WEB_RESPONSE
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ def wait_for_container(app_name)
4
+ start_time = Time.now
5
+ until (`docker-compose ps -q --filter health=healthy #{app_name}`.strip) != ''
6
+ elapsed = Time.now - start_time
7
+ raise "Timeout waiting for container #{app_name} to be ready" if elapsed > 10
8
+
9
+ $stderr.write '.' if elapsed > 3
10
+ sleep 0.25
11
+ end
12
+ end
13
+
14
+ shared_context 'Rails app pg database' do
15
+ before(:all) do
16
+ raise "you must set @fixure_dir" unless @fixture_dir
17
+
18
+ Dir.chdir @fixture_dir do
19
+ cmd = 'docker-compose up -d pg'
20
+ system cmd or raise "Command failed: #{cmd}"
21
+ wait_for_container 'pg'
22
+
23
+ cmd = 'docker-compose run --rm app ./create_app'
24
+ system cmd or raise "Command failed: #{cmd}"
25
+ end
26
+ end
27
+
28
+ after(:all) do
29
+ if ENV['NOKILL'] != 'true'
30
+ cmd = 'docker-compose down -v'
31
+ system cmd, chdir: @fixture_dir or raise "Command failed: #{cmd}"
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,35 @@
1
+ require 'rails_spec_helper'
2
+
3
+ describe 'AppMap tracer via Railtie' do
4
+ before(:all) { @fixture_dir = 'spec/fixtures/rails_users_app' }
5
+ include_context 'Rails app pg database'
6
+
7
+ let(:env) { {} }
8
+
9
+ let(:cmd) { %(docker-compose run --rm -e RAILS_ENV -e APPMAP app ./bin/rails r "puts Rails.configuration.appmap.enabled.inspect") }
10
+ let(:command_capture2) do
11
+ require 'open3'
12
+ Open3.capture2(env, cmd, chdir: @fixture_dir).tap do |result|
13
+ raise 'Failed to run rails_users_app container' unless result[1] == 0
14
+ end
15
+ end
16
+ let(:command_output) { command_capture2[0].strip }
17
+ let(:command_result) { command_capture2[1] }
18
+
19
+ it 'is disabled by default' do
20
+ expect(command_output).to eq('nil')
21
+ end
22
+
23
+ describe 'with APPMAP=true' do
24
+ let(:env) { { 'APPMAP' => 'true' } }
25
+ it 'is enabled' do
26
+ expect(command_output).to eq('true')
27
+ end
28
+ context 'and RAILS_ENV=test' do
29
+ let(:env) { { 'APPMAP' => 'true', 'RAILS_ENV' => 'test' } }
30
+ it 'is disabled' do
31
+ expect(command_output).to eq('nil')
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,76 @@
1
+ require 'rails_spec_helper'
2
+
3
+ describe 'Record SQL queries in a Rails4 app' do
4
+ before(:all) { @fixture_dir = 'spec/fixtures/rails4_users_app' }
5
+ include_context 'Rails app pg database'
6
+
7
+ around(:each) do |example|
8
+ FileUtils.rm_rf tmpdir
9
+ FileUtils.mkdir_p tmpdir
10
+ cmd = "docker-compose run --rm -e ORM_MODULE=#{orm_module} -e APPMAP=true -v #{File.absolute_path tmpdir}:/app/tmp app ./bin/rspec -f doc -b spec/controllers/users_controller_api_spec.rb:#{test_line_number}"
11
+ system cmd, chdir: @fixture_dir or raise 'Failed to run rails_users_app container'
12
+
13
+ example.run
14
+ end
15
+
16
+ let(:tmpdir) { "tmp/spec/record_sql_rails_pg_spec" }
17
+ let(:appmap) { JSON.parse(File.read(appmap_json)).to_yaml }
18
+
19
+ context 'when running specs' do
20
+ let(:test_line_number) { 31 }
21
+ let(:orm_module) { 'activerecord' }
22
+
23
+ it { is_expected.to be }
24
+ end
25
+
26
+ context 'while creating a new record' do
27
+ let(:test_line_number) { 8 }
28
+ let(:appmap_json) { File.join(tmpdir, 'appmap/rspec/Api_UsersController_POST_api_users_with_required_parameters_creates_a_user.appmap.json') }
29
+
30
+ xcontext 'using Sequel ORM' do
31
+ let(:orm_module) { 'sequel' }
32
+ it 'detects the sql INSERT' do
33
+ expect(appmap).to include(<<-SQL_QUERY.strip)
34
+ sql_query:
35
+ sql: INSERT INTO "users" ("login") VALUES ('alice') RETURNING *
36
+ SQL_QUERY
37
+ end
38
+ end
39
+ context 'using ActiveRecord ORM' do
40
+ let(:orm_module) { 'activerecord' }
41
+ it 'detects the sql INSERT' do
42
+ expect(appmap).to include(<<-SQL_QUERY.strip)
43
+ sql_query:
44
+ sql: INSERT INTO "users" ("login", "created_at", "updated_at") VALUES ($1, $2,
45
+ $3) RETURNING "id"
46
+ SQL_QUERY
47
+ end
48
+ end
49
+ end
50
+
51
+ context 'while listing records' do
52
+ let(:test_line_number) { 23 }
53
+ let(:appmap_json) { File.join(tmpdir, 'appmap/rspec/Api_UsersController_GET_api_users_lists_the_users.appmap.json') }
54
+
55
+ xcontext 'using Sequel ORM' do
56
+ let(:orm_module) { 'sequel' }
57
+ it 'detects the sql SELECT' do
58
+ expect(appmap).to include(<<-SQL_QUERY.strip)
59
+ sql_query:
60
+ sql: SELECT * FROM "users"
61
+ SQL_QUERY
62
+
63
+ expect(appmap).to include('sql:')
64
+ end
65
+ end
66
+ context 'using ActiveRecord ORM' do
67
+ let(:orm_module) { 'activerecord' }
68
+ it 'detects the sql SELECT' do
69
+ expect(appmap).to include(<<-SQL_QUERY.strip)
70
+ sql_query:
71
+ sql: SELECT "users".* FROM "users"
72
+ SQL_QUERY
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,68 @@
1
+ require 'rails_spec_helper'
2
+
3
+ describe 'Record SQL queries in a Rails app' do
4
+ before(:all) { @fixture_dir = 'spec/fixtures/rails_users_app' }
5
+ include_context 'Rails app pg database'
6
+
7
+ around(:each) do |example|
8
+ FileUtils.rm_rf tmpdir
9
+ FileUtils.mkdir_p tmpdir
10
+ cmd = "docker-compose run --rm -e ORM_MODULE=#{orm_module} -e APPMAP=true -v #{File.absolute_path tmpdir}:/app/tmp app ./bin/rspec spec/controllers/users_controller_api_spec.rb:#{test_line_number}"
11
+ system cmd, chdir: @fixture_dir or raise 'Failed to run rails_users_app container'
12
+
13
+ example.run
14
+ end
15
+
16
+ let(:tmpdir) { "tmp/spec/record_sql_rails_pg_spec" }
17
+ let(:appmap) { JSON.parse(File.read(appmap_json)).to_yaml }
18
+
19
+ context 'while creating a new record' do
20
+ let(:test_line_number) { 8 }
21
+ let(:appmap_json) { File.join(tmpdir, 'appmap/rspec/Api_UsersController_POST_api_users_with_required_parameters_creates_a_user.appmap.json') }
22
+
23
+ context 'using Sequel ORM' do
24
+ let(:orm_module) { 'sequel' }
25
+ it 'detects the sql INSERT' do
26
+ expect(appmap).to include(<<-SQL_QUERY.strip)
27
+ sql_query:
28
+ sql: INSERT INTO "users" ("login") VALUES ('alice') RETURNING *
29
+ SQL_QUERY
30
+ end
31
+ end
32
+ context 'using ActiveRecord ORM' do
33
+ let(:orm_module) { 'activerecord' }
34
+ it 'detects the sql INSERT' do
35
+ expect(appmap).to include(<<-SQL_QUERY.strip)
36
+ sql_query:
37
+ sql: INSERT INTO "users" ("login") VALUES ($1) RETURNING "id"
38
+ SQL_QUERY
39
+ end
40
+ end
41
+ end
42
+
43
+ context 'while listing records' do
44
+ let(:test_line_number) { 23 }
45
+ let(:appmap_json) { File.join(tmpdir, 'appmap/rspec/Api_UsersController_GET_api_users_lists_the_users.appmap.json') }
46
+
47
+ context 'using Sequel ORM' do
48
+ let(:orm_module) { 'sequel' }
49
+ it 'detects the sql SELECT' do
50
+ expect(appmap).to include(<<-SQL_QUERY.strip)
51
+ sql_query:
52
+ sql: SELECT * FROM "users"
53
+ SQL_QUERY
54
+
55
+ expect(appmap).to include('sql:')
56
+ end
57
+ end
58
+ context 'using ActiveRecord ORM' do
59
+ let(:orm_module) { 'activerecord' }
60
+ it 'detects the sql SELECT' do
61
+ expect(appmap).to include(<<-SQL_QUERY.strip)
62
+ sql_query:
63
+ sql: SELECT "users".* FROM "users"
64
+ SQL_QUERY
65
+ end
66
+ end
67
+ end
68
+ end