lesli_testing 1.2.1 → 1.2.3

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: 9ded980f17f0eecf679e78acf07e9c161172ab5d5fd82fc9f81f39d725886f72
4
- data.tar.gz: 02b7b1279b175c6fb46d1818d190a920e40da7dfe34003c332237db2902f2d90
3
+ metadata.gz: d3f8b488a261e18bdf9030e0c369c534cd987341222892b3f397467ab382998b
4
+ data.tar.gz: bc20743265959a07b2acd5b1975b4d59eb9e30ab612d40621c1b8ccc1a86648e
5
5
  SHA512:
6
- metadata.gz: 8b018fb87570259581b7ebce74b0e50c37fdfb6be788b19d449fe9557d4512a8dca2f4ff4c6fa100394c8da6792b4d9513dab97fbdd154d98e3274f32437c3d3
7
- data.tar.gz: f09421aa36f74b8e7a840459d30a0ca9e08187367458810366dc7337cbabf4aa0e94f8caaa9753626043e9c3085955751901156537a787b4c9e9d1e544c418c3
6
+ metadata.gz: 17f37531c01a9a60131c69bd6cb87c6b4cb8b9a56ab54ddf1cfc04520fda3eb2f03d998f4b1c814ff4f29813ffb93280dbc940a28ba5b23de18d7b81c6b0861b
7
+ data.tar.gz: e29091cc308623a4f80d4423968c22d6882785dbf4712441567e3435e56f7fc1839e3120e6409fab285542fdae81d532ba364e71e29cea3efc18cfcb3c04f961
@@ -38,10 +38,6 @@ module LesliTesting
38
38
  # Run tests across all the engines: LESLI_INTEGRATION_TEST=true rails test
39
39
  # Run tests for the current engine: rails test
40
40
  if engine_module
41
- # Migration and Fixture logic goes here...
42
- ActiveRecord::Migrator.migrations_paths = [engine_module.root.join("db/migrate").to_s] if defined?(ActiveRecord)
43
- ActiveRecord::Migrator.migrations_paths = [engine_module.root.join("db/migrate/1.0").to_s] if defined?(ActiveRecord)
44
-
45
41
 
46
42
  # Load fixtures from the engine
47
43
  if ActiveSupport::TestCase.respond_to?(:fixture_paths=)
@@ -54,9 +54,9 @@ module LesliTesting
54
54
  "/config",
55
55
  "/docs",
56
56
  "/db",
57
- "/lib",
58
57
  "/test",
59
58
  "/test/dummy/",
59
+ "/lib/tasks",
60
60
  "/vendor"
61
61
  ]
62
62
 
@@ -0,0 +1,67 @@
1
+ =begin
2
+
3
+ Lesli
4
+
5
+ Copyright (c) 2026, Lesli Technologies, S. A.
6
+
7
+ This program is free software: you can redistribute it and/or modify
8
+ it under the terms of the GNU General Public License as published by
9
+ the Free Software Foundation, either version 3 of the License, or
10
+ (at your option) any later version.
11
+
12
+ This program is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ GNU General Public License for more details.
16
+
17
+ You should have received a copy of the GNU General Public License
18
+ along with this program. If not, see http://www.gnu.org/licenses/.
19
+
20
+ Lesli · Ruby on Rails SaaS Development Framework.
21
+
22
+ Made with ♥ by LesliTech
23
+ Building a better future, one line of code at a time.
24
+
25
+ @contact hello@lesli.tech
26
+ @website https://www.lesli.tech
27
+ @license GPLv3 http://www.gnu.org/licenses/gpl-3.0.en.html
28
+
29
+ // · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
30
+ // ·
31
+ =end
32
+
33
+ module LesliTesting
34
+ class Engine < ::Rails::Engine
35
+ initializer "lesli_testing.load_required_migrations", after: :load_config_initializers do |app|
36
+
37
+ # Only run this if we are in the test environment
38
+ unless Rails.env.production?
39
+
40
+ # 1. Define the dependencies you want to automatically include
41
+ # You can add more gems to this list as your ecosystem grows
42
+ dependencies = ["Lesli"]
43
+
44
+ dependencies.each do |gem_name|
45
+ begin
46
+ # Find the constant for the gem's Engine
47
+ gem_engine = "#{gem_name}::Engine".safe_constantize
48
+
49
+ if gem_engine
50
+ migration_path = gem_engine.root.join("db/migrate").to_s
51
+
52
+ # Append to the main app's migration paths if the directory exists
53
+ if Dir.exist?(migration_path)
54
+ app.config.paths["db/migrate"] << migration_path
55
+ end
56
+ end
57
+ rescue StandardError => e
58
+ puts "LesliTesting: Could not load migrations for #{gem_name}: #{e.message}"
59
+ end
60
+ end
61
+
62
+ # 2. Clean up duplicates
63
+ app.config.paths["db/migrate"].uniq!
64
+ end
65
+ end
66
+ end
67
+ end
@@ -37,8 +37,8 @@ require "simplecov-cobertura"
37
37
 
38
38
 
39
39
  # Load test frameworks
40
- require_relative "reporters/cli_reporter"
41
40
  require "minitest/lesli_testing_plugin"
41
+ require_relative "reporters/cli_reporter"
42
42
 
43
43
  # Force Minitest to know about Lesli Minitest reporter plugin
44
44
  unless Minitest.extensions.include?("lesli_testing")
@@ -55,16 +55,19 @@ module LesliTesting
55
55
 
56
56
  class << self
57
57
 
58
- def start_coverage!(engine_module = nil, options = {})
59
- return if defined?(SimpleCov) && SimpleCov.running
58
+ attr_accessor :engine_module;
59
+
60
+ def configure(engine_module = nil, options = {})
61
+
62
+ engine_module = engine_module ? engine_module.name : "RailsApp"
60
63
 
61
- name = engine_module ? engine_module.name : "RailsApp"
64
+ return if defined?(SimpleCov) && SimpleCov.running
62
65
 
63
66
  # Start Coverage
64
- LesliTesting::Coverage.start(name, options[:min_coverage] || 40)
67
+ LesliTesting::Coverage.start(engine_module, options[:min_coverage] || 40)
65
68
  end
66
69
 
67
- def configure_tests!(engine_module = nil)
70
+ def configure_tests()
68
71
 
69
72
  # Apply Minitest/Reporters/Paths
70
73
  LesliTesting::Config.apply(engine_module)
@@ -7,43 +7,54 @@ module LesliTesting
7
7
  class CliReporter < Minitest::StatisticsReporter
8
8
  def start
9
9
  super
10
+
11
+ Termline.br
12
+
10
13
  Termline.m(
11
- Termline::Style.colorize(" Running Lesli tests...", :blue),
12
- Termline::Style.colorize(" -> For a better result run test over a clean database", :blue),
13
- Termline::Style.colorize(" -> You can use: rake dev:db:reset", :blue)
14
+ Termline::Style.colorize("Running Lesli tests...", :blue),
15
+ Termline::Style.colorize("-> For a better result run test over a clean database", :blue),
16
+ Termline::Style.colorize("-> You can use: rake dev:db:reset", :blue)
14
17
  )
15
- Termline.br
18
+
19
+ Termline.br 2
16
20
  end
17
21
 
18
22
  def record(test)
19
23
  super
20
24
 
21
- assert_color = :green
22
- assert_color = :yellow if test.assertions < 5
23
- assert_color = :red if test.assertions < 2
24
-
25
- parts = []
26
- parts << Termline::Style.colorize('['+Time.now.strftime('%H:%M:%S:%L')+']', :gray)
27
-
28
- case test.result_code
29
- when "."
30
- parts << Termline::Style.colorize("PASS", :green)
31
- when "F"
32
- parts << Termline::Style.colorize("FAIL", :red)
33
- when "E"
34
- parts << Termline::Style.colorize("ERROR", :red)
35
- when "S"
36
- parts << Termline::Style.colorize("SKIP", :yellow)
25
+ # Only print the line if the configuration allows it
26
+ return if ENV["QUIET"]
27
+
28
+ # Map result codes to styles
29
+ status_map = {
30
+ "." => [:green, "PASS"],
31
+ "S" => [:yellow, "SKIP"],
32
+ "E" => [:red, "ERROR"],
33
+ "F" => [:red, "FAIL"]
34
+ }
35
+ color, label = status_map[test.result_code] || [:gray, "????"]
36
+
37
+ # Determine assertion health
38
+ assert_color = case test.assertions
39
+ when 0..1 then :red
40
+ when 2..4 then :yellow
41
+ else :green
37
42
  end
38
43
 
39
- parts << '::'
40
- parts << Termline::Style.colorize(test.klass, :blue)
41
- parts << '->'
42
- parts << Termline::Style.colorize(test.name, :skyblue)
43
- parts << Termline::Style.colorize("(#{ test.assertions} asserts)", assert_color)
44
- parts << Termline::Style.colorize("#{"(%.2fs)" % test.time}", :red) if test.time > 1
44
+ parts = [
45
+ Termline::Style.colorize("[#{Time.now.strftime('%H:%M:%S')}]", :gray),
46
+ Termline::Style.colorize(label, color),
47
+ "::",
48
+ Termline::Style.colorize(test.klass, :blue),
49
+ "->",
50
+ Termline::Style.colorize(test.name, :skyblue),
51
+ Termline::Style.colorize("(#{test.assertions} asserts)", assert_color)
52
+ ]
45
53
 
46
- puts(parts.compact.join(" ").strip)
54
+ # Add execution time per test
55
+ parts << Termline::Style.colorize("(%.2fs)" % test.time, :red) if test.time > 1
56
+
57
+ puts(parts.join(" "))
47
58
  end
48
59
 
49
60
  def report
@@ -86,7 +97,7 @@ module LesliTesting
86
97
  Termline.danger("Test suite failed", tag:'FAILURE')
87
98
  end
88
99
 
89
- Termline.br
100
+ Termline.br 2
90
101
 
91
102
  print_failure_details if total_failures.positive? || total_errors.positive?
92
103
 
@@ -104,22 +115,63 @@ module LesliTesting
104
115
  failure_tag = failure.is_a?(Minitest::Assertion) ? "FAILURE" : "ERROR"
105
116
  failure_msg = "#{result.class}##{result.name} (#{result.assertions} asserts)"
106
117
 
118
+ file, line = result.source_location
119
+ location_file = file ? "#{file} (line: #{line})" : "Location unknown"
120
+
107
121
  Termline.br
108
122
  Termline.line(6)
109
123
  Termline.br
110
124
 
125
+ puts Termline::Msg.builder(failure_msg, tag: " #{Termline::Style.icon(:error)} #{failure_tag} #{index + 1}:", color: :red, timestamp:nil)
126
+ puts Termline::Msg.builder(location_file, tag: " #{Termline::Style.icon(:debug)} Location:", color: :yellow, timestamp:nil)
127
+
111
128
  if failure.is_a?(Minitest::Assertion)
112
- Termline::Msg.builder(failure_msg, tag: " #{Termline::Style.icon(:error)} #{failure_tag} #{index + 1}:", color: :red, timestamp:nil)
113
- puts " #{Termline::Style.colorize('Location:', :yellow)} #{result.source_location.first} (line: #{result.source_location.second})"
114
- puts " #{Termline::Style.colorize(result.failure.message.to_s.lines.first.strip, :green)}"
115
- puts " #{Termline::Style.colorize(result.failure.message.to_s.lines.second.strip, :red)}"
116
- else
117
- Termline.warning(failure_msg, tag: failure_tag)
129
+ result.failure.message.to_s.lines.each do |message|
130
+ puts(parse_minitest_assertion_messages(message))
131
+ #puts(parse_minitest_assertion_messages2(message))
132
+ end
118
133
  end
119
134
  end
120
135
 
121
136
  Termline.br
122
137
  end
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
+ def parse_minitest_assertion_messages(message)
147
+ msg = message.strip
148
+
149
+ case msg
150
+
151
+ # 1. Boolean/Nil Failures (e.g., "Expected true to be nil" or "Expected false to be truthy")
152
+ when /Expected (.*) to be (nil|truthy|falsey)/, /Expected (.*) to be (.*)/
153
+ Termline::Style.colorize(" #{Termline::Style.icon(:info)} #{msg}", :skyblue)
154
+
155
+ # 2. Standard Diffs (Expected vs Actual)
156
+ when /^Expected:?\s+/
157
+ Termline::Style.colorize(" #{Termline::Style.icon(:add)} #{msg}", :green)
158
+
159
+ when /^Actual:?\s+/
160
+ Termline::Style.colorize(" #{Termline::Style.icon(:remove)} #{msg}", :red)
161
+
162
+ # 3. Rails Difference Failures (e.g., "User.count" didn't change by 1)
163
+ when /"(.*)" didn't change by (.*)/, /actual change was (.*)/
164
+ Termline::Style.colorize(" #{Termline::Style.icon(:warning)} #{msg}", :yellow)
165
+
166
+ # 4. Collection/Count Failures (e.g., Expected 5 elements, found 2)
167
+ when /Expected (.*) elements?, found (.*)/, /Expected exactly (.*) nodes/
168
+ Termline::Style.colorize(" #{Termline::Style.icon(:list)} #{msg}", :magenta)
169
+
170
+ # 5. Fallback for custom messages (anything else)
171
+ else
172
+ Termline::Style.colorize(" #{Termline::Style.icon(:arrow_right)} #{msg}", :gray)
173
+ end
174
+ end
123
175
  end
124
176
  end
125
177
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LesliTesting
4
- VERSION = "1.2.1"
5
- BUILD = "1774404580"
4
+ VERSION = "1.2.3"
5
+ BUILD = "1775000800"
6
6
  end
data/lib/lesli_testing.rb CHANGED
@@ -31,6 +31,7 @@
31
31
 
32
32
  #
33
33
  require_relative "lesli_testing/version"
34
+ require "termline" unless defined?(Termline)
34
35
 
35
36
  module LesliTesting
36
37
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lesli_testing
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Lesli Development Team
@@ -93,6 +93,20 @@ dependencies:
93
93
  - - "~>"
94
94
  - !ruby/object:Gem::Version
95
95
  version: 1.10.0
96
+ - !ruby/object:Gem::Dependency
97
+ name: termline
98
+ requirement: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: 1.1.0
103
+ type: :runtime
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: 1.1.0
96
110
  description: "Core testing utilities for the Lesli Platform, providing standardized
97
111
  Minitest configuration, \ncoverage setup, and shared testing conventions across
98
112
  engines and applications.\n"
@@ -105,6 +119,7 @@ files:
105
119
  - lib/lesli_testing.rb
106
120
  - lib/lesli_testing/config.rb
107
121
  - lib/lesli_testing/coverage.rb
122
+ - lib/lesli_testing/engine.rb
108
123
  - lib/lesli_testing/helpers/response_integration_helper.rb
109
124
  - lib/lesli_testing/loader.rb
110
125
  - lib/lesli_testing/reporters/cli_reporter.rb