appmap 0.26.0 → 0.31.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -2
  3. data/CHANGELOG.md +38 -0
  4. data/README.md +144 -31
  5. data/Rakefile +1 -1
  6. data/exe/appmap +3 -1
  7. data/lib/appmap.rb +55 -35
  8. data/lib/appmap/algorithm/stats.rb +2 -1
  9. data/lib/appmap/class_map.rb +16 -24
  10. data/lib/appmap/command/record.rb +2 -61
  11. data/lib/appmap/config.rb +91 -0
  12. data/lib/appmap/cucumber.rb +89 -0
  13. data/lib/appmap/event.rb +6 -6
  14. data/lib/appmap/hook.rb +94 -116
  15. data/lib/appmap/metadata.rb +62 -0
  16. data/lib/appmap/middleware/remote_recording.rb +2 -6
  17. data/lib/appmap/minitest.rb +141 -0
  18. data/lib/appmap/rails/action_handler.rb +2 -2
  19. data/lib/appmap/rails/sql_handler.rb +2 -2
  20. data/lib/appmap/railtie.rb +2 -2
  21. data/lib/appmap/record.rb +27 -0
  22. data/lib/appmap/rspec.rb +20 -38
  23. data/lib/appmap/trace.rb +19 -11
  24. data/lib/appmap/util.rb +40 -0
  25. data/lib/appmap/version.rb +1 -1
  26. data/package-lock.json +3 -3
  27. data/spec/abstract_controller4_base_spec.rb +1 -1
  28. data/spec/abstract_controller_base_spec.rb +1 -1
  29. data/spec/config_spec.rb +3 -3
  30. data/spec/fixtures/hook/compare.rb +7 -0
  31. data/spec/fixtures/hook/openssl_sign.rb +87 -0
  32. data/spec/fixtures/hook/singleton_method.rb +54 -0
  33. data/spec/fixtures/rails_users_app/Gemfile +1 -0
  34. data/spec/fixtures/rails_users_app/features/api_users.feature +13 -0
  35. data/spec/fixtures/rails_users_app/features/support/env.rb +4 -0
  36. data/spec/fixtures/rails_users_app/features/support/hooks.rb +11 -0
  37. data/spec/fixtures/rails_users_app/features/support/steps.rb +18 -0
  38. data/spec/hook_spec.rb +243 -36
  39. data/spec/rails_spec_helper.rb +2 -0
  40. data/spec/rspec_feature_metadata_spec.rb +2 -0
  41. data/spec/spec_helper.rb +4 -0
  42. data/spec/util_spec.rb +21 -0
  43. data/test/cli_test.rb +2 -2
  44. data/test/cucumber_test.rb +72 -0
  45. data/test/fixtures/cucumber4_recorder/Gemfile +5 -0
  46. data/test/fixtures/cucumber4_recorder/appmap.yml +3 -0
  47. data/test/fixtures/cucumber4_recorder/features/say_hello.feature +5 -0
  48. data/test/fixtures/cucumber4_recorder/features/support/env.rb +5 -0
  49. data/test/fixtures/cucumber4_recorder/features/support/hooks.rb +11 -0
  50. data/test/fixtures/cucumber4_recorder/features/support/steps.rb +9 -0
  51. data/test/fixtures/cucumber4_recorder/lib/hello.rb +7 -0
  52. data/test/fixtures/cucumber_recorder/Gemfile +5 -0
  53. data/test/fixtures/cucumber_recorder/appmap.yml +3 -0
  54. data/test/fixtures/cucumber_recorder/features/say_hello.feature +5 -0
  55. data/test/fixtures/cucumber_recorder/features/support/env.rb +5 -0
  56. data/test/fixtures/cucumber_recorder/features/support/hooks.rb +11 -0
  57. data/test/fixtures/cucumber_recorder/features/support/steps.rb +9 -0
  58. data/test/fixtures/cucumber_recorder/lib/hello.rb +7 -0
  59. data/test/fixtures/minitest_recorder/Gemfile +5 -0
  60. data/test/fixtures/minitest_recorder/appmap.yml +3 -0
  61. data/test/fixtures/minitest_recorder/lib/hello.rb +5 -0
  62. data/test/fixtures/minitest_recorder/test/hello_test.rb +12 -0
  63. data/test/fixtures/process_recorder/appmap.yml +3 -0
  64. data/test/fixtures/process_recorder/hello.rb +9 -0
  65. data/test/fixtures/rspec_recorder/Gemfile +1 -1
  66. data/test/fixtures/rspec_recorder/spec/decorated_hello_spec.rb +12 -0
  67. data/test/minitest_test.rb +38 -0
  68. data/test/record_process_test.rb +35 -0
  69. data/test/rspec_test.rb +5 -0
  70. metadata +39 -3
  71. data/spec/fixtures/hook/class_method.rb +0 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 75d21c5ea95115ab89fb0dd6674a601d19455473f787344d07f7a935aec58aec
4
- data.tar.gz: 9d76905534e5c3277c318376708224f318f6357ab41647a6a14a82edf63cbe54
3
+ metadata.gz: 54b9a05aeb3eea84572b115a6de1106e6743b74046048e3c168f99a75aa9e669
4
+ data.tar.gz: eb8a690376d833c4bec9f0789c5499f413f7dcb3b1ef111257785bd344861f64
5
5
  SHA512:
6
- metadata.gz: c6ca34edd66c0cec51119cc2af49ea5824c91023e54ac1507493eebc3ef39d8308db2b013fdd83d9a1102fc3f6f791dbcec5cf7c75a0cda409d4ade695739815
7
- data.tar.gz: 3e5ff519cc8ce4964771806f20258590b607a48a497bb4f100a72ce31f0b40305542315ac3ecfdf1ec5b92723c30369041707327fdf2bf0ac35a5f526e77a969
6
+ metadata.gz: 453f06041220ecd0a4fc563ae007e7f8247d3dfcccf49657cbf47ddc53d0175e6834d1dbd89a2338a032d6cfae866929216b58a11bb6f0fe3fd2ea69508d7b2a
7
+ data.tar.gz: 77f372ad255c3c664c690affa2962958cebd1e8f34579809e4d975fdf57404889d8506f9153d44a95afda297ffe7b1654529252a5293487477e803bdf0cc9608
data/.gitignore CHANGED
@@ -1,7 +1,6 @@
1
1
  .DS_Store
2
2
  /html/
3
- /.appmap/
4
- /.bundle/
3
+ .bundle
5
4
  /.yardoc
6
5
  /_yardoc/
7
6
  /coverage/
@@ -1,3 +1,41 @@
1
+ # v0.31.0
2
+
3
+ * Add the ability to hook methods by default, and optionally add labels to them in the
4
+ classmap. Use it to hook `ActiveSupport::SecurityUtils.secure_compare`.
5
+
6
+ # v0.30.0
7
+
8
+ * Add support for Minitest.
9
+
10
+ # v0.29.0
11
+
12
+ * Add `lib/appmap/record.rb`, which can be `require`d to record the rest of the process.
13
+
14
+ # v0.28.1
15
+
16
+ * Fix the `defined_class` recorded in an appmap for an instance method included in a class
17
+ at runtime.
18
+ * Only include the `static` attribute on `call` events in an appmap. Determine its value
19
+ based on the receiver of the method call.
20
+
21
+ # v0.28.0
22
+
23
+ * Change behavior of **AppMap.record** to return a complete AppMap as a Hash.
24
+ * Update README with information about recording Cucumber tests.
25
+ * **AppMap.initialize** automatically runs when `AppMap` is required, unless disabled
26
+ by environment variable `APPMAP_INITIALIZE=false`.
27
+ * **AppMap.hook** no longer takes a `configuration` argument.
28
+ * Add **AppMap::Util.scenario_filename**.
29
+
30
+ # v0.27.0
31
+
32
+ * Add **AppMap.record** to programatically record and capture an AppMap of a Ruby block.
33
+
34
+ # v0.26.1
35
+
36
+ * Fix a bug that caused duplicate entries in the list of frameworks that appear
37
+ in the `metadata` section of an appmap.
38
+
1
39
  # v0.26.0
2
40
 
3
41
  * **appmap upload** is removed. Upload functionality has been moved to
data/README.md CHANGED
@@ -1,18 +1,24 @@
1
1
  - [About](#about)
2
- - [Testing](#testing)
3
2
  - [Installation](#installation)
4
3
  - [Configuration](#configuration)
5
4
  - [Running](#running)
6
5
  - [RSpec](#rspec)
6
+ - [Minitest](#minitest)
7
+ - [Cucumber](#cucumber)
7
8
  - [Remote recording](#remote-recording)
8
9
  - [Ruby on Rails](#ruby-on-rails)
9
10
  - [Uploading AppMaps](#uploading-appmaps)
11
+ - [Development](#development)
12
+ - [Running tests](#running-tests)
13
+ - [Using fixture apps](#using-fixture-apps)
14
+ - [`test/fixtures`](#testfixtures)
15
+ - [`spec/fixtures`](#specfixtures)
10
16
  - [Build status](#build-status)
11
17
 
12
18
  # About
13
19
 
14
20
  `appmap-ruby` is a Ruby Gem for recording
15
- [AppMaps](https://github.com/applandinc/appmap) of your code.
21
+ [AppMaps](https://github.com/applandinc/appmap) of your code.
16
22
  "AppMap" is a data format which records code structure (modules, classes, and methods), code execution events
17
23
  (function calls and returns), and code metadata (repo name, repo URL, commit
18
24
  SHA, labels, etc). It's more granular than a performance profile, but it's less
@@ -22,7 +28,7 @@ There are several ways to record AppMaps of your Ruby program using the `appmap`
22
28
 
23
29
  * Run your RSpec tests with the environment variable `APPMAP=true`. An AppMap will be generated for each spec.
24
30
  * Run your application server with AppMap remote recording enabled, and use the AppMap.
25
- browser extension to start, stop, and upload recordings.
31
+ browser extension to start, stop, and upload recordings.
26
32
  * Run the command `appmap record <program>` to record the entire execution of a program.
27
33
 
28
34
  Once you have recorded some AppMaps (for example, by running RSpec tests), you use the `appland upload` command
@@ -31,17 +37,6 @@ by the [AppLand CLI](https://github.com/applandinc/appland-cli/releases), to
31
37
  Then, on the [AppLand website](https://app.land), you can
32
38
  visualize the design of your code and share links with collaborators.
33
39
 
34
- # Testing
35
- Before running tests, configure `local.appmap` to point to your local `appmap-ruby` directory.
36
- ```
37
- $ bundle config local.appmap $(pwd)
38
- ```
39
-
40
- Run the tests via `rake`:
41
- ```
42
- $ bundle exec rake test
43
- ```
44
-
45
40
  # Installation
46
41
 
47
42
  Add `gem 'appmap'` to your Gemfile just as you would any other dependency.
@@ -60,7 +55,7 @@ group :development, :test do
60
55
  end
61
56
  ```
62
57
 
63
- Then install with `bundle`.
58
+ Then install with `bundle`.
64
59
 
65
60
  # Configuration
66
61
 
@@ -90,7 +85,7 @@ Each entry in the `packages` list is a YAML object which has the following keys:
90
85
 
91
86
  ## RSpec
92
87
 
93
- To instrument RSpec tests, follow these additional steps:
88
+ To record RSpec tests, follow these additional steps:
94
89
 
95
90
  1) Require `appmap/rspec` in your `spec_helper.rb`.
96
91
 
@@ -98,28 +93,16 @@ To instrument RSpec tests, follow these additional steps:
98
93
  require 'appmap/rspec'
99
94
  ```
100
95
 
101
- 2) Add `appmap: true` to the tests you want to instrument.
102
-
103
- ```ruby
104
- describe Hello, appmap: true do
105
- describe 'says hello' do
106
- it 'when prompted' do
107
- expect(Hello.new.say_hello).to eq('Hello!')
108
- end
109
- end
110
- end
111
- ```
112
-
113
- 3) *Optional* Add `feature: '<feature name>'` and `feature_group: '<feature group name>'` annotations to your
96
+ 2) *Optional* Add `feature: '<feature name>'` and `feature_group: '<feature group name>'` annotations to your
114
97
  examples.
115
98
 
116
- 4) Run the tests with the environment variable `APPMAP=true`:
99
+ 3) Run the tests with the environment variable `APPMAP=true`:
117
100
 
118
101
  ```sh-session
119
102
  $ APPMAP=true bundle exec rspec -t appmap
120
103
  ```
121
104
 
122
- Each RSpec test will output a data file into the directory `tmp/appmap/rspec`. For example:
105
+ Each RSpec test will output an AppMap file into the directory `tmp/appmap/rspec`. For example:
123
106
 
124
107
  ```
125
108
  $ find tmp/appmap/rspec
@@ -143,6 +126,67 @@ If you include the `feature` and `feature_group` metadata, these attributes will
143
126
 
144
127
  If you don't explicitly declare `feature` and `feature_group`, then they will be inferred from the spec name and example descriptions.
145
128
 
129
+ ## Minitest
130
+
131
+ To record Minitest tests, follow these additional steps:
132
+
133
+ 1) Require `appmap/minitest` in `test_helper.rb`
134
+
135
+ ```ruby
136
+ require 'appmap/minitest'
137
+ ```
138
+
139
+ 2) Run the tests with the environment variable `APPMAP=true`:
140
+
141
+ ```sh-session
142
+ $ APPMAP=true bundle exec -Ilib -Itest test/*
143
+ ```
144
+
145
+ Each Minitest test will output an AppMap file into the directory `tmp/appmap/minitest`. For example:
146
+
147
+ ```
148
+ $ find tmp/appmap/minitest
149
+ Hello_says_hello_when_prompted.appmap.json
150
+ ```
151
+
152
+ ## Cucumber
153
+
154
+ To record Cucumber tests, follow these additional steps:
155
+
156
+ 1) Require `appmap/cucumber` in `support/env.rb`:
157
+
158
+ ```ruby
159
+ require 'appmap/cucumber'
160
+ ```
161
+
162
+ 2) Create an `Around` hook in `support/hooks.rb` to record the scenario:
163
+
164
+
165
+ ```ruby
166
+ if AppMap::Cucumber.enabled?
167
+ Around('not @appmap-disable') do |scenario, block|
168
+ appmap = AppMap.record do
169
+ block.call
170
+ end
171
+
172
+ AppMap::Cucumber.write_scenario(scenario, appmap)
173
+ end
174
+ end
175
+ ```
176
+
177
+ 3) Run the tests with the environment variable `APPMAP=true`:
178
+
179
+ ```sh-session
180
+ $ APPMAP=true bundle exec cucumber
181
+ ```
182
+
183
+ Each Cucumber test will output an AppMap file into the directory `tmp/appmap/cucumber`. For example:
184
+
185
+ ```
186
+ $ find tmp/appmap/cucumber
187
+ Hello_Says_hello_when_prompted.appmap.json
188
+ ```
189
+
146
190
  ## Remote recording
147
191
 
148
192
  To manually record ad-hoc AppMaps of your Ruby app, use AppMap remote recording.
@@ -183,5 +227,74 @@ Note that using this method is kind of a blunt instrument. Recording RSpecs and
183
227
 
184
228
  For instructions on uploading, see the documentation of the [AppLand CLI](https://github.com/applandinc/appland-cli).
185
229
 
230
+ # Development
231
+
232
+ ## Running tests
233
+
234
+ Before running tests, configure `local.appmap` to point to your local `appmap-ruby` directory.
235
+ ```
236
+ $ bundle config local.appmap $(pwd)
237
+ ```
238
+
239
+ Run the tests via `rake`:
240
+ ```
241
+ $ bundle exec rake test
242
+ ```
243
+
244
+ ## Using fixture apps
245
+
246
+ ### `test/fixtures`
247
+
248
+ The fixture apps in `test/fixtures` are plain Ruby projects that exercise the basic functionality of the
249
+ `appmap` gem. To develop in a fixture, simple enter the fixture directory and `bundle`.
250
+
251
+ ### `spec/fixtures`
252
+
253
+ The fixture apps in `spec/fixtures` are simple Rack, Rails4, and Rails5 apps.
254
+ You can use them to interactively develop and test the recording features of the `appmap` gem.
255
+ These fixture apps are more sophisticated than `test/fixtures`, because they include additional
256
+ resources such as a PostgreSQL database.
257
+
258
+ To build the fixture container images, first run:
259
+
260
+ ```sh-session
261
+ $ bundle exec rake fixtures:all
262
+ ```
263
+
264
+ This will build the `appmap.gem`, along with a Docker image for each fixture app.
265
+
266
+ Then move to the directory of the fixture you want to use, and provision the environment.
267
+ In this example, we use Ruby 2.6.
268
+
269
+ ```sh-session
270
+ $ export RUBY_VERSION=2.6
271
+ $ docker-compose up -d pg
272
+ $ sleep 10s # Or some reasonable amount of time
273
+ $ docker-compose run --rm app ./create_app
274
+ ```
275
+
276
+ Now you can start a development container.
277
+
278
+ ```sh-session
279
+ $ docker-compose run --rm -v $PWD/../../..:/src/appmap-ruby app bash
280
+ Starting rails_users_app_pg_1 ... done
281
+ root@6fab5f89125f:/app# cd /src/app
282
+ root@6fab5f89125f:/src/app# bundle config local.appmap /src/appmap-ruby
283
+ root@6fab5f89125f:/src/app# bundle update appmap
284
+ ```
285
+
286
+ At this point, the bundle is built with the `appmap` gem located in `/src/appmap`, which is volume-mounted from the host.
287
+ So you can edit the fixture code and the appmap code and run test commands such as `rspec` and `cucumber` in the container.
288
+ For example:
289
+
290
+ ```sh-session
291
+ root@6fab5f89125f:/src/app# bundle exec rspec
292
+ Configuring AppMap from path appmap.yml
293
+ ....
294
+
295
+ Finished in 0.07357 seconds (files took 2.1 seconds to load)
296
+ 4 examples, 0 failures
297
+ ```
298
+
186
299
  # Build status
187
300
  [![Build Status](https://travis-ci.org/applandinc/appmap-ruby.svg?branch=master)](https://travis-ci.org/applandinc/appmap-ruby)
data/Rakefile CHANGED
@@ -122,7 +122,7 @@ end
122
122
  Rake::TestTask.new(:minitest) do |t|
123
123
  t.libs << 'test'
124
124
  t.libs << 'lib'
125
- t.test_files = FileList['test/**/*_test.rb']
125
+ t.test_files = FileList['test/*_test.rb']
126
126
  end
127
127
 
128
128
  task spec: "spec:all"
data/exe/appmap CHANGED
@@ -3,6 +3,8 @@
3
3
 
4
4
  require 'gli'
5
5
 
6
+ ENV['APPMAP_INITIALIZE'] = 'false'
7
+
6
8
  require 'appmap'
7
9
  require 'appmap/version'
8
10
 
@@ -136,7 +138,7 @@ module AppMap
136
138
  protected
137
139
 
138
140
  def interpret_config_option(fname)
139
- AppMap.configure fname
141
+ AppMap.initialize fname
140
142
  end
141
143
 
142
144
  def interpret_output_file_option(file_name)
@@ -8,60 +8,80 @@ rescue NameError
8
8
  end
9
9
 
10
10
  require 'appmap/version'
11
+ require 'appmap/hook'
12
+ require 'appmap/config'
13
+ require 'appmap/trace'
14
+ require 'appmap/class_map'
15
+ require 'appmap/metadata'
11
16
 
12
17
  module AppMap
13
- BATCH_HEADER_NAME = 'AppLand-Scenario-Batch'
14
-
15
18
  class << self
16
- @config = nil
17
- @config_file_path = nil
19
+ @configuration = nil
20
+ @configuration_file_path = nil
18
21
 
19
- # configuration gets the AppMap configuration.
22
+ # configuration gets the configuration. If there is no configuration, the default
23
+ # configuration is initialized.
20
24
  def configuration
21
- raise "AppMap is not configured" unless @config
22
-
23
- @config
25
+ @configuration ||= configure
24
26
  end
25
27
 
26
- # configure applies the configuration from a file. This method can only be performed once.
27
- # Be sure and call it before +hook+ if you want non-default configuration.
28
- #
29
- # Default behavior is to configure from "appmap.yml".
30
- def configure(config_file_path = 'appmap.yml')
31
- if @config
32
- return @config if @config_file_path == config_file_path
33
-
34
- raise "AppMap is already configured from #{@config_file_path}, can't reconfigure from #{config_file_path}"
35
- end
28
+ # configuration= sets the configuration. This is only expected to happen once per
29
+ # Ruby process.
30
+ def configuration=(config)
31
+ warn 'AppMap is already configured' if @configuration && config
36
32
 
37
- warn "Configuring AppMap from path #{config_file_path}"
38
- require 'appmap/hook'
39
- AppMap::Hook::Config.load_from_file(config_file_path).tap do |config|
40
- @config = config
41
- @config_file_path = config_file_path
42
- end
33
+ @configuration = config
43
34
  end
44
35
 
45
- # Activate the code hooks which record function calls as trace events.
36
+ # initialize configures AppMap for recording. Default behavior is to configure from "appmap.yml".
37
+ # This method also activates the code hooks which record function calls as trace events.
46
38
  # Call this function before the program code is loaded by the Ruby VM, otherwise
47
39
  # the load events won't be seen and the hooks won't activate.
48
- def hook(config = configure)
49
- require 'appmap/hook'
50
- AppMap::Hook.hook(config)
40
+ def initialize(config_file_path = 'appmap.yml')
41
+ warn "Configuring AppMap from path #{config_file_path}"
42
+ self.configuration = Config.load_from_file(config_file_path)
43
+ Hook.new(configuration).enable
51
44
  end
52
45
 
53
- # Access the AppMap::Tracers, which can be used to start tracing, stop tracing, and record events.
46
+ # tracing can be used to start tracing, stop tracing, and record events.
54
47
  def tracing
55
- require 'appmap/trace'
56
- @tracing ||= Trace::Tracers.new
48
+ @tracing ||= Trace::Tracing.new
49
+ end
50
+
51
+ # record records the events which occur while processing a block,
52
+ # and returns an AppMap as a Hash.
53
+ def record
54
+ tracer = tracing.trace
55
+ begin
56
+ yield
57
+ ensure
58
+ tracing.delete(tracer)
59
+ end
60
+
61
+ events = [].tap do |event_list|
62
+ event_list << tracer.next_event.to_h while tracer.event?
63
+ end
64
+ {
65
+ 'version' => AppMap::APPMAP_FORMAT_VERSION,
66
+ 'metadata' => detect_metadata,
67
+ 'classMap' => class_map(tracer.event_methods),
68
+ 'events' => events
69
+ }
70
+ end
71
+
72
+ # class_map builds a class map from a config and a list of Ruby methods.
73
+ def class_map(methods)
74
+ ClassMap.build_from_methods(configuration, methods)
57
75
  end
58
76
 
59
- # Build a class map from a config and a list of Ruby methods.
60
- def class_map(config, methods)
61
- require 'appmap/class_map'
62
- AppMap::ClassMap.build_from_methods(config, methods)
77
+ # detect_metadata returns default metadata detected from the Ruby system and from the
78
+ # filesystem.
79
+ def detect_metadata
80
+ @metadata ||= Metadata.detect.freeze
81
+ @metadata.deep_dup
63
82
  end
64
83
  end
65
84
  end
66
85
 
67
86
  require 'appmap/railtie' if defined?(::Rails::Railtie)
87
+ AppMap.initialize unless ENV['APPMAP_INITIALIZE'] == 'false'