capydash 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -1
- data/lib/capydash/test_data_aggregator.rb +121 -35
- data/lib/capydash/version.rb +1 -1
- data/lib/generators/capydash/install_generator.rb +4 -25
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49eae6d67432aa999fc952f38f9268dd145275fccc64e31ebf9ec325580084f1
|
4
|
+
data.tar.gz: c169ad633644fadf23a8c6a672bb0e73621fdf66c2c16d35662dcea5e7fea0a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13a7e91002c75629f074f0e717f585a066296f90847599da479c6d54a6bb622cd354d0449d0e5526a7af253bc702fad7629a5bb595a3426b525f153110546880
|
7
|
+
data.tar.gz: 95432cc4068cd79a74c1f569a5c239eef704d152918fe81f81e8771e451295f0d9664977cf4127680b91483424ea89945991bda8df79a325e1266d44a45c4d10
|
data/README.md
CHANGED
@@ -30,7 +30,7 @@ This will automatically:
|
|
30
30
|
- ✅ Create the CapyDash initializer
|
31
31
|
- ✅ Update your test helper with all necessary hooks
|
32
32
|
- ✅ Add rake tasks for report generation
|
33
|
-
- ✅
|
33
|
+
- ✅ Works with parallel testing out of the box
|
34
34
|
|
35
35
|
### Manual Setup (Alternative)
|
36
36
|
|
@@ -87,6 +87,8 @@ Then open `http://localhost:4000` in your browser.
|
|
87
87
|
|
88
88
|
4. **Tests not appearing in report**: Ensure your tests are using Capybara methods like `visit`, `click_button`, `fill_in`, etc.
|
89
89
|
|
90
|
+
5. **"No test data found"**: Make sure you're running system tests that use Capybara methods. CapyDash works with parallel testing by default.
|
91
|
+
|
90
92
|
### Example Test
|
91
93
|
|
92
94
|
Here's an example test that will work with CapyDash:
|
@@ -1,103 +1,128 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'time'
|
3
3
|
require 'securerandom'
|
4
|
+
require 'fileutils'
|
4
5
|
|
5
6
|
module CapyDash
|
6
7
|
class TestDataAggregator
|
7
8
|
class << self
|
8
9
|
def start_test_run
|
9
|
-
|
10
|
-
|
10
|
+
run_id = generate_run_id
|
11
|
+
run_data = {
|
12
|
+
id: run_id,
|
11
13
|
created_at: Time.now.iso8601,
|
12
14
|
total_tests: 0,
|
13
15
|
passed_tests: 0,
|
14
16
|
failed_tests: 0,
|
15
17
|
tests: []
|
16
18
|
}
|
17
|
-
|
18
|
-
|
19
|
+
|
20
|
+
# Save initial run data to file
|
21
|
+
save_run_data(run_data)
|
22
|
+
|
23
|
+
# Set current test context
|
24
|
+
set_current_test_context(run_id, nil, [])
|
19
25
|
end
|
20
26
|
|
21
27
|
def finish_test_run
|
22
|
-
|
28
|
+
run_id = get_current_run_id
|
29
|
+
return unless run_id
|
23
30
|
|
24
|
-
#
|
25
|
-
|
31
|
+
# Load current run data
|
32
|
+
run_data = load_run_data(run_id)
|
33
|
+
return unless run_data
|
34
|
+
|
35
|
+
# Save the final test run data
|
36
|
+
CapyDash.save_test_run(run_data)
|
26
37
|
|
27
38
|
# Clear current state
|
28
|
-
|
29
|
-
@current_test = nil
|
30
|
-
@test_steps = nil
|
39
|
+
clear_current_test_context
|
31
40
|
end
|
32
41
|
|
33
42
|
def handle_event(event)
|
34
|
-
|
43
|
+
run_id = get_current_run_id
|
44
|
+
return unless run_id
|
45
|
+
|
46
|
+
# Load current run data
|
47
|
+
run_data = load_run_data(run_id)
|
48
|
+
return unless run_data
|
35
49
|
|
36
50
|
case event[:step_name]
|
37
51
|
when 'test_start'
|
38
|
-
start_new_test(event)
|
52
|
+
start_new_test(event, run_data)
|
39
53
|
when 'test_finish'
|
40
|
-
finish_current_test(event)
|
54
|
+
finish_current_test(event, run_data)
|
41
55
|
when 'test_result'
|
42
56
|
# This indicates the test is finished
|
43
|
-
finish_current_test(event)
|
57
|
+
finish_current_test(event, run_data)
|
44
58
|
else
|
45
59
|
# This is a test step (visit, click_button, fill_in, etc.)
|
46
60
|
# If we don't have a current test, start one
|
47
|
-
|
48
|
-
|
61
|
+
current_test = get_current_test
|
62
|
+
start_new_test(event, run_data) unless current_test
|
63
|
+
add_test_step(event, run_data)
|
49
64
|
end
|
50
65
|
end
|
51
66
|
|
52
67
|
private
|
53
68
|
|
54
|
-
def start_new_test(event)
|
69
|
+
def start_new_test(event, run_data)
|
55
70
|
# Extract test name from the current test context
|
56
71
|
test_name = event[:test_name] || CapyDash.current_test || "unknown_test"
|
57
72
|
|
58
|
-
|
73
|
+
current_test = {
|
59
74
|
test_name: test_name,
|
60
75
|
steps: []
|
61
76
|
}
|
62
|
-
|
77
|
+
|
78
|
+
# Set current test context
|
79
|
+
set_current_test_context(run_data[:id], current_test, [])
|
63
80
|
|
64
81
|
# Add the test_start step
|
65
|
-
add_test_step(event)
|
82
|
+
add_test_step(event, run_data)
|
66
83
|
end
|
67
84
|
|
68
|
-
def finish_current_test(event)
|
69
|
-
|
85
|
+
def finish_current_test(event, run_data)
|
86
|
+
current_test = get_current_test
|
87
|
+
return unless current_test
|
70
88
|
|
71
89
|
# Add the test_finish step
|
72
|
-
add_test_step(event)
|
90
|
+
add_test_step(event, run_data)
|
91
|
+
|
92
|
+
# Get updated test data
|
93
|
+
current_test = get_current_test
|
94
|
+
test_steps = get_current_test_steps
|
73
95
|
|
74
96
|
# Determine test status
|
75
|
-
test_status = determine_test_status(
|
97
|
+
test_status = determine_test_status(test_steps)
|
76
98
|
|
77
99
|
# Update counters
|
78
|
-
|
100
|
+
run_data[:total_tests] += 1
|
79
101
|
if test_status == 'passed'
|
80
|
-
|
102
|
+
run_data[:passed_tests] += 1
|
81
103
|
elsif test_status == 'failed'
|
82
|
-
|
104
|
+
run_data[:failed_tests] += 1
|
83
105
|
end
|
84
106
|
|
85
107
|
# Add test to current run
|
86
|
-
|
108
|
+
run_data[:tests] << current_test
|
109
|
+
|
110
|
+
# Save updated run data
|
111
|
+
save_run_data(run_data)
|
87
112
|
|
88
113
|
# Clear current test
|
89
|
-
|
90
|
-
@test_steps = nil
|
114
|
+
set_current_test_context(run_data[:id], nil, [])
|
91
115
|
end
|
92
116
|
|
93
|
-
def add_test_step(event)
|
94
|
-
|
117
|
+
def add_test_step(event, run_data)
|
118
|
+
current_test = get_current_test
|
119
|
+
return unless current_test
|
95
120
|
|
96
121
|
step = {
|
97
122
|
step_name: event[:step_name],
|
98
123
|
detail: event[:detail],
|
99
124
|
status: event[:status],
|
100
|
-
test_name: event[:test_name] || CapyDash.current_test ||
|
125
|
+
test_name: event[:test_name] || CapyDash.current_test || current_test[:test_name]
|
101
126
|
}
|
102
127
|
|
103
128
|
# Add screenshot if present
|
@@ -110,8 +135,12 @@ module CapyDash
|
|
110
135
|
step[:error] = event[:error]
|
111
136
|
end
|
112
137
|
|
113
|
-
|
114
|
-
|
138
|
+
# Update current test with new step
|
139
|
+
current_test[:steps] << step
|
140
|
+
test_steps = get_current_test_steps + [step]
|
141
|
+
|
142
|
+
# Save updated test context
|
143
|
+
set_current_test_context(run_data[:id], current_test, test_steps)
|
115
144
|
end
|
116
145
|
|
117
146
|
def determine_test_status(steps)
|
@@ -123,6 +152,63 @@ module CapyDash
|
|
123
152
|
def generate_run_id
|
124
153
|
"#{Time.now.to_i}_#{SecureRandom.hex(4)}"
|
125
154
|
end
|
155
|
+
|
156
|
+
# File-based storage methods for parallel testing support
|
157
|
+
def run_data_file(run_id)
|
158
|
+
File.join(Dir.pwd, "tmp", "capydash_data", "run_#{run_id}.json")
|
159
|
+
end
|
160
|
+
|
161
|
+
def context_file
|
162
|
+
File.join(Dir.pwd, "tmp", "capydash_data", "current_context.json")
|
163
|
+
end
|
164
|
+
|
165
|
+
def save_run_data(run_data)
|
166
|
+
FileUtils.mkdir_p(File.dirname(run_data_file(run_data[:id])))
|
167
|
+
File.write(run_data_file(run_data[:id]), run_data.to_json)
|
168
|
+
end
|
169
|
+
|
170
|
+
def load_run_data(run_id)
|
171
|
+
file_path = run_data_file(run_id)
|
172
|
+
return nil unless File.exist?(file_path)
|
173
|
+
|
174
|
+
JSON.parse(File.read(file_path), symbolize_names: true)
|
175
|
+
end
|
176
|
+
|
177
|
+
def set_current_test_context(run_id, current_test, test_steps)
|
178
|
+
context = {
|
179
|
+
run_id: run_id,
|
180
|
+
current_test: current_test,
|
181
|
+
test_steps: test_steps
|
182
|
+
}
|
183
|
+
|
184
|
+
FileUtils.mkdir_p(File.dirname(context_file))
|
185
|
+
File.write(context_file, context.to_json)
|
186
|
+
end
|
187
|
+
|
188
|
+
def get_current_run_id
|
189
|
+
return nil unless File.exist?(context_file)
|
190
|
+
|
191
|
+
context = JSON.parse(File.read(context_file), symbolize_names: true)
|
192
|
+
context[:run_id]
|
193
|
+
end
|
194
|
+
|
195
|
+
def get_current_test
|
196
|
+
return nil unless File.exist?(context_file)
|
197
|
+
|
198
|
+
context = JSON.parse(File.read(context_file), symbolize_names: true)
|
199
|
+
context[:current_test]
|
200
|
+
end
|
201
|
+
|
202
|
+
def get_current_test_steps
|
203
|
+
return [] unless File.exist?(context_file)
|
204
|
+
|
205
|
+
context = JSON.parse(File.read(context_file), symbolize_names: true)
|
206
|
+
context[:test_steps] || []
|
207
|
+
end
|
208
|
+
|
209
|
+
def clear_current_test_context
|
210
|
+
File.delete(context_file) if File.exist?(context_file)
|
211
|
+
end
|
126
212
|
end
|
127
213
|
end
|
128
214
|
end
|
data/lib/capydash/version.rb
CHANGED
@@ -103,31 +103,6 @@ module Capydash
|
|
103
103
|
end
|
104
104
|
end
|
105
105
|
|
106
|
-
def create_example_test
|
107
|
-
example_test_path = "test/system/capydash_example_test.rb"
|
108
|
-
|
109
|
-
unless File.exist?(example_test_path)
|
110
|
-
create_file example_test_path, <<~RUBY
|
111
|
-
require "application_system_test_case"
|
112
|
-
|
113
|
-
class CapydashExampleTest < ApplicationSystemTestCase
|
114
|
-
test "example test for CapyDash" do
|
115
|
-
visit "/"
|
116
|
-
|
117
|
-
# This test will be captured by CapyDash
|
118
|
-
assert_text "Welcome"
|
119
|
-
|
120
|
-
# Fill in a form
|
121
|
-
fill_in "Your name", with: "Alice" if page.has_field?("Your name")
|
122
|
-
click_button "Submit" if page.has_button?("Submit")
|
123
|
-
end
|
124
|
-
end
|
125
|
-
RUBY
|
126
|
-
say "Created example test at #{example_test_path}"
|
127
|
-
else
|
128
|
-
say "Example test already exists at #{example_test_path}", :yellow
|
129
|
-
end
|
130
|
-
end
|
131
106
|
|
132
107
|
def show_instructions
|
133
108
|
say "\n" + "="*60, :green
|
@@ -137,6 +112,10 @@ module Capydash
|
|
137
112
|
say "1. Run your tests: bundle exec rails test"
|
138
113
|
say "2. Generate report: bundle exec rake capydash:report"
|
139
114
|
say "3. View report: open capydash_report/index.html"
|
115
|
+
say "\nImportant:", :yellow
|
116
|
+
say "- CapyDash only captures system tests that use Capybara methods (visit, click, fill_in, etc.)"
|
117
|
+
say "- Unit tests and integration tests without Capybara won't appear in the report"
|
118
|
+
say "- Works with parallel testing - no configuration needed"
|
140
119
|
say "\nFor more information, see the README.md file."
|
141
120
|
say "="*60, :green
|
142
121
|
end
|