test_bench-fixture 1.2.2.2 → 1.3.1.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: 13a777ff52df4352c49326e6b394828cd64eed0abfdf54a0a677bff3f3958737
4
- data.tar.gz: ccaa7603572eec663dcf2638b5345af7c245ed0aaf137cac124a24e800775910
3
+ metadata.gz: 1d3be2a7cebd18fa06326859f2169a44e6a8974af8c32033669bbd95aacc827b
4
+ data.tar.gz: 36784decf899b9f0432da060ce1133d4e426a45830ce6adaf92c7c82e405f4d2
5
5
  SHA512:
6
- metadata.gz: 4694182ab91a9e75de0f6c69c59bd027842989f075bb0787b15be6e2b4a092d4405943e3c91e1b7f242d1575132f9e3a268544809c201f16f817230d266aacee
7
- data.tar.gz: edc04eee7d348c8e2ea6216200e17eea95c6beee183ce45346542452bbce7f8da6a8dd06d87a4f3213825f7c44694fd43b5469ccdb698c141fd94ae1e11e9612
6
+ metadata.gz: a9d28986ecc5bd4c76efd955b7dcc6923289dbe8430fa849ba20e5340805dead1f0a1f3ed7813dd403041fbf3decb2bd2dcd27d72e195a3690cdf84d4abf4eed
7
+ data.tar.gz: 8d52b899330892b3e021ce3c275dc51573ea6c02995c704bab40d5698da21a5e934ab42e1ea81afdeb14b213dd19e295e9061901a2d2201173050d1c6b1679be
@@ -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
@@ -37,7 +37,11 @@ module TestBench
37
37
  def self.call(cls, *args, **kwargs, &block)
38
38
  factory_method = factory_method(cls)
39
39
 
40
- last_parameter_type, _ = factory_method.parameters.last
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
41
45
 
42
46
  if last_parameter_type == :block
43
47
  instance = build(cls, *args, **kwargs, &block)
@@ -58,22 +62,30 @@ module TestBench
58
62
  alias_method :session, :test_session
59
63
  alias_method :session=, :test_session=
60
64
 
61
- def comment(text)
65
+ def comment(text, *additional_lines)
62
66
  test_session.comment(text)
67
+
68
+ additional_lines.each do |text|
69
+ test_session.comment(text)
70
+ end
63
71
  end
64
72
 
65
- def detail(text)
73
+ def detail(text, *additional_lines)
66
74
  test_session.detail(text)
75
+
76
+ additional_lines.each do |text|
77
+ test_session.detail(text)
78
+ end
67
79
  end
68
80
 
69
81
  def assert(value, caller_location: nil)
70
- caller_location ||= caller_locations.first
82
+ caller_location ||= caller[0]
71
83
 
72
84
  test_session.assert(value, caller_location: caller_location)
73
85
  end
74
86
 
75
87
  def refute(value, caller_location: nil)
76
- caller_location ||= caller_locations.first
88
+ caller_location ||= caller[0]
77
89
 
78
90
  test_session.assert(!value, caller_location: caller_location)
79
91
  end
@@ -86,7 +98,7 @@ module TestBench
86
98
  strict = true if strict.nil?
87
99
  end
88
100
 
89
- caller_location ||= caller_locations.first
101
+ caller_location ||= caller[0]
90
102
 
91
103
  detail "Expected Error: #{error_class}#{' (strict)' if strict}"
92
104
  detail "Expected Message: #{message.inspect}" unless message.nil?
@@ -122,7 +134,7 @@ module TestBench
122
134
  strict = true if strict.nil?
123
135
  end
124
136
 
125
- caller_location ||= caller_locations.first
137
+ caller_location ||= caller[0]
126
138
 
127
139
  detail "Prohibited Error: #{error_class}#{' (strict)' if strict}"
128
140
 
@@ -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
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.2
4
+ version: 1.3.1.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-08-08 00:00:00.000000000 Z
11
+ date: 2020-09-14 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: []