capydash 0.1.4 → 0.1.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 92f824ed1079edfc71c33d6260bf708a036a9a0f99a20f10c919a2a0f305623a
4
- data.tar.gz: c70b934e69ae0b8a4759146044beb115f1f3170ccdfd7d6fd7d1480f2492f2d2
3
+ metadata.gz: 0c4ac0c982d52d8e79b722368df5d106ff716fd450bbc82bcad5c00461610427
4
+ data.tar.gz: 5453b6ae15d944cc97e318744788b9e8712538b93599d847991ba436dc5a7667
5
5
  SHA512:
6
- metadata.gz: 0cbabbb16e97c1ef1214e383dc6166cfb84c3267ae9e5e26f131483420e380d102e4ac0c36ba8c589332b1068cf3d1270d9e6a631e7c06cf24540002af1106a0
7
- data.tar.gz: b170062c27cd772973a37380e681b28846c592bfdbf17287b9be2535f6e71a71d6d6415970fdd8bf1f047d033d76dc5ee79bcf198112955981231b11fa71b7c4
6
+ metadata.gz: 85afa448055003ea66763bf6db6c01098dc12fc3e518ce4300d452b6f659a355bdd36c744e2c6ccb07b6bd20321ec7dfeb0dd08ef63bed4474ed5a3b623d5fae
7
+ data.tar.gz: 9de10d46959fda60e26133d9d457d73f78c5d5e181b92586226c207d223b7cb32bfcd1311ab565bdce372fbc6f91460802629fed37ba5667b17888e3960e70b2
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
- - ✅ Create an example test to get you started
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,135 @@
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
- @current_run = {
10
- id: generate_run_id,
10
+ # Don't start a new run if one is already in progress
11
+ return if test_run_started?
12
+
13
+ run_id = generate_run_id
14
+ run_data = {
15
+ id: run_id,
11
16
  created_at: Time.now.iso8601,
12
17
  total_tests: 0,
13
18
  passed_tests: 0,
14
19
  failed_tests: 0,
15
20
  tests: []
16
21
  }
17
- @current_test = nil
18
- @test_steps = []
22
+
23
+ # Save initial run data to file
24
+ save_run_data(run_data)
25
+
26
+ # Set current test context
27
+ set_current_test_context(run_id, nil, [])
28
+ end
29
+
30
+ def test_run_started?
31
+ get_current_run_id != nil
19
32
  end
20
33
 
21
34
  def finish_test_run
22
- return unless @current_run
35
+ run_id = get_current_run_id
36
+ return unless run_id
23
37
 
24
- # Save the test run data
25
- CapyDash.save_test_run(@current_run)
38
+ # Load current run data
39
+ run_data = load_run_data(run_id)
40
+ return unless run_data
41
+
42
+ # Save the final test run data
43
+ CapyDash.save_test_run(run_data)
26
44
 
27
45
  # Clear current state
28
- @current_run = nil
29
- @current_test = nil
30
- @test_steps = nil
46
+ clear_current_test_context
31
47
  end
32
48
 
33
49
  def handle_event(event)
34
- return unless @current_run
50
+ run_id = get_current_run_id
51
+ return unless run_id
52
+
53
+ # Load current run data
54
+ run_data = load_run_data(run_id)
55
+ return unless run_data
35
56
 
36
57
  case event[:step_name]
37
58
  when 'test_start'
38
- start_new_test(event)
59
+ start_new_test(event, run_data)
39
60
  when 'test_finish'
40
- finish_current_test(event)
61
+ finish_current_test(event, run_data)
41
62
  when 'test_result'
42
63
  # This indicates the test is finished
43
- finish_current_test(event)
64
+ finish_current_test(event, run_data)
44
65
  else
45
66
  # This is a test step (visit, click_button, fill_in, etc.)
46
67
  # If we don't have a current test, start one
47
- start_new_test(event) unless @current_test
48
- add_test_step(event)
68
+ current_test = get_current_test
69
+ start_new_test(event, run_data) unless current_test
70
+ add_test_step(event, run_data)
49
71
  end
50
72
  end
51
73
 
52
74
  private
53
75
 
54
- def start_new_test(event)
76
+ def start_new_test(event, run_data)
55
77
  # Extract test name from the current test context
56
78
  test_name = event[:test_name] || CapyDash.current_test || "unknown_test"
57
79
 
58
- @current_test = {
80
+ current_test = {
59
81
  test_name: test_name,
60
82
  steps: []
61
83
  }
62
- @test_steps = []
84
+
85
+ # Set current test context
86
+ set_current_test_context(run_data[:id], current_test, [])
63
87
 
64
88
  # Add the test_start step
65
- add_test_step(event)
89
+ add_test_step(event, run_data)
66
90
  end
67
91
 
68
- def finish_current_test(event)
69
- return unless @current_test
92
+ def finish_current_test(event, run_data)
93
+ current_test = get_current_test
94
+ return unless current_test
70
95
 
71
96
  # Add the test_finish step
72
- add_test_step(event)
97
+ add_test_step(event, run_data)
98
+
99
+ # Get updated test data
100
+ current_test = get_current_test
101
+ test_steps = get_current_test_steps
73
102
 
74
103
  # Determine test status
75
- test_status = determine_test_status(@test_steps)
104
+ test_status = determine_test_status(test_steps)
76
105
 
77
106
  # Update counters
78
- @current_run[:total_tests] += 1
107
+ run_data[:total_tests] += 1
79
108
  if test_status == 'passed'
80
- @current_run[:passed_tests] += 1
109
+ run_data[:passed_tests] += 1
81
110
  elsif test_status == 'failed'
82
- @current_run[:failed_tests] += 1
111
+ run_data[:failed_tests] += 1
83
112
  end
84
113
 
85
114
  # Add test to current run
86
- @current_run[:tests] << @current_test
115
+ run_data[:tests] << current_test
116
+
117
+ # Save updated run data
118
+ save_run_data(run_data)
87
119
 
88
120
  # Clear current test
89
- @current_test = nil
90
- @test_steps = nil
121
+ set_current_test_context(run_data[:id], nil, [])
91
122
  end
92
123
 
93
- def add_test_step(event)
94
- return unless @current_test
124
+ def add_test_step(event, run_data)
125
+ current_test = get_current_test
126
+ return unless current_test
95
127
 
96
128
  step = {
97
129
  step_name: event[:step_name],
98
130
  detail: event[:detail],
99
131
  status: event[:status],
100
- test_name: event[:test_name] || CapyDash.current_test || @current_test[:test_name]
132
+ test_name: event[:test_name] || CapyDash.current_test || current_test[:test_name]
101
133
  }
102
134
 
103
135
  # Add screenshot if present
@@ -110,8 +142,12 @@ module CapyDash
110
142
  step[:error] = event[:error]
111
143
  end
112
144
 
113
- @current_test[:steps] << step
114
- @test_steps << step
145
+ # Update current test with new step
146
+ current_test[:steps] << step
147
+ test_steps = get_current_test_steps + [step]
148
+
149
+ # Save updated test context
150
+ set_current_test_context(run_data[:id], current_test, test_steps)
115
151
  end
116
152
 
117
153
  def determine_test_status(steps)
@@ -123,6 +159,63 @@ module CapyDash
123
159
  def generate_run_id
124
160
  "#{Time.now.to_i}_#{SecureRandom.hex(4)}"
125
161
  end
162
+
163
+ # File-based storage methods for parallel testing support
164
+ def run_data_file(run_id)
165
+ File.join(Dir.pwd, "tmp", "capydash_data", "run_#{run_id}.json")
166
+ end
167
+
168
+ def context_file
169
+ File.join(Dir.pwd, "tmp", "capydash_data", "current_context.json")
170
+ end
171
+
172
+ def save_run_data(run_data)
173
+ FileUtils.mkdir_p(File.dirname(run_data_file(run_data[:id])))
174
+ File.write(run_data_file(run_data[:id]), run_data.to_json)
175
+ end
176
+
177
+ def load_run_data(run_id)
178
+ file_path = run_data_file(run_id)
179
+ return nil unless File.exist?(file_path)
180
+
181
+ JSON.parse(File.read(file_path), symbolize_names: true)
182
+ end
183
+
184
+ def set_current_test_context(run_id, current_test, test_steps)
185
+ context = {
186
+ run_id: run_id,
187
+ current_test: current_test,
188
+ test_steps: test_steps
189
+ }
190
+
191
+ FileUtils.mkdir_p(File.dirname(context_file))
192
+ File.write(context_file, context.to_json)
193
+ end
194
+
195
+ def get_current_run_id
196
+ return nil unless File.exist?(context_file)
197
+
198
+ context = JSON.parse(File.read(context_file), symbolize_names: true)
199
+ context[:run_id]
200
+ end
201
+
202
+ def get_current_test
203
+ return nil unless File.exist?(context_file)
204
+
205
+ context = JSON.parse(File.read(context_file), symbolize_names: true)
206
+ context[:current_test]
207
+ end
208
+
209
+ def get_current_test_steps
210
+ return [] unless File.exist?(context_file)
211
+
212
+ context = JSON.parse(File.read(context_file), symbolize_names: true)
213
+ context[:test_steps] || []
214
+ end
215
+
216
+ def clear_current_test_context
217
+ File.delete(context_file) if File.exist?(context_file)
218
+ end
126
219
  end
127
220
  end
128
221
  end
@@ -1,3 +1,3 @@
1
1
  module Capydash
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.6"
3
3
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capydash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damon Clark