test_bench-fixture 1.2.2.0 → 1.3.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 92b0873c28e3a281b549ddd3d9247c521aa10156b478871c02222294d5cf3adc
4
- data.tar.gz: ea44fe5f2acd028bf0401975fc77e82e8ff698c657a86009f661d093d8649f6a
3
+ metadata.gz: 439b3f623746bdb26d4d9e5a30ee5abd7283b829e04383c4240aa175ec4b07e7
4
+ data.tar.gz: 73abed890d2945a1854c54ac338b46ec846d8ba5b8c5bdd70d2f7f1a54110680
5
5
  SHA512:
6
- metadata.gz: d1ce9862fcf53f463caf27576548393cae6691bc51632a990727dada4c3e7258b5692671f6765db71b015771f06bfe6ff5bf6c73089fe555bfef8d737921d3b5
7
- data.tar.gz: fda6888b01d652073e9d739078d00677d9abc561607864eba80cc9bbd70a438e66bcf15918af48b8c5a50e40324e110b183ac48c760d5f1978cac8dbc53a317a
6
+ metadata.gz: cd516904ef461a2fe872abdef28b9f5ced3cd8e8e68608d59f8e182a2c1a37ef27f36f365e7edbf5f7f1dea9b06a349fde016829648147c5d2f2414647a670a9
7
+ data.tar.gz: 4d07e52f97d8913db429c665d1dffa709174340086cc4827ab3be365ae984198b25d3c7e64112def9c9b961190d44d1fa039f0aa1d41d58bf78d7f584b14cf94
@@ -1,5 +1,7 @@
1
- require 'logger'
2
- require 'stringio'
1
+ unless RUBY_ENGINE == 'mruby'
2
+ require 'logger'
3
+ require 'stringio'
4
+ end
3
5
 
4
6
  require 'test_bench/fixture/assertion_failure'
5
7
 
@@ -2,7 +2,7 @@ module TestBench
2
2
  module Fixture
3
3
  class AssertionFailure < RuntimeError
4
4
  def self.build(caller_location=nil)
5
- caller_location ||= caller_locations.first
5
+ caller_location ||= caller[0]
6
6
 
7
7
  backtrace = [caller_location.to_s]
8
8
 
@@ -1,4 +1,6 @@
1
- require 'tempfile'
1
+ unless RUBY_ENGINE == 'mruby'
2
+ require 'tempfile'
3
+ end
2
4
 
3
5
  require 'test_bench/fixture/controls/caller_location'
4
6
  require 'test_bench/fixture/controls/error/backtrace'
@@ -2,18 +2,12 @@ module TestBench
2
2
  module Fixture
3
3
  module Controls
4
4
  module CallerLocation
5
- def self.example(file: nil, line_number: nil)
5
+ def self.example(file: nil, line_number: nil, label: nil)
6
6
  file ||= self.file
7
7
  line_number ||= self.line_number
8
+ label ||= self.label
8
9
 
9
- eval(<<~RUBY, TOPLEVEL_BINDING, file, line_number - 2)
10
- some_class = Class.new do
11
- def self.some_method
12
- Thread.current.backtrace_locations[1]
13
- end
14
- end
15
- some_class.some_method
16
- RUBY
10
+ "#{file}:#{line_number}:in `#{label}'"
17
11
  end
18
12
 
19
13
  def self.file
@@ -24,6 +18,10 @@ module TestBench
24
18
  11
25
19
  end
26
20
 
21
+ def self.label
22
+ 'some_method'
23
+ end
24
+
27
25
  module Alternate
28
26
  def self.example(line_number: nil)
29
27
  line_number ||= self.line_number
@@ -38,12 +36,6 @@ module TestBench
38
36
  def self.line_number
39
37
  111
40
38
  end
41
-
42
- module Pattern
43
- def self.example
44
- /other_dir/
45
- end
46
- end
47
39
  end
48
40
 
49
41
  Implementation = self
@@ -53,9 +45,7 @@ module TestBench
53
45
  file ||= self.file
54
46
  line_number ||= self.line_number
55
47
 
56
- eval <<~RUBY, TOPLEVEL_BINDING, file, line_number
57
- proc { Thread.current.backtrace_locations[1] }.call
58
- RUBY
48
+ TOPLEVEL_BINDING.receiver.instance_eval 'proc { caller[0] }.call', file, line_number
59
49
  end
60
50
 
61
51
  def self.file
@@ -65,6 +55,10 @@ module TestBench
65
55
  def self.line_number
66
56
  22
67
57
  end
58
+
59
+ def self.label
60
+ 'block in <main>'
61
+ end
68
62
  end
69
63
  end
70
64
  end
@@ -4,7 +4,8 @@ module TestBench
4
4
  module TestFile
5
5
  def self.example(filename: nil, text: nil, directory: nil)
6
6
  filename ||= self.filename
7
- text ||= text
7
+ text ||= self.text
8
+ directory ||= self.directory
8
9
 
9
10
  basename, extension, _ = filename.partition('.rb')
10
11
 
@@ -29,6 +30,10 @@ module TestBench
29
30
  '# Nothing'
30
31
  end
31
32
 
33
+ def self.directory
34
+ '/tmp'
35
+ end
36
+
32
37
  def self.tempfiles
33
38
  @tempfiles ||= []
34
39
  end
@@ -24,7 +24,7 @@ module TestBench
24
24
  policies.fetch(policy) do
25
25
  *policies, final_policy = self.policies.keys
26
26
 
27
- policy_list = "#{policies.map(&:inspect) * ', '} or #{final_policy.inspect}"
27
+ policy_list = "#{policies.map(&:inspect).join(', ')} or #{final_policy.inspect}"
28
28
 
29
29
  raise PolicyError, "Policy #{policy.inspect} is unknown. It must be one of: #{policy_list}"
30
30
  end
@@ -67,13 +67,13 @@ module TestBench
67
67
  end
68
68
 
69
69
  def assert(value, caller_location: nil)
70
- caller_location ||= caller_locations.first
70
+ caller_location ||= caller[0]
71
71
 
72
72
  test_session.assert(value, caller_location: caller_location)
73
73
  end
74
74
 
75
75
  def refute(value, caller_location: nil)
76
- caller_location ||= caller_locations.first
76
+ caller_location ||= caller[0]
77
77
 
78
78
  test_session.assert(!value, caller_location: caller_location)
79
79
  end
@@ -86,7 +86,7 @@ module TestBench
86
86
  strict = true if strict.nil?
87
87
  end
88
88
 
89
- caller_location ||= caller_locations.first
89
+ caller_location ||= caller[0]
90
90
 
91
91
  detail "Expected Error: #{error_class}#{' (strict)' if strict}"
92
92
  detail "Expected Message: #{message.inspect}" unless message.nil?
@@ -122,7 +122,7 @@ module TestBench
122
122
  strict = true if strict.nil?
123
123
  end
124
124
 
125
- caller_location ||= caller_locations.first
125
+ caller_location ||= caller[0]
126
126
 
127
127
  detail "Prohibited Error: #{error_class}#{' (strict)' if strict}"
128
128
 
@@ -99,13 +99,31 @@ module TestBench
99
99
  def new_record(signal, data)
100
100
  context = current_context.dup
101
101
 
102
- record = Record.new(signal, data, context)
102
+ record = Record.build(signal, data, context)
103
103
  end
104
104
 
105
- Record = Struct.new(:signal, :data, :context) do
105
+ class Record
106
+ attr_accessor :signal
107
+ attr_accessor :data
108
+ attr_accessor :context
109
+
110
+ def self.build(signal, data, context=nil)
111
+ instance = new
112
+ instance.signal = signal
113
+ instance.data = data
114
+ instance.context = context
115
+ instance
116
+ end
117
+
106
118
  def forward(receiver)
107
119
  receiver.public_send(signal, *data)
108
120
  end
121
+
122
+ def ==(record)
123
+ self.signal == record.signal &&
124
+ self.data == record.data &&
125
+ self.context == record.context
126
+ end
109
127
  end
110
128
  end
111
129
  end
@@ -59,7 +59,7 @@ module TestBench
59
59
 
60
60
  def self.assure_level(level)
61
61
  unless level_ordinals.key?(level)
62
- raise Error, "Unknown log level #{level.inspect} (Valid levels: #{levels.map(&:inspect) * ', '})"
62
+ raise Error, "Unknown log level #{level.inspect} (Valid levels: #{levels.map(&:inspect).join(', ')})"
63
63
  end
64
64
  end
65
65
 
@@ -114,7 +114,7 @@ module TestBench
114
114
  end
115
115
 
116
116
  def assert(value, caller_location: nil)
117
- caller_location ||= caller_locations.first
117
+ caller_location ||= caller[0]
118
118
 
119
119
  result = value ? true : false
120
120
 
@@ -135,13 +135,15 @@ module TestBench
135
135
  def load(path)
136
136
  output.enter_file(path)
137
137
 
138
- action = proc { Kernel.load(path) }
138
+ result = false
139
139
 
140
- result = evaluate(action)
140
+ Kernel.load(path)
141
141
 
142
- output.exit_file(path, result)
142
+ result = true
143
143
 
144
- result
144
+ ensure
145
+
146
+ output.exit_file(path, result)
145
147
  end
146
148
 
147
149
  def test(title=nil, &block)
@@ -198,9 +200,10 @@ module TestBench
198
200
  output.start_fixture(fixture)
199
201
 
200
202
  action = proc { actions.each(&:call) }
201
- result = evaluate(action)
202
203
 
203
- output.finish_fixture(fixture, result)
204
+ result = evaluate(action) do |result|
205
+ output.finish_fixture(fixture, result)
206
+ end
204
207
 
205
208
  result
206
209
  end
@@ -214,12 +217,12 @@ module TestBench
214
217
  rescue => error
215
218
  error(error)
216
219
 
217
- ensure
218
- current_exception = $!
220
+ error = nil
219
221
 
222
+ ensure
220
223
  result = error_counter == previous_error_counter
221
224
 
222
- block.(result, current_exception) unless block.nil?
225
+ block.(result, error) unless block.nil?
223
226
  end
224
227
 
225
228
  result
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: test_bench-fixture
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2.0
4
+ version: 1.3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Ladd
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-31 00:00:00.000000000 Z
11
+ date: 2020-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test_bench-bootstrap
@@ -74,5 +74,5 @@ requirements: []
74
74
  rubygems_version: 3.1.4
75
75
  signing_key:
76
76
  specification_version: 4
77
- summary: Test object framework
77
+ summary: Test object framework for Ruby and MRuby
78
78
  test_files: []