lesli_testing 1.2.3 → 1.2.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 +4 -4
- data/lib/lesli_testing/config.rb +15 -6
- data/lib/lesli_testing/coverage.rb +1 -1
- data/lib/lesli_testing/loader.rb +12 -6
- data/lib/lesli_testing/reporters/cli_reporter.rb +68 -34
- data/lib/lesli_testing/testers.rb +18 -13
- data/lib/lesli_testing/version.rb +2 -2
- data/lib/minitest/lesli_testing_plugin.rb +6 -6
- data/readme.md +50 -1
- 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: e1cf4a585e7dba931395ea96d8d0c34a5043d4d89f04ad76a54efa9bfd3859ca
|
|
4
|
+
data.tar.gz: 23ad0d2b61b1ae38c6eb564259f034a2c06cf577b8432a9d3ec061effd223bbc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6639e33ce003c35998736b06e908b8e8ff44b19a68e4d24978f4dcbb848c084313579d7c9a9b673591b7d3de21b7c5d3bd00a97664faa737c5f6ccb05e90f03a
|
|
7
|
+
data.tar.gz: d31df87681c091a836d4d6b1c7f77c6dbb8f76fb776d637ed5c628106c3c18241123845b5538dd45501b47ac66a572a263df1c7f4a68c644c8a3ab8fa82bcac8
|
data/lib/lesli_testing/config.rb
CHANGED
|
@@ -34,6 +34,21 @@ module LesliTesting
|
|
|
34
34
|
module Config
|
|
35
35
|
def self.apply(engine_module = nil)
|
|
36
36
|
|
|
37
|
+
if defined?(Lesli)
|
|
38
|
+
# Load fixtures from Lesli
|
|
39
|
+
if ActiveSupport::TestCase.respond_to?(:fixture_paths=)
|
|
40
|
+
ActiveSupport::TestCase.fixture_paths = [ Lesli::Engine.root.join("test", "fixtures").to_s ]
|
|
41
|
+
ActionDispatch::IntegrationTest.fixture_paths = ActiveSupport::TestCase.fixture_paths
|
|
42
|
+
ActiveSupport::TestCase.file_fixture_path = Lesli::Engine.root.join("test", "fixtures", "files").to_s
|
|
43
|
+
|
|
44
|
+
# IMPORTANT: attach fixture sets to namespaced models BEFORE loading fixtures
|
|
45
|
+
ActiveSupport::TestCase.set_fixture_class(
|
|
46
|
+
lesli_users: "Lesli::User",
|
|
47
|
+
lesli_accounts: "Lesli::Account"
|
|
48
|
+
)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
37
52
|
# Load dummy app for unit testing
|
|
38
53
|
# Run tests across all the engines: LESLI_INTEGRATION_TEST=true rails test
|
|
39
54
|
# Run tests for the current engine: rails test
|
|
@@ -45,12 +60,6 @@ module LesliTesting
|
|
|
45
60
|
ActionDispatch::IntegrationTest.fixture_paths = ActiveSupport::TestCase.fixture_paths
|
|
46
61
|
ActiveSupport::TestCase.file_fixture_path = engine_module.root.join("test", "fixtures", "files").to_s
|
|
47
62
|
|
|
48
|
-
# IMPORTANT: attach fixture sets to namespaced models BEFORE loading fixtures
|
|
49
|
-
ActiveSupport::TestCase.set_fixture_class(
|
|
50
|
-
lesli_users: "Lesli::User",
|
|
51
|
-
lesli_accounts: "Lesli::Account"
|
|
52
|
-
)
|
|
53
|
-
|
|
54
63
|
ActiveSupport::TestCase.fixtures :all
|
|
55
64
|
end
|
|
56
65
|
end
|
data/lib/lesli_testing/loader.rb
CHANGED
|
@@ -40,11 +40,13 @@ require "simplecov-cobertura"
|
|
|
40
40
|
require "minitest/lesli_testing_plugin"
|
|
41
41
|
require_relative "reporters/cli_reporter"
|
|
42
42
|
|
|
43
|
+
|
|
43
44
|
# Force Minitest to know about Lesli Minitest reporter plugin
|
|
44
45
|
unless Minitest.extensions.include?("lesli_testing")
|
|
45
46
|
Minitest.register_plugin("lesli_testing")
|
|
46
47
|
end
|
|
47
48
|
|
|
49
|
+
|
|
48
50
|
# Load test configuration and test helper modules
|
|
49
51
|
require_relative "coverage"
|
|
50
52
|
require_relative "testers"
|
|
@@ -57,20 +59,24 @@ module LesliTesting
|
|
|
57
59
|
|
|
58
60
|
attr_accessor :engine_module;
|
|
59
61
|
|
|
60
|
-
def configure(engine_module = nil
|
|
62
|
+
def configure(engine_module = nil)
|
|
63
|
+
self.engine_module = engine_module
|
|
64
|
+
end
|
|
61
65
|
|
|
62
|
-
|
|
66
|
+
def configure_coverage(options)
|
|
67
|
+
|
|
68
|
+
engine_name = self.engine_module ? self.engine_module.name : "RailsApp"
|
|
63
69
|
|
|
64
70
|
return if defined?(SimpleCov) && SimpleCov.running
|
|
65
71
|
|
|
66
72
|
# Start Coverage
|
|
67
|
-
LesliTesting::Coverage.start(
|
|
68
|
-
end
|
|
73
|
+
LesliTesting::Coverage.start(engine_name, options[:min_coverage] || 40)
|
|
74
|
+
end
|
|
69
75
|
|
|
70
|
-
def
|
|
76
|
+
def configure_engine()
|
|
71
77
|
|
|
72
78
|
# Apply Minitest/Reporters/Paths
|
|
73
|
-
LesliTesting::Config.apply(engine_module)
|
|
79
|
+
LesliTesting::Config.apply(self.engine_module)
|
|
74
80
|
end
|
|
75
81
|
end
|
|
76
82
|
end
|
|
@@ -136,41 +136,75 @@ module LesliTesting
|
|
|
136
136
|
Termline.br
|
|
137
137
|
end
|
|
138
138
|
|
|
139
|
-
def parse_minitest_assertion_messages2 message
|
|
140
|
-
msg = message.strip
|
|
141
|
-
return Termline::Style.colorize(" + #{msg}", :green) if msg.start_with? "Expected:"
|
|
142
|
-
return Termline::Style.colorize(" - #{msg}", :red) if msg.start_with? "Actual:"
|
|
143
|
-
return Termline::Style.colorize(" #{Termline::Style.icon(:warning)} #{msg}", :yellow)
|
|
144
|
-
end
|
|
145
|
-
|
|
146
139
|
def parse_minitest_assertion_messages(message)
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
140
|
+
message.to_s.rstrip.lines.map do |line|
|
|
141
|
+
msg = line.strip
|
|
142
|
+
|
|
143
|
+
case msg
|
|
144
|
+
|
|
145
|
+
# 1. Unified Diff Headers
|
|
146
|
+
# Covers Minitest diff output like:
|
|
147
|
+
# --- expected
|
|
148
|
+
# +++ actual
|
|
149
|
+
# @@ -1 +1 @@
|
|
150
|
+
when /^--- /
|
|
151
|
+
Termline::Style.colorize("#{msg}:", :red)
|
|
152
|
+
|
|
153
|
+
when /^\+\+\+ /
|
|
154
|
+
Termline::Style.colorize("++#{msg}:", :green)
|
|
155
|
+
|
|
156
|
+
when /^@@ /
|
|
157
|
+
Termline::Style.colorize("#{msg}", :skyblue)
|
|
158
|
+
|
|
159
|
+
# 2. Unified Diff Content Lines
|
|
160
|
+
# Covers actual changed lines inside the diff, like:
|
|
161
|
+
# -[:lesli_support_item_tasks, "lesli_support"]
|
|
162
|
+
# +[:lesli_support_items_tasks, "lesli_support"]
|
|
163
|
+
# The negative lookahead avoids matching the diff headers above.
|
|
164
|
+
when /^-(?!-)/
|
|
165
|
+
Termline::Style.colorize(" #{Termline::Style.icon(:remove)}-#{msg}", :red)
|
|
166
|
+
|
|
167
|
+
when /^\+(?!\+)/
|
|
168
|
+
Termline::Style.colorize(" #{Termline::Style.icon(:add)}+#{msg}", :green)
|
|
169
|
+
|
|
170
|
+
# 3. Boolean/Nil Failures
|
|
171
|
+
# Covers cases like:
|
|
172
|
+
# Expected true to be nil
|
|
173
|
+
# Expected false to be truthy
|
|
174
|
+
# Expected "abc" to be empty
|
|
175
|
+
when /Expected (.*) to be (nil|truthy|falsey)/, /Expected (.*) to be (.*)/
|
|
176
|
+
Termline::Style.colorize(" #{Termline::Style.icon(:info)} #{msg}", :skyblue)
|
|
177
|
+
|
|
178
|
+
# 4. Standard Expected vs Actual Output
|
|
179
|
+
# Covers simple assertion output like:
|
|
180
|
+
# Expected: 1
|
|
181
|
+
# Actual: 2
|
|
182
|
+
when /^Expected:?\s+/
|
|
183
|
+
Termline::Style.colorize(" #{Termline::Style.icon(:add)} #{msg}", :green)
|
|
184
|
+
|
|
185
|
+
when /^Actual:?\s+/
|
|
186
|
+
Termline::Style.colorize(" #{Termline::Style.icon(:remove)} #{msg}", :red)
|
|
187
|
+
|
|
188
|
+
# 5. Rails Difference Failures
|
|
189
|
+
# Covers assertions like:
|
|
190
|
+
# "User.count" didn't change by 1
|
|
191
|
+
# actual change was 0
|
|
192
|
+
when /"(.*)" didn't change by (.*)/, /actual change was (.*)/
|
|
193
|
+
Termline::Style.colorize(" #{Termline::Style.icon(:warning)} #{msg}", :yellow)
|
|
194
|
+
|
|
195
|
+
# 6. Collection/Count Failures
|
|
196
|
+
# Covers collection assertions like:
|
|
197
|
+
# Expected 5 elements, found 2
|
|
198
|
+
# Expected exactly 1 nodes
|
|
199
|
+
when /Expected (.*) elements?, found (.*)/, /Expected exactly (.*) nodes/
|
|
200
|
+
Termline::Style.colorize(" #{Termline::Style.icon(:list)} #{msg}", :magenta)
|
|
201
|
+
|
|
202
|
+
# 7. Fallback for Custom or Unrecognized Messages
|
|
203
|
+
# Covers anything else not matched above.
|
|
204
|
+
else
|
|
205
|
+
Termline::Style.colorize(" #{Termline::Style.icon(:arrow_right)} #{msg}", :gray)
|
|
206
|
+
end
|
|
207
|
+
end.join("\n")
|
|
174
208
|
end
|
|
175
209
|
end
|
|
176
210
|
end
|
|
@@ -37,24 +37,29 @@ require_relative "helpers/response_integration_helper"
|
|
|
37
37
|
#
|
|
38
38
|
module LesliTesting
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
if defined?(ActionDispatch::IntegrationTest)
|
|
41
|
+
class IntegrationTester < ActionDispatch::IntegrationTest
|
|
42
|
+
include ResponseIntegrationHelper
|
|
43
|
+
end
|
|
42
44
|
end
|
|
43
45
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
if defined?(ActionView::TestCase)
|
|
47
|
+
class ViewTester < ActionView::TestCase
|
|
48
|
+
# We use a hook to include the helpers only when the class is used.
|
|
49
|
+
# This ensures Lesli core is fully loaded by Rails before we ask for the helpers.
|
|
50
|
+
def self.inherited(subclass)
|
|
51
|
+
super
|
|
52
|
+
subclass.class_eval do
|
|
53
|
+
include Lesli::HtmlHelper if defined?(Lesli::HtmlHelper)
|
|
54
|
+
include Lesli::SystemHelper if defined?(Lesli::SystemHelper)
|
|
55
|
+
end
|
|
52
56
|
end
|
|
53
57
|
end
|
|
54
58
|
end
|
|
55
59
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
60
|
+
if defined?(ActiveSupport::TestCase)
|
|
61
|
+
class ModelTester < ActiveSupport::TestCase
|
|
62
|
+
include ActiveSupport::Testing::TimeHelpers
|
|
63
|
+
end
|
|
59
64
|
end
|
|
60
65
|
end
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
require "lesli_testing/reporters/cli_reporter"
|
|
2
2
|
|
|
3
3
|
module Minitest
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
def self.plugin_lesli_testing_options(opts, options)
|
|
5
|
+
end
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
def self.plugin_lesli_testing_init(options)
|
|
8
|
+
reporter.reporters.clear if reporter.respond_to?(:reporters)
|
|
9
|
+
reporter << LesliTesting::Reporters::CliReporter.new($stdout, options)
|
|
10
|
+
end
|
|
11
11
|
end
|
data/readme.md
CHANGED
|
@@ -10,11 +10,60 @@
|
|
|
10
10
|
|
|
11
11
|
### Quick start
|
|
12
12
|
|
|
13
|
+
|
|
14
|
+
**Install LesliTesting gem**
|
|
15
|
+
|
|
13
16
|
```shell
|
|
14
|
-
# Add LesliAdmin engine gem
|
|
15
17
|
bundle add lesli_testing
|
|
16
18
|
```
|
|
17
19
|
|
|
20
|
+
**Include LesliTesting in your rails/test/test_helper.rb**
|
|
21
|
+
|
|
22
|
+
```ruby
|
|
23
|
+
|
|
24
|
+
# load lesli testing tools
|
|
25
|
+
require "lesli_testing/loader"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# register engine for testing
|
|
29
|
+
LesliTesting.configure(Lesli::Engine)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
# initialize coverage
|
|
33
|
+
LesliTesting.configure_coverage({ :min_coverage => 10 })
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
# Loading dummy app
|
|
37
|
+
require_relative "../test/dummy/config/environment"
|
|
38
|
+
ActiveRecord::Migrator.migrations_paths = [ File.expand_path("../test/dummy/db/migrate", __dir__) ]
|
|
39
|
+
ActiveRecord::Migrator.migrations_paths << File.expand_path("../db/migrate", __dir__)
|
|
40
|
+
require "rails/test_help"
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
# configure tests
|
|
44
|
+
LesliTesting.configure_engine()
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
**Run your tests D:**
|
|
48
|
+
|
|
49
|
+
```shell
|
|
50
|
+
rails test
|
|
51
|
+
|
|
52
|
+
# or
|
|
53
|
+
|
|
54
|
+
COVERAGE=true rails test
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**Result :D**
|
|
58
|
+
|
|
59
|
+
<div align="center">
|
|
60
|
+
<img
|
|
61
|
+
style="width:100%;max-width:800px;border-radius:6px;"
|
|
62
|
+
alt="LesliTesting screenshot" src="./docs/images/screenshot.png" />
|
|
63
|
+
</div>
|
|
64
|
+
|
|
65
|
+
<br />
|
|
66
|
+
<br />
|
|
18
67
|
|
|
19
68
|
### Documentation
|
|
20
69
|
* [website](https://www.lesli.dev/)
|