test_bench-fixture 1.4.0.2 → 2.1.0.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/lib/test_bench/fixture/actuate/class.rb +95 -0
  3. data/lib/test_bench/fixture/actuate/object.rb +91 -0
  4. data/lib/test_bench/fixture/controls/exception.rb +7 -0
  5. data/lib/test_bench/fixture/controls/fixture/class.rb +86 -0
  6. data/lib/test_bench/fixture/controls/fixture/object/modules.rb +39 -0
  7. data/lib/test_bench/fixture/controls/fixture/object.rb +31 -0
  8. data/lib/test_bench/fixture/controls/fixture.rb +8 -66
  9. data/lib/test_bench/fixture/controls/output.rb +1 -58
  10. data/lib/test_bench/fixture/controls/random.rb +7 -0
  11. data/lib/test_bench/fixture/controls/result.rb +1 -17
  12. data/lib/test_bench/fixture/controls/title.rb +7 -0
  13. data/lib/test_bench/fixture/controls.rb +9 -9
  14. data/lib/test_bench/fixture/evaluate.rb +29 -0
  15. data/lib/test_bench/fixture/fixture.rb +117 -128
  16. data/lib/test_bench/fixture.rb +5 -18
  17. metadata +29 -22
  18. data/lib/test_bench/fixture/assertion_failure.rb +0 -19
  19. data/lib/test_bench/fixture/controls/caller_location.rb +0 -66
  20. data/lib/test_bench/fixture/controls/error/backtrace.rb +0 -31
  21. data/lib/test_bench/fixture/controls/error.rb +0 -52
  22. data/lib/test_bench/fixture/controls/output/log.rb +0 -45
  23. data/lib/test_bench/fixture/controls/test_file.rb +0 -77
  24. data/lib/test_bench/fixture/error_policy.rb +0 -75
  25. data/lib/test_bench/fixture/output/capture.rb +0 -131
  26. data/lib/test_bench/fixture/output/log.rb +0 -142
  27. data/lib/test_bench/fixture/output/multiple.rb +0 -42
  28. data/lib/test_bench/fixture/output/null.rb +0 -9
  29. data/lib/test_bench/fixture/output/substitute/scope.rb +0 -26
  30. data/lib/test_bench/fixture/output/substitute.rb +0 -114
  31. data/lib/test_bench/fixture/output.rb +0 -57
  32. data/lib/test_bench/fixture/session/substitute.rb +0 -127
  33. data/lib/test_bench/fixture/session.rb +0 -250
@@ -1,198 +1,187 @@
1
1
  module TestBench
2
2
  module Fixture
3
- Error = Class.new(RuntimeError)
4
-
5
- def self.build(cls, *args, session: nil, output: nil, error_policy: nil, factory_method: nil, **kwargs, &block)
6
- assure_fixture(cls)
7
-
8
- factory_method = factory_method(cls)
9
-
10
- if kwargs.empty?
11
- instance = factory_method.(*args, &block)
12
- else
13
- instance = factory_method.(*args, **kwargs, &block)
14
- end
15
-
16
- Session.configure(instance, session: session, output: output, error_policy: error_policy)
17
-
18
- instance
19
- end
20
-
21
- def self.assure_fixture(cls)
22
- unless cls.included_modules.include?(self)
23
- raise Error, "Not a fixture class (Class: #{cls.inspect})"
24
- end
25
- end
26
-
27
- def self.factory_method(cls)
28
- if cls.respond_to?(:build)
29
- cls.method(:build)
30
- elsif cls.respond_to?(:new)
31
- cls.method(:new)
32
- else
33
- raise Error, "Must be given a class (Argument: #{cls.inspect})"
34
- end
35
- end
36
-
37
- def self.call(cls, *args, **kwargs, &block)
38
- factory_method = factory_method(cls)
39
-
40
- if factory_method.name == :new
41
- last_parameter_type, _ = cls.instance_method(:initialize).parameters.last
42
- else
43
- last_parameter_type, _ = factory_method.parameters.last
44
- end
45
-
46
- if last_parameter_type == :block
47
- instance = build(cls, *args, **kwargs, &block)
48
- block = nil
49
- else
50
- instance = build(cls, *args, **kwargs)
51
- end
52
-
53
- instance.test_session.fixture(instance, &block)
54
-
55
- instance
56
- end
3
+ include TestBench::Session::Events
57
4
 
58
5
  def test_session
59
6
  @test_session ||= Session::Substitute.build
60
7
  end
61
8
  attr_writer :test_session
62
- alias_method :session, :test_session
63
- alias_method :session=, :test_session=
64
9
 
65
- def inspect
66
- original_test_session = test_session
67
-
68
- self.test_session = "(not inspected; class is #{original_test_session.class})"
69
-
70
- begin
71
- super
72
- ensure
73
- self.test_session = original_test_session
74
- end
10
+ def fixture_passed?
11
+ test_session.passed?
75
12
  end
13
+ alias :passed? :fixture_passed?
76
14
 
77
- def comment(text, *additional_lines)
78
- test_session.comment(text)
79
-
80
- additional_lines.each do |text|
81
- test_session.comment(text)
82
- end
15
+ def comment(...)
16
+ Fixture.comment(test_session.telemetry, Commented, ...)
83
17
  end
84
18
 
85
- def detail(text, *additional_lines)
86
- test_session.detail(text)
19
+ def detail(...)
20
+ Fixture.comment(test_session.telemetry, Detailed, ...)
21
+ end
87
22
 
88
- additional_lines.each do |text|
89
- test_session.detail(text)
23
+ def assert(result)
24
+ if not [true, false, nil].include?(result)
25
+ raise TypeError, "Value #{result.inspect} isn't a boolean"
90
26
  end
91
- end
92
27
 
93
- def assert(value, caller_location: nil)
94
- caller_location ||= caller[0]
28
+ result = false if result.nil?
95
29
 
96
- test_session.assert(value, caller_location: caller_location)
30
+ test_session.assert(result)
97
31
  end
98
32
 
99
- def refute(value, caller_location: nil)
100
- caller_location ||= caller[0]
33
+ def refute(result)
34
+ if not [true, false, nil].include?(result)
35
+ raise TypeError, "Value #{result.inspect} isn't a boolean"
36
+ end
101
37
 
102
- test_session.assert(!value, caller_location: caller_location)
38
+ negated_result = !result
39
+
40
+ test_session.assert(negated_result)
103
41
  end
104
42
 
105
- def assert_raises(error_class=nil, message=nil, strict: nil, caller_location: nil, &block)
106
- if error_class.nil?
43
+ def assert_raises(exception_class=nil, message=nil, strict: nil, &block)
44
+ if exception_class.nil?
107
45
  strict ||= false
108
- error_class = StandardError
46
+ exception_class = StandardError
109
47
  else
110
48
  strict = true if strict.nil?
111
49
  end
112
50
 
113
- caller_location ||= caller[0]
114
-
115
- detail "Expected Error: #{error_class}#{' (strict)' if strict}"
116
- detail "Expected Message: #{message.inspect}" unless message.nil?
51
+ detail "Expected exception: #{exception_class}#{' (strict)' if strict}"
52
+ if not message.nil?
53
+ detail "Expected message: #{message.inspect}"
54
+ end
117
55
 
118
56
  block.()
119
57
 
120
- detail "(No error was raised)"
58
+ detail "(No exception was raised)"
121
59
 
122
- rescue error_class => error
60
+ rescue exception_class => exception
123
61
 
124
- detail "Raised error: #{error.inspect}#{" (subclass of #{error_class})" if error.class < error_class}"
62
+ detail "Raised exception: #{exception.inspect}#{" (subclass of #{exception_class})" if exception.class < exception_class}"
125
63
 
126
- if strict && !error.instance_of?(error_class)
127
- raise error
64
+ if strict && !exception.instance_of?(exception_class)
65
+ raise exception
128
66
  end
129
67
 
130
68
  if message.nil?
131
69
  result = true
132
70
  else
133
- result = error.message == message
71
+ result = exception.message == message
134
72
  end
135
73
 
136
- assert(result, caller_location: caller_location)
137
-
74
+ assert(result)
138
75
  else
139
- assert(false, caller_location: caller_location)
76
+ assert(false)
140
77
  end
141
78
 
142
- def refute_raises(error_class=nil, strict: nil, caller_location: nil, &block)
143
- if error_class.nil?
79
+ def refute_raises(exception_class=nil, strict: nil, &block)
80
+ if exception_class.nil?
144
81
  strict ||= false
145
- error_class = StandardError
82
+ exception_class = StandardError
146
83
  else
147
84
  strict = true if strict.nil?
148
85
  end
149
86
 
150
- caller_location ||= caller[0]
151
-
152
- detail "Prohibited Error: #{error_class}#{' (strict)' if strict}"
87
+ detail "Prohibited exception: #{exception_class}#{' (strict)' if strict}"
153
88
 
154
89
  block.()
155
90
 
156
- detail "(No error was raised)"
157
-
158
- result = true
91
+ detail "(No exception was raised)"
159
92
 
160
- rescue error_class => error
93
+ rescue exception_class => exception
161
94
 
162
- detail "Raised Error: #{error.inspect}"
95
+ detail "Raised exception: #{exception.inspect}#{" (subclass of #{exception_class})" if exception.class < exception_class}"
163
96
 
164
- if strict && !error.instance_of?(error_class)
165
- raise error
97
+ if strict && !exception.instance_of?(exception_class)
98
+ raise exception
166
99
  end
167
100
 
168
- result = false
101
+ assert(false)
102
+ else
103
+ assert(true)
104
+ end
105
+
106
+ def context(title=nil, &block)
107
+ test_session.context(title, &block)
108
+ end
169
109
 
170
- ensure
171
- unless result.nil?
172
- assert(result, caller_location: caller_location)
173
- end
110
+ def context!(title=nil, &block)
111
+ test_session.context!(title, &block)
112
+ end
113
+
114
+ def test(title=nil, &block)
115
+ test_session.test(title, &block)
116
+ end
117
+
118
+ def test!(title=nil, &block)
119
+ test_session.test!(title, &block)
174
120
  end
175
121
 
176
- def context(text=nil, &block)
177
- test_session.context(text, &block)
122
+ def fail(message=nil)
123
+ test_session.fail(message)
178
124
  end
179
125
 
180
- def test(text=nil, &block)
181
- test_session.test(text, &block)
126
+ def fixture(fixture_class_or_object, *, **, &)
127
+ session = self.test_session
128
+
129
+ Fixture.(fixture_class_or_object, *, session:, **, &)
182
130
  end
183
131
 
184
- def test!(text=nil, &block)
185
- result = test(text, &block)
132
+ def self.comment(telemetry, event_class, text, *additional_texts, heading: nil, quote: nil)
133
+ texts = [text, *additional_texts]
186
134
 
187
- unless result
188
- raise Session::Abort.new, "Context aborted"
135
+ if quote.nil?
136
+ quote = texts.last.end_with?("\n")
189
137
  end
190
138
 
191
- result
139
+ if quote
140
+ if heading.nil?
141
+ heading = !text.end_with?("\n")
142
+ end
143
+ end
144
+
145
+ if heading
146
+ heading = texts.shift
147
+ else
148
+ heading = nil
149
+ end
150
+
151
+ if quote
152
+ text = texts.join
153
+ else
154
+ text = texts.first
155
+ end
156
+
157
+ event = event_class.new
158
+ event.text = text
159
+ event.quote = quote
160
+ event.heading = heading
161
+
162
+ telemetry.record(event)
163
+
164
+ if not quote
165
+ texts[1..-1].each do |text|
166
+ comment(telemetry, event_class, text, heading: false, quote: false)
167
+ end
168
+ end
169
+ end
170
+
171
+ def self.output(fixture, styling: nil)
172
+ session = fixture.test_session
173
+
174
+ TestBench::Session::Output::Get.(session, styling:)
192
175
  end
193
176
 
194
- def fixture(cls, *args, **kwargs, &block)
195
- Fixture.(cls, *args, session: test_session, **kwargs, &block)
177
+ def self.call(fixture_class_or_object, ...)
178
+ if fixture_class_or_object.instance_of?(Class)
179
+ fixture_class = fixture_class_or_object
180
+ Actuate::Class.(fixture_class, ...)
181
+ else
182
+ object = fixture_class_or_object
183
+ Actuate::Object.(object, ...)
184
+ end
196
185
  end
197
186
  end
198
187
  end
@@ -1,21 +1,8 @@
1
- unless RUBY_ENGINE == 'mruby'
2
- require 'logger'
3
- require 'stringio'
4
- end
1
+ require 'test_bench/session'
5
2
 
6
- require 'test_bench/fixture/assertion_failure'
7
-
8
- require 'test_bench/fixture/output'
9
- require 'test_bench/fixture/output/null'
10
- require 'test_bench/fixture/output/log'
11
- require 'test_bench/fixture/output/capture'
12
- require 'test_bench/fixture/output/substitute'
13
- require 'test_bench/fixture/output/substitute/scope'
14
- require 'test_bench/fixture/output/multiple'
15
-
16
- require 'test_bench/fixture/error_policy'
17
-
18
- require 'test_bench/fixture/session'
19
- require 'test_bench/fixture/session/substitute'
3
+ require 'test_bench/fixture/actuate/class'
4
+ require 'test_bench/fixture/actuate/object'
20
5
 
21
6
  require 'test_bench/fixture/fixture'
7
+
8
+ require 'test_bench/fixture/evaluate'
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: test_bench-fixture
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0.2
4
+ version: 2.1.0.0.pre1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Ladd
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-09 00:00:00.000000000 Z
11
+ date: 2023-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: test_bench-session
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: test_bench-bootstrap
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -31,27 +45,20 @@ extensions: []
31
45
  extra_rdoc_files: []
32
46
  files:
33
47
  - lib/test_bench/fixture.rb
34
- - lib/test_bench/fixture/assertion_failure.rb
48
+ - lib/test_bench/fixture/actuate/class.rb
49
+ - lib/test_bench/fixture/actuate/object.rb
35
50
  - lib/test_bench/fixture/controls.rb
36
- - lib/test_bench/fixture/controls/caller_location.rb
37
- - lib/test_bench/fixture/controls/error.rb
38
- - lib/test_bench/fixture/controls/error/backtrace.rb
51
+ - lib/test_bench/fixture/controls/exception.rb
39
52
  - lib/test_bench/fixture/controls/fixture.rb
53
+ - lib/test_bench/fixture/controls/fixture/class.rb
54
+ - lib/test_bench/fixture/controls/fixture/object.rb
55
+ - lib/test_bench/fixture/controls/fixture/object/modules.rb
40
56
  - lib/test_bench/fixture/controls/output.rb
41
- - lib/test_bench/fixture/controls/output/log.rb
57
+ - lib/test_bench/fixture/controls/random.rb
42
58
  - lib/test_bench/fixture/controls/result.rb
43
- - lib/test_bench/fixture/controls/test_file.rb
44
- - lib/test_bench/fixture/error_policy.rb
59
+ - lib/test_bench/fixture/controls/title.rb
60
+ - lib/test_bench/fixture/evaluate.rb
45
61
  - lib/test_bench/fixture/fixture.rb
46
- - lib/test_bench/fixture/output.rb
47
- - lib/test_bench/fixture/output/capture.rb
48
- - lib/test_bench/fixture/output/log.rb
49
- - lib/test_bench/fixture/output/multiple.rb
50
- - lib/test_bench/fixture/output/null.rb
51
- - lib/test_bench/fixture/output/substitute.rb
52
- - lib/test_bench/fixture/output/substitute/scope.rb
53
- - lib/test_bench/fixture/session.rb
54
- - lib/test_bench/fixture/session/substitute.rb
55
62
  homepage: https://github.com/test-bench/test-bench-fixture
56
63
  licenses:
57
64
  - MIT
@@ -67,12 +74,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
67
74
  version: '0'
68
75
  required_rubygems_version: !ruby/object:Gem::Requirement
69
76
  requirements:
70
- - - ">="
77
+ - - ">"
71
78
  - !ruby/object:Gem::Version
72
- version: '0'
79
+ version: 1.3.1
73
80
  requirements: []
74
- rubygems_version: 3.3.4
81
+ rubygems_version: 3.4.10
75
82
  signing_key:
76
83
  specification_version: 4
77
- summary: Test object framework for Ruby and MRuby
84
+ summary: ruby
78
85
  test_files: []
@@ -1,19 +0,0 @@
1
- module TestBench
2
- module Fixture
3
- class AssertionFailure < RuntimeError
4
- def self.build(caller_location=nil)
5
- caller_location ||= caller[0]
6
-
7
- backtrace = [caller_location.to_s]
8
-
9
- instance = new(message)
10
- instance.set_backtrace(backtrace)
11
- instance
12
- end
13
-
14
- def self.message
15
- 'Assertion failed'
16
- end
17
- end
18
- end
19
- end
@@ -1,66 +0,0 @@
1
- module TestBench
2
- module Fixture
3
- module Controls
4
- module CallerLocation
5
- def self.example(file: nil, line_number: nil, label: nil)
6
- file ||= self.file
7
- line_number ||= self.line_number
8
- label ||= self.label
9
-
10
- "#{file}:#{line_number}:in `#{label}'"
11
- end
12
-
13
- def self.file
14
- 'lib/some_dir/some_file.rb'
15
- end
16
-
17
- def self.line_number
18
- 11
19
- end
20
-
21
- def self.label
22
- 'some_method'
23
- end
24
-
25
- module Alternate
26
- def self.example(line_number: nil)
27
- line_number ||= self.line_number
28
-
29
- CallerLocation.example(file: file, line_number: line_number)
30
- end
31
-
32
- def self.file
33
- 'lib/other_dir/other_file.rb'
34
- end
35
-
36
- def self.line_number
37
- 111
38
- end
39
- end
40
-
41
- Implementation = self
42
-
43
- module Test
44
- def self.example(file: nil, line_number: nil)
45
- file ||= self.file
46
- line_number ||= self.line_number
47
-
48
- TOPLEVEL_BINDING.receiver.instance_eval 'proc { caller[0] }.call', file, line_number
49
- end
50
-
51
- def self.file
52
- 'test/some_dir/some_test_file.rb'
53
- end
54
-
55
- def self.line_number
56
- 22
57
- end
58
-
59
- def self.label
60
- 'block in <main>'
61
- end
62
- end
63
- end
64
- end
65
- end
66
- end
@@ -1,31 +0,0 @@
1
- module TestBench
2
- module Fixture
3
- module Controls
4
- module Error
5
- module Backtrace
6
- def self.example(depth: nil)
7
- depth ||= self.depth
8
-
9
- controls = [
10
- CallerLocation,
11
- CallerLocation::Alternate,
12
- CallerLocation::Alternate
13
- ].cycle.first(depth)
14
-
15
- controls.map.with_index do |control, index|
16
- line_number = index + 1
17
-
18
- caller_location = control.example(line_number: line_number)
19
-
20
- caller_location.to_s
21
- end
22
- end
23
-
24
- def self.depth
25
- 3
26
- end
27
- end
28
- end
29
- end
30
- end
31
- end
@@ -1,52 +0,0 @@
1
- module TestBench
2
- module Fixture
3
- module Controls
4
- module Error
5
- def self.example(message=nil, backtrace: nil, backtrace_depth: nil, cause: nil, cls: nil)
6
- message ||= self.message
7
- cls ||= Example
8
-
9
- if backtrace == :none
10
- backtrace = []
11
- else
12
- backtrace ||= Backtrace.example(depth: backtrace_depth)
13
- end
14
-
15
- if cause == true
16
- cause = Cause.example
17
- end
18
-
19
- error = cls.new(message)
20
- error.set_backtrace(backtrace)
21
-
22
- if cause
23
- begin
24
- begin
25
- raise cause
26
- rescue cause.class
27
- raise error
28
- end
29
- rescue cls
30
- end
31
- end
32
-
33
- error
34
- end
35
-
36
- def self.message
37
- 'Some error'
38
- end
39
-
40
- Example = Class.new(RuntimeError)
41
-
42
- module Cause
43
- def self.example
44
- Error.example("Some cause", cls: Example)
45
- end
46
-
47
- Example = Class.new(RuntimeError)
48
- end
49
- end
50
- end
51
- end
52
- end
@@ -1,45 +0,0 @@
1
- module TestBench
2
- module Fixture
3
- module Controls
4
- module Output
5
- module Log
6
- module Level
7
- def self.example
8
- fatal
9
- end
10
-
11
- def self.unknown
12
- :unknown
13
- end
14
-
15
- def self.fatal
16
- :fatal
17
- end
18
-
19
- def self.error
20
- :error
21
- end
22
-
23
- def self.warning
24
- :warning
25
- end
26
-
27
- def self.info
28
- :info
29
- end
30
-
31
- def self.debug
32
- :debug
33
- end
34
-
35
- module Invalid
36
- def self.example
37
- :not_a_log_level
38
- end
39
- end
40
- end
41
- end
42
- end
43
- end
44
- end
45
- end