Skip to content

Commit 1b43203

Browse files
committed
feat: define commands as objects
1 parent 078ef05 commit 1b43203

File tree

2 files changed

+80
-41
lines changed

2 files changed

+80
-41
lines changed

lib/appmap/service/test_command_provider.rb

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,27 @@ def all
1313
if TestFrameworkDetector.rspec_present? && !integration_test_paths[:rspec].empty?
1414
commands << {
1515
framework: :rspec,
16-
command: "APPMAP=true bundle exec rspec #{integration_test_paths[:rspec].join(' ')}"
16+
command: {
17+
program: 'bundle',
18+
args: %w[exec rspec] + integration_test_paths[:rspec].map { |path| "./#{path}" },
19+
environment: {
20+
APPMAP: 'true'
21+
}
22+
}
1723
}
1824
end
1925

2026
if TestFrameworkDetector.minitest_present? && !integration_test_paths[:minitest].empty?
21-
commands << {
22-
framework: :minitest,
23-
command: minitest_command
24-
}
27+
commands += minitest_commands
2528
end
26-
2729
if TestFrameworkDetector.cucumber_present? && !integration_test_paths[:cucumber].empty?
2830
commands << {
2931
framework: :cucumber,
30-
command: 'APPMAP=true bundle exec cucumber'
32+
command: {
33+
program: 'bundle',
34+
args: %w[exec cucumber],
35+
environment: { APPMAP: 'true' }
36+
}
3137
}
3238
end
3339

@@ -36,12 +42,29 @@ def all
3642

3743
private
3844

39-
def minitest_command
45+
def minitest_commands
4046
if Gem.loaded_specs.has_key?('rails')
41-
"APPMAP=true bundle exec rails test #{integration_test_paths[:minitest].join(' ')}"
47+
[
48+
{
49+
framework: :minitest,
50+
command: {
51+
program: 'bundle',
52+
args: %w[exec rails test] + integration_test_paths[:minitest].map { |path| "./#{path}" },
53+
environment: { APPMAP: 'true' }
54+
}
55+
}
56+
]
4257
else
43-
subcommands = integration_test_paths[:minitest].map { |path| "APPMAP=true bundle exec ruby #{path}" }
44-
subcommands.join(' && ')
58+
integration_test_paths[:minitest].map do |path|
59+
{
60+
framework: :minitest,
61+
command: {
62+
program: 'bundle',
63+
args: ['exec', 'ruby', "./#{path}"],
64+
environment: { APPMAP: 'true' }
65+
}
66+
}
67+
end
4568
end
4669
end
4770

test/agent_setup_status_test.rb

Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,39 +27,55 @@ def test_status_gem
2727
end
2828

2929
def test_status_rails_app
30-
def test_status
31-
output = `cd spec/fixtures/rails6_users_app && bundle exec ../../../exe/appmap-agent-status`
32-
assert_equal 0, $CHILD_STATUS.exitstatus
33-
expected = {
34-
test_commands: [
35-
{
36-
framework: :rspec,
37-
command: 'APPMAP=true bundle exec rspec spec/controllers'
38-
},
39-
{
40-
framework: :minitest,
41-
command: 'APPMAP=true bundle exec ruby test/controllers && APPMAP=true bundle exec ruby test/integration'
42-
},
43-
{
44-
framework: :cucumber,
45-
command: 'APPMAP=true bundle exec cucumber'
30+
output = `cd spec/fixtures/rails6_users_app && bundle exec ../../../exe/appmap-agent-status`
31+
assert_equal 0, $CHILD_STATUS.exitstatus
32+
expected = {
33+
test_commands: [
34+
{
35+
framework: :rspec,
36+
command: {
37+
program: 'bundle',
38+
args: %w[exec rspec ./spec/controllers],
39+
environment: {
40+
APPMAP: 'true'
41+
}
42+
}
43+
},
44+
{
45+
framework: :minitest,
46+
command: {
47+
program: 'bundle',
48+
args: %w[exec ruby ./test/controllers],
49+
environment: {
50+
APPMAP: 'true'
51+
}
4652
}
47-
],
48-
properties: {
49-
config: {
50-
app: nil,
51-
present: true,
52-
valid: true
53-
},
54-
project: {
55-
agentVersion: AppMap::VERSION,
56-
language: 'ruby',
57-
remoteRecordingCapable: false,
58-
integrationTests: true
53+
},
54+
{
55+
framework: :minitest,
56+
command: {
57+
program: 'bundle',
58+
args: %w[exec ruby ./test/integration],
59+
environment: {
60+
APPMAP: 'true'
61+
}
5962
}
6063
}
64+
],
65+
properties: {
66+
config: {
67+
app: nil,
68+
present: true,
69+
valid: false
70+
},
71+
project: {
72+
agentVersion: AppMap::VERSION,
73+
language: 'ruby',
74+
remoteRecordingCapable: false,
75+
integrationTests: true
76+
}
6177
}
62-
assert_equal JSON.pretty_generate(expected), output.strip
63-
end
78+
}
79+
assert_equal JSON.pretty_generate(expected), output.strip
6480
end
6581
end

0 commit comments

Comments
 (0)