capydash 0.1.3 → 0.1.4

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: aa238074c05a59e8c88ec84c887944dc2c376ae379ffde69c3422b939d052d77
4
- data.tar.gz: fdfc24fbe669f5a8d0ff44792383b5eae3abcf69d21ed52810228972d0773959
3
+ metadata.gz: 92f824ed1079edfc71c33d6260bf708a036a9a0f99a20f10c919a2a0f305623a
4
+ data.tar.gz: c70b934e69ae0b8a4759146044beb115f1f3170ccdfd7d6fd7d1480f2492f2d2
5
5
  SHA512:
6
- metadata.gz: b49bd9f834a849025f79fc72fc3c317e971fba0ea74504e09d35026a4bdb18b224f48a86ab6041fb43a78de5dd6897ecba9ca43e9f57bfc356385a318313f0e4
7
- data.tar.gz: 9c3f988ea6164e454f73d1600ec61ceddfc63f9f6dbb4220c535df60ecf4662f08653fdbcfc9bf6936616382455d8bef473a5f03336d6af8aba72da328c67428
6
+ metadata.gz: 0cbabbb16e97c1ef1214e383dc6166cfb84c3267ae9e5e26f131483420e380d102e4ac0c36ba8c589332b1068cf3d1270d9e6a631e7c06cf24540002af1106a0
7
+ data.tar.gz: b170062c27cd772973a37380e681b28846c592bfdbf17287b9be2535f6e71a71d6d6415970fdd8bf1f047d033d76dc5ee79bcf198112955981231b11fa71b7c4
data/README.md CHANGED
@@ -16,8 +16,36 @@ Or run:
16
16
  bundle add capydash
17
17
  ```
18
18
 
19
+ ## Quick Setup
20
+
21
+ ### One-Command Installation
22
+
23
+ After adding CapyDash to your Gemfile and running `bundle install`, simply run:
24
+
25
+ ```bash
26
+ bundle exec rails generate capydash:install
27
+ ```
28
+
29
+ This will automatically:
30
+ - ✅ Create the CapyDash initializer
31
+ - ✅ Update your test helper with all necessary hooks
32
+ - ✅ Add rake tasks for report generation
33
+ - ✅ Create an example test to get you started
34
+
35
+ ### Manual Setup (Alternative)
36
+
37
+ If you prefer to set up CapyDash manually, see the [Manual Setup Guide](#manual-setup) below.
38
+
19
39
  ## Usage
20
40
 
41
+ ### Run Tests with CapyDash
42
+
43
+ Run your tests normally - CapyDash will automatically instrument them:
44
+
45
+ ```bash
46
+ bundle exec rails test
47
+ ```
48
+
21
49
  ### Generate Test Report
22
50
 
23
51
  After running your Capybara tests, generate a static HTML report:
@@ -45,17 +73,131 @@ open capydash_report/index.html
45
73
  bundle exec rake capydash:server
46
74
  ```
47
75
 
48
- Then open `http://localhost:5173` in your browser.
76
+ Then open `http://localhost:4000` in your browser.
49
77
 
50
- ### Run Tests with CapyDash
78
+ ## Troubleshooting
51
79
 
52
- Run your tests normally - CapyDash will automatically instrument them:
80
+ ### Common Issues
53
81
 
54
- ```bash
55
- bundle exec rails test
82
+ 1. **"No test data found"**: Make sure you've added the test helper configuration and are running actual Capybara tests (not just unit tests).
83
+
84
+ 2. **"log shifting failed" error**: This is a Rails logger issue, not related to CapyDash. It's harmless but you can fix it by updating your Rails version.
85
+
86
+ 3. **Screenshots not working**: Make sure you're using a driver that supports screenshots (like Selenium, not rack_test).
87
+
88
+ 4. **Tests not appearing in report**: Ensure your tests are using Capybara methods like `visit`, `click_button`, `fill_in`, etc.
89
+
90
+ ### Example Test
91
+
92
+ Here's an example test that will work with CapyDash:
93
+
94
+ ```ruby
95
+ require 'test_helper'
96
+
97
+ class HomepageTest < ActionDispatch::IntegrationTest
98
+ include Capybara::DSL
99
+
100
+ test "homepage loads with correct content" do
101
+ visit "/"
102
+ assert_text "Welcome"
103
+
104
+ fill_in "Your name", with: "Alice"
105
+ click_button "Greet"
106
+ assert_text "Hello, Alice!"
107
+ end
108
+ end
109
+ ```
110
+
111
+ ## Manual Setup
112
+
113
+ If you prefer to set up CapyDash manually instead of using the generator:
114
+
115
+ ### Step 1: Create CapyDash Initializer
116
+
117
+ Create `config/initializers/capydash.rb` in your Rails project:
118
+
119
+ ```ruby
120
+ require 'capydash'
121
+
122
+ # Configure CapyDash
123
+ CapyDash.configure do |config|
124
+ config.port = 4000
125
+ config.screenshot_path = "tmp/capydash_screenshots"
126
+ end
127
+
128
+ # Subscribe to events for test data collection
129
+ CapyDash::EventEmitter.subscribe do |event|
130
+ # Collect test data for report generation
131
+ CapyDash::TestDataAggregator.handle_event(event)
132
+ end
133
+ ```
134
+
135
+ ### Step 2: Update Test Helper
136
+
137
+ In your `test/test_helper.rb`, add the following:
138
+
139
+ ```ruby
140
+ require 'capydash'
141
+
142
+ # Start test run data collection
143
+ CapyDash::TestDataCollector.start_test_run
144
+
145
+ # Hook into test execution to set current test name and manage test runs
146
+ module CapyDash
147
+ module TestHooks
148
+ def run(&block)
149
+ # Set the current test name for CapyDash
150
+ CapyDash.current_test = self.name
151
+
152
+ # Start test run data collection if not already started
153
+ CapyDash::TestDataAggregator.start_test_run unless CapyDash::TestDataAggregator.instance_variable_get(:@current_run)
154
+
155
+ super
156
+ end
157
+ end
158
+ end
159
+
160
+ # Apply the hook to the test case
161
+ class ActiveSupport::TestCase
162
+ prepend CapyDash::TestHooks
163
+ end
164
+
165
+ # Hook to finish test run when all tests are done
166
+ Minitest.after_run do
167
+ CapyDash::TestDataCollector.finish_test_run
168
+ CapyDash::TestDataAggregator.finish_test_run
169
+ end
56
170
  ```
57
171
 
58
- The report will be generated in `capydash_report/index.html` after test completion.
172
+ ### Step 3: Add Rake Tasks
173
+
174
+ Create `lib/tasks/capydash.rake` in your Rails project:
175
+
176
+ ```ruby
177
+ namespace :capydash do
178
+ desc "Generate static HTML test report"
179
+ task :report => :environment do
180
+ CapyDash::ReportGenerator.generate_report
181
+ end
182
+
183
+ desc "Start local server to view static HTML report"
184
+ task :server => :environment do
185
+ CapyDash::DashboardServer.start
186
+ end
187
+ end
188
+ ```
189
+
190
+ ### Step 4: Configure System Tests (Optional)
191
+
192
+ If you're using system tests, make sure your `test/application_system_test_case.rb` uses a driver that supports screenshots:
193
+
194
+ ```ruby
195
+ require "test_helper"
196
+
197
+ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
198
+ driven_by :selenium, using: :headless_chrome, screen_size: [ 800, 600 ]
199
+ end
200
+ ```
59
201
 
60
202
  ## Development
61
203
 
data/capydash.gemspec CHANGED
@@ -16,6 +16,9 @@ Gem::Specification.new do |spec|
16
16
  spec.files = Dir["lib/**/*", "bin/*", "README.md", "LICENSE*", "*.gemspec"]
17
17
  spec.require_paths = ["lib"]
18
18
 
19
+ # Add generator support
20
+ spec.add_runtime_dependency "railties", ">= 5.0"
21
+
19
22
  # Dependencies
20
23
  spec.add_runtime_dependency "capybara", ">= 3.0"
21
24
  spec.add_runtime_dependency "faye-websocket"
@@ -1,3 +1,3 @@
1
1
  module Capydash
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -0,0 +1,145 @@
1
+ require 'rails/generators'
2
+
3
+ module Capydash
4
+ module Generators
5
+ class InstallGenerator < Rails::Generators::Base
6
+ source_root File.expand_path('templates', __dir__)
7
+
8
+ desc "Installs CapyDash with all necessary configuration files"
9
+
10
+ def create_initializer
11
+ create_file "config/initializers/capydash.rb", <<~RUBY
12
+ require 'capydash'
13
+
14
+ # Configure CapyDash
15
+ CapyDash.configure do |config|
16
+ config.port = 4000
17
+ config.screenshot_path = "tmp/capydash_screenshots"
18
+ end
19
+
20
+ # Subscribe to events for test data collection
21
+ CapyDash::EventEmitter.subscribe do |event|
22
+ # Collect test data for report generation
23
+ CapyDash::TestDataAggregator.handle_event(event)
24
+ end
25
+ RUBY
26
+ end
27
+
28
+ def create_rake_tasks
29
+ create_file "lib/tasks/capydash.rake", <<~RUBY
30
+ namespace :capydash do
31
+ desc "Generate static HTML test report"
32
+ task :report => :environment do
33
+ CapyDash::ReportGenerator.generate_report
34
+ end
35
+
36
+ desc "Start local server to view static HTML report"
37
+ task :server => :environment do
38
+ CapyDash::DashboardServer.start
39
+ end
40
+ end
41
+ RUBY
42
+ end
43
+
44
+ def update_test_helper
45
+ test_helper_path = "test/test_helper.rb"
46
+
47
+ if File.exist?(test_helper_path)
48
+ # Read existing test helper
49
+ content = File.read(test_helper_path)
50
+
51
+ # Check if CapyDash is already configured
52
+ unless content.include?("require 'capydash'")
53
+ # Add CapyDash configuration
54
+ capydash_config = <<~RUBY
55
+
56
+ # CapyDash configuration
57
+ require 'capydash'
58
+
59
+ # Start test run data collection
60
+ CapyDash::TestDataCollector.start_test_run
61
+
62
+ # Hook into test execution to set current test name and manage test runs
63
+ module CapyDash
64
+ module TestHooks
65
+ def run(&block)
66
+ # Set the current test name for CapyDash
67
+ CapyDash.current_test = self.name
68
+
69
+ # Start test run data collection if not already started
70
+ CapyDash::TestDataAggregator.start_test_run unless CapyDash::TestDataAggregator.instance_variable_get(:@current_run)
71
+
72
+ super
73
+ end
74
+ end
75
+ end
76
+
77
+ # Apply the hook to the test case
78
+ class ActiveSupport::TestCase
79
+ prepend CapyDash::TestHooks
80
+ end
81
+
82
+ # Hook to finish test run when all tests are done
83
+ Minitest.after_run do
84
+ CapyDash::TestDataCollector.finish_test_run
85
+ CapyDash::TestDataAggregator.finish_test_run
86
+ end
87
+ RUBY
88
+
89
+ # Insert after the last require statement
90
+ if content.match(/require.*\n/)
91
+ content = content.gsub(/(require.*\n)/, "\\1#{capydash_config}")
92
+ else
93
+ content = capydash_config + content
94
+ end
95
+
96
+ File.write(test_helper_path, content)
97
+ say "Updated test/test_helper.rb with CapyDash configuration"
98
+ else
99
+ say "CapyDash already configured in test/test_helper.rb", :yellow
100
+ end
101
+ else
102
+ say "test/test_helper.rb not found. Please add CapyDash configuration manually.", :red
103
+ end
104
+ end
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
+
132
+ def show_instructions
133
+ say "\n" + "="*60, :green
134
+ say "CapyDash has been successfully installed!", :green
135
+ say "="*60, :green
136
+ say "\nNext steps:", :yellow
137
+ say "1. Run your tests: bundle exec rails test"
138
+ say "2. Generate report: bundle exec rake capydash:report"
139
+ say "3. View report: open capydash_report/index.html"
140
+ say "\nFor more information, see the README.md file."
141
+ say "="*60, :green
142
+ end
143
+ end
144
+ end
145
+ 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.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damon Clark
@@ -9,6 +9,20 @@ bindir: bin
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: railties
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '5.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '5.0'
12
26
  - !ruby/object:Gem::Dependency
13
27
  name: capybara
14
28
  requirement: !ruby/object:Gem::Requirement
@@ -119,6 +133,7 @@ files:
119
133
  - lib/capydash/test_data_aggregator.rb
120
134
  - lib/capydash/test_data_collector.rb
121
135
  - lib/capydash/version.rb
136
+ - lib/generators/capydash/install_generator.rb
122
137
  - lib/tasks/capydash.rake
123
138
  homepage: https://github.com/damonclark/capydash
124
139
  licenses: