tryouts 3.0.0 → 3.1.0

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.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +51 -115
  3. data/exe/try +25 -4
  4. data/lib/tryouts/cli/formatters/base.rb +33 -21
  5. data/lib/tryouts/cli/formatters/compact.rb +122 -84
  6. data/lib/tryouts/cli/formatters/factory.rb +1 -1
  7. data/lib/tryouts/cli/formatters/output_manager.rb +13 -2
  8. data/lib/tryouts/cli/formatters/quiet.rb +22 -16
  9. data/lib/tryouts/cli/formatters/verbose.rb +101 -60
  10. data/lib/tryouts/console.rb +53 -17
  11. data/lib/tryouts/expectation_evaluators/base.rb +101 -0
  12. data/lib/tryouts/expectation_evaluators/boolean.rb +60 -0
  13. data/lib/tryouts/expectation_evaluators/exception.rb +61 -0
  14. data/lib/tryouts/expectation_evaluators/expectation_result.rb +67 -0
  15. data/lib/tryouts/expectation_evaluators/false.rb +60 -0
  16. data/lib/tryouts/expectation_evaluators/intentional_failure.rb +74 -0
  17. data/lib/tryouts/expectation_evaluators/output.rb +101 -0
  18. data/lib/tryouts/expectation_evaluators/performance_time.rb +81 -0
  19. data/lib/tryouts/expectation_evaluators/regex_match.rb +57 -0
  20. data/lib/tryouts/expectation_evaluators/registry.rb +66 -0
  21. data/lib/tryouts/expectation_evaluators/regular.rb +67 -0
  22. data/lib/tryouts/expectation_evaluators/result_type.rb +51 -0
  23. data/lib/tryouts/expectation_evaluators/true.rb +58 -0
  24. data/lib/tryouts/prism_parser.rb +112 -15
  25. data/lib/tryouts/test_executor.rb +6 -4
  26. data/lib/tryouts/test_runner.rb +1 -1
  27. data/lib/tryouts/testbatch.rb +288 -98
  28. data/lib/tryouts/testcase.rb +141 -0
  29. data/lib/tryouts/translators/minitest_translator.rb +40 -11
  30. data/lib/tryouts/translators/rspec_translator.rb +47 -12
  31. data/lib/tryouts/version.rb +1 -1
  32. data/lib/tryouts.rb +42 -0
  33. metadata +16 -3
@@ -27,11 +27,24 @@ class Tryouts
27
27
 
28
28
  method_name = "test_#{index.to_s.rjust(3, '0')}_#{parameterize(test_case.description)}"
29
29
  define_method(method_name) do
30
- result = instance_eval(test_case.code) unless test_case.code.strip.empty?
31
-
32
- test_case.expectations.each do |expectation|
33
- expected_value = instance_eval(expectation)
34
- assert_equal expected_value, result
30
+ if test_case.exception_expectations?
31
+ # Handle exception expectations
32
+ assert_raises(StandardError) do
33
+ instance_eval(test_case.code) unless test_case.code.strip.empty?
34
+ end
35
+
36
+ test_case.exception_expectations.each do |expectation|
37
+ result = instance_eval(expectation.content)
38
+ assert result, "Exception expectation failed: #{expectation.content}"
39
+ end
40
+ else
41
+ # Handle regular expectations
42
+ result = instance_eval(test_case.code) unless test_case.code.strip.empty?
43
+
44
+ test_case.regular_expectations.each do |expectation|
45
+ expected_value = instance_eval(expectation.content)
46
+ assert_equal expected_value, result
47
+ end
35
48
  end
36
49
  end
37
50
  end
@@ -72,15 +85,31 @@ class Tryouts
72
85
 
73
86
  method_name = "test_#{index.to_s.rjust(3, '0')}_#{parameterize(test_case.description)}"
74
87
  lines << " def #{method_name}"
75
- unless test_case.code.strip.empty?
76
- lines << ' result = begin'
77
- test_case.code.lines.each { |line| lines << " #{line.chomp}" }
88
+
89
+ if test_case.exception_expectations?
90
+ # Handle exception expectations
91
+ lines << ' error = assert_raises(StandardError) do'
92
+ unless test_case.code.strip.empty?
93
+ test_case.code.lines.each { |line| lines << " #{line.chomp}" }
94
+ end
78
95
  lines << ' end'
79
- end
80
96
 
81
- test_case.expectations.each do |expectation|
82
- lines << " assert_equal #{expectation}, result"
97
+ test_case.exception_expectations.each do |expectation|
98
+ lines << " assert #{expectation}, \"Exception expectation failed: #{expectation}\""
99
+ end
100
+ else
101
+ # Handle regular expectations
102
+ unless test_case.code.strip.empty?
103
+ lines << ' result = begin'
104
+ test_case.code.lines.each { |line| lines << " #{line.chomp}" }
105
+ lines << ' end'
106
+ end
107
+
108
+ test_case.expectations.each do |expectation|
109
+ lines << " assert_equal #{expectation}, result"
110
+ end
83
111
  end
112
+
84
113
  lines << ' end'
85
114
  lines << ''
86
115
  end
@@ -16,7 +16,7 @@ class Tryouts
16
16
  # Setup before all tests
17
17
  if testrun.setup && !testrun.setup.empty?
18
18
  before(:all) do
19
- instance_eval(testrun.setup.code)
19
+ instance_eval(testrun.setup.code, testrun.source_file)
20
20
  end
21
21
  end
22
22
 
@@ -25,11 +25,27 @@ class Tryouts
25
25
  next if test_case.empty? || !test_case.expectations?
26
26
 
27
27
  it test_case.description do
28
- result = instance_eval(test_case.code) unless test_case.code.strip.empty?
28
+ if test_case.exception_expectations?
29
+ # Handle exception expectations
30
+ error = nil
31
+ expect do
32
+ instance_eval(test_case.code, testrun.source_file) unless test_case.code.strip.empty?
33
+ end.to raise_error do |caught_error|
34
+ error = caught_error
35
+ end
29
36
 
30
- test_case.expectations.each do |expectation|
31
- expected_value = instance_eval(expectation)
32
- expect(result).to eq(expected_value)
37
+ test_case.exception_expectations.each do |expectation|
38
+ expected_value = instance_eval(expectation.content, testrun.source_file)
39
+ expect(expected_value).to be_truthy
40
+ end
41
+ else
42
+ # Handle regular expectations
43
+ result = instance_eval(test_case.code, testrun.source_file) unless test_case.code.strip.empty?
44
+
45
+ test_case.regular_expectations.each do |expectation|
46
+ expected_value = instance_eval(expectation.content, testrun.source_file)
47
+ expect(result).to eq(expected_value)
48
+ end
33
49
  end
34
50
  end
35
51
  end
@@ -37,7 +53,7 @@ class Tryouts
37
53
  # Teardown after all tests
38
54
  if testrun.teardown && !testrun.teardown.empty?
39
55
  after(:all) do
40
- instance_eval(testrun.teardown.code)
56
+ instance_eval(testrun.teardown.code, testrun.source_file)
41
57
  end
42
58
  end
43
59
  end
@@ -61,15 +77,34 @@ class Tryouts
61
77
  next if test_case.empty? || !test_case.expectations?
62
78
 
63
79
  lines << " it '#{test_case.description}' do"
64
- unless test_case.code.strip.empty?
65
- lines << ' result = begin'
66
- test_case.code.lines.each { |line| lines << " #{line.chomp}" }
80
+
81
+ if test_case.exception_expectations?
82
+ # Handle exception expectations
83
+ lines << ' error = nil'
84
+ lines << ' expect {'
85
+ unless test_case.code.strip.empty?
86
+ test_case.code.lines.each { |line| lines << " #{line.chomp}" }
87
+ end
88
+ lines << ' }.to raise_error do |caught_error|'
89
+ lines << ' error = caught_error'
67
90
  lines << ' end'
68
- end
69
91
 
70
- test_case.expectations.each do |expectation|
71
- lines << " expect(result).to eq(#{expectation})"
92
+ test_case.exception_expectations.each do |expectation|
93
+ lines << " expect(#{expectation.content}).to be_truthy"
94
+ end
95
+ else
96
+ # Handle regular expectations
97
+ unless test_case.code.strip.empty?
98
+ lines << ' result = begin'
99
+ test_case.code.lines.each { |line| lines << " #{line.chomp}" }
100
+ lines << ' end'
101
+ end
102
+
103
+ test_case.regular_expectations.each do |expectation|
104
+ lines << " expect(result).to eq(#{expectation.content})"
105
+ end
72
106
  end
107
+
73
108
  lines << ' end'
74
109
  lines << ''
75
110
  end
@@ -1,5 +1,5 @@
1
1
  # lib/tryouts/version.rb
2
2
 
3
3
  class Tryouts
4
- VERSION = '3.0.0'
4
+ VERSION = '3.1.0'
5
5
  end
data/lib/tryouts.rb CHANGED
@@ -3,6 +3,7 @@
3
3
 
4
4
 
5
5
  require 'stringio'
6
+ require 'timeout'
6
7
 
7
8
  TRYOUTS_LIB_HOME = __dir__ unless defined?(TRYOUTS_LIB_HOME)
8
9
 
@@ -47,6 +48,47 @@ class Tryouts
47
48
  prefix = (' ' * indent) + Console.color(:dim, 'TRACE')
48
49
  warn "#{prefix} #{msg}"
49
50
  end
51
+
52
+ def debug(msg, indent: 0)
53
+ return unless debug?
54
+
55
+ prefix = (' ' * indent) + Console.color(:cyan, 'DEBUG')
56
+ warn "#{prefix} #{msg}"
57
+ end
58
+
59
+ # Error classification for resilient error handling
60
+ def classify_error(exception)
61
+ case exception
62
+ when SystemExit, SignalException
63
+ :non_recoverable_exit
64
+ when Timeout::Error
65
+ :transient
66
+ when Errno::ENOENT, Errno::EACCES, Errno::EPERM
67
+ :file_system
68
+ when LoadError, NameError, NoMethodError
69
+ :code_structure
70
+ when SecurityError, NoMemoryError, SystemStackError
71
+ :system_resource
72
+ when SyntaxError, TryoutSyntaxError
73
+ :syntax
74
+ when StandardError
75
+ :recoverable
76
+ else
77
+ :unknown
78
+ end
79
+ end
80
+
81
+ # Determine if an error should stop batch execution
82
+ def batch_stopping_error?(exception)
83
+ classification = classify_error(exception)
84
+ [:non_recoverable_exit, :system_resource, :syntax].include?(classification)
85
+ end
86
+
87
+ # Determine if an error should stop individual test execution
88
+ def test_stopping_error?(exception)
89
+ classification = classify_error(exception)
90
+ [:non_recoverable_exit, :system_resource].include?(classification)
91
+ end
50
92
  end
51
93
 
52
94
  extend ClassMethods
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tryouts
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Delano Mandelbaum
@@ -83,6 +83,19 @@ files:
83
83
  - lib/tryouts/cli/modes/inspect.rb
84
84
  - lib/tryouts/cli/opts.rb
85
85
  - lib/tryouts/console.rb
86
+ - lib/tryouts/expectation_evaluators/base.rb
87
+ - lib/tryouts/expectation_evaluators/boolean.rb
88
+ - lib/tryouts/expectation_evaluators/exception.rb
89
+ - lib/tryouts/expectation_evaluators/expectation_result.rb
90
+ - lib/tryouts/expectation_evaluators/false.rb
91
+ - lib/tryouts/expectation_evaluators/intentional_failure.rb
92
+ - lib/tryouts/expectation_evaluators/output.rb
93
+ - lib/tryouts/expectation_evaluators/performance_time.rb
94
+ - lib/tryouts/expectation_evaluators/regex_match.rb
95
+ - lib/tryouts/expectation_evaluators/registry.rb
96
+ - lib/tryouts/expectation_evaluators/regular.rb
97
+ - lib/tryouts/expectation_evaluators/result_type.rb
98
+ - lib/tryouts/expectation_evaluators/true.rb
86
99
  - lib/tryouts/file_processor.rb
87
100
  - lib/tryouts/prism_parser.rb
88
101
  - lib/tryouts/test_executor.rb
@@ -104,14 +117,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
104
117
  requirements:
105
118
  - - ">="
106
119
  - !ruby/object:Gem::Version
107
- version: '3.4'
120
+ version: '3.2'
108
121
  required_rubygems_version: !ruby/object:Gem::Requirement
109
122
  requirements:
110
123
  - - ">="
111
124
  - !ruby/object:Gem::Version
112
125
  version: '0'
113
126
  requirements: []
114
- rubygems_version: 3.6.7
127
+ rubygems_version: 3.6.9
115
128
  specification_version: 4
116
129
  summary: Ruby tests that read like documentation.
117
130
  test_files: []