test_bench-fixture 1.0.0.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.
- checksums.yaml +7 -0
- data/lib/test_bench/fixture.rb +18 -0
- data/lib/test_bench/fixture/assertion_failure.rb +19 -0
- data/lib/test_bench/fixture/controls.rb +10 -0
- data/lib/test_bench/fixture/controls/caller_location.rb +72 -0
- data/lib/test_bench/fixture/controls/error.rb +47 -0
- data/lib/test_bench/fixture/controls/error/backtrace.rb +31 -0
- data/lib/test_bench/fixture/controls/fixture.rb +85 -0
- data/lib/test_bench/fixture/controls/output.rb +64 -0
- data/lib/test_bench/fixture/controls/result.rb +23 -0
- data/lib/test_bench/fixture/controls/test_file.rb +72 -0
- data/lib/test_bench/fixture/error_policy.rb +75 -0
- data/lib/test_bench/fixture/fixture.rb +149 -0
- data/lib/test_bench/fixture/output.rb +56 -0
- data/lib/test_bench/fixture/output/log.rb +109 -0
- data/lib/test_bench/fixture/output/multiple.rb +42 -0
- data/lib/test_bench/fixture/output/null.rb +9 -0
- data/lib/test_bench/fixture/output/substitute.rb +141 -0
- data/lib/test_bench/fixture/session.rb +246 -0
- data/lib/test_bench/fixture/session/substitute.rb +126 -0
- data/lib/test_bench/fixture/session/substitute/match_tests.rb +131 -0
- metadata +76 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 11a8f07325bd4895d293ada5d0562bfe183c8913ff1f1ed2fb85bf770f37a34f
|
4
|
+
data.tar.gz: 3f547833da8e092eeef33a7605621bdd91ac7af38384097dabaacc6eacd493cf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 897778edd91e443502415d4b638517a77835afa40ab53709affab0efd5418b6bb3ce61f2e78bb51782e288bc99c7cd73e98bde4deb7191121e46872d2bb02c48
|
7
|
+
data.tar.gz: a2041b6063d7cfb1979e49ce84248dc32229bef552448332774e2dd7c450e255ab17be19e0f2ede7f904647537add7e60f8adc0de7f91142499663b1b5141fc4
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'stringio'
|
3
|
+
|
4
|
+
require 'test_bench/fixture/assertion_failure'
|
5
|
+
|
6
|
+
require 'test_bench/fixture/output'
|
7
|
+
require 'test_bench/fixture/output/null'
|
8
|
+
require 'test_bench/fixture/output/log'
|
9
|
+
require 'test_bench/fixture/output/substitute'
|
10
|
+
require 'test_bench/fixture/output/multiple'
|
11
|
+
|
12
|
+
require 'test_bench/fixture/error_policy'
|
13
|
+
|
14
|
+
require 'test_bench/fixture/session'
|
15
|
+
require 'test_bench/fixture/session/substitute'
|
16
|
+
require 'test_bench/fixture/session/substitute/match_tests'
|
17
|
+
|
18
|
+
require 'test_bench/fixture/fixture'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module TestBench
|
2
|
+
module Fixture
|
3
|
+
class AssertionFailure < RuntimeError
|
4
|
+
def self.build(caller_location=nil)
|
5
|
+
caller_location ||= caller_locations.first
|
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
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
|
3
|
+
require 'test_bench/fixture/controls/caller_location'
|
4
|
+
require 'test_bench/fixture/controls/error/backtrace'
|
5
|
+
require 'test_bench/fixture/controls/error'
|
6
|
+
require 'test_bench/fixture/controls/fixture'
|
7
|
+
require 'test_bench/fixture/controls/result'
|
8
|
+
require 'test_bench/fixture/controls/test_file'
|
9
|
+
|
10
|
+
require 'test_bench/fixture/controls/output'
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module TestBench
|
2
|
+
module Fixture
|
3
|
+
module Controls
|
4
|
+
module CallerLocation
|
5
|
+
def self.example(file: nil, line_number: nil)
|
6
|
+
file ||= self.file
|
7
|
+
line_number ||= self.line_number
|
8
|
+
|
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
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.file
|
20
|
+
'lib/some_dir/some_file.rb'
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.line_number
|
24
|
+
11
|
25
|
+
end
|
26
|
+
|
27
|
+
module Alternate
|
28
|
+
def self.example(line_number: nil)
|
29
|
+
line_number ||= self.line_number
|
30
|
+
|
31
|
+
CallerLocation.example(file: file, line_number: line_number)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.file
|
35
|
+
'lib/other_dir/other_file.rb'
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.line_number
|
39
|
+
111
|
40
|
+
end
|
41
|
+
|
42
|
+
module Pattern
|
43
|
+
def self.example
|
44
|
+
/other_dir/
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
Implementation = self
|
50
|
+
|
51
|
+
module Test
|
52
|
+
def self.example(file: nil, line_number: nil)
|
53
|
+
file ||= self.file
|
54
|
+
line_number ||= self.line_number
|
55
|
+
|
56
|
+
eval <<~RUBY, TOPLEVEL_BINDING, file, line_number
|
57
|
+
proc { Thread.current.backtrace_locations[1] }.call
|
58
|
+
RUBY
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.file
|
62
|
+
'test/some_dir/some_test_file.rb'
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.line_number
|
66
|
+
22
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,47 @@
|
|
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
|
+
backtrace ||= Backtrace.example(depth: backtrace_depth)
|
9
|
+
|
10
|
+
if cause == true
|
11
|
+
cause = Cause.example
|
12
|
+
end
|
13
|
+
|
14
|
+
error = cls.new(message)
|
15
|
+
error.set_backtrace(backtrace)
|
16
|
+
|
17
|
+
if cause
|
18
|
+
begin
|
19
|
+
begin
|
20
|
+
raise cause
|
21
|
+
rescue cause.class
|
22
|
+
raise error
|
23
|
+
end
|
24
|
+
rescue cls
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
error
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.message
|
32
|
+
'Some error'
|
33
|
+
end
|
34
|
+
|
35
|
+
Example = Class.new(RuntimeError)
|
36
|
+
|
37
|
+
module Cause
|
38
|
+
def self.example
|
39
|
+
Error.example("Some cause", cls: Example)
|
40
|
+
end
|
41
|
+
|
42
|
+
Example = Class.new(RuntimeError)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,31 @@
|
|
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
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module TestBench
|
2
|
+
module Fixture
|
3
|
+
module Controls
|
4
|
+
module Fixture
|
5
|
+
def self.example
|
6
|
+
Example.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.example_class(&block)
|
10
|
+
Class.new do
|
11
|
+
include TestBench::Fixture
|
12
|
+
|
13
|
+
class_exec(&block) unless block.nil?
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
module InstanceActuator
|
18
|
+
def self.example
|
19
|
+
Example.new
|
20
|
+
end
|
21
|
+
|
22
|
+
Example = Fixture.example_class do
|
23
|
+
attr_accessor :actuated
|
24
|
+
alias_method :actuated?, :actuated
|
25
|
+
|
26
|
+
def call
|
27
|
+
self.actuated = true
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
module Non
|
32
|
+
def self.example
|
33
|
+
Example.new
|
34
|
+
end
|
35
|
+
|
36
|
+
Example = Fixture.example_class
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
module FactoryMethod
|
41
|
+
def self.example
|
42
|
+
Example.build
|
43
|
+
end
|
44
|
+
|
45
|
+
Example = Fixture.example_class do
|
46
|
+
attr_accessor :build_method_called
|
47
|
+
alias_method :build_method_called?, :build_method_called
|
48
|
+
|
49
|
+
def self.build
|
50
|
+
instance = new
|
51
|
+
instance.build_method_called = true
|
52
|
+
instance
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
module ConstructorArguments
|
58
|
+
Example = Fixture.example_class do
|
59
|
+
include Fixture
|
60
|
+
|
61
|
+
attr_reader :arg1, :arg2, :arg3, :arg4, :blk
|
62
|
+
|
63
|
+
def initialize(arg1, arg2=nil, arg3:, arg4: nil, &blk)
|
64
|
+
@arg1, @arg2, @arg3, @arg4, @blk = arg1, arg2, arg3, arg4, blk
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
module FactoryMethod
|
69
|
+
Example = Class.new(Example) do
|
70
|
+
def initialize(arg1, arg2, arg3, arg4, blk)
|
71
|
+
@arg1, @arg2, @arg3, @arg4, @blk = arg1, arg2, arg3, arg4, blk
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.build(arg1, arg2=nil, arg3:, arg4: nil, &blk)
|
75
|
+
new(arg1, arg2, arg3, arg4, blk)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
Example = InstanceActuator::Example
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module TestBench
|
2
|
+
module Fixture
|
3
|
+
module Controls
|
4
|
+
module Output
|
5
|
+
def self.example
|
6
|
+
Example.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.example_class(&block)
|
10
|
+
Class.new do
|
11
|
+
include TestBench::Fixture::Output
|
12
|
+
|
13
|
+
class_exec(&block) unless block.nil?
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
Example = example_class
|
18
|
+
|
19
|
+
module Exercise
|
20
|
+
def self.call(output=nil, &block)
|
21
|
+
output ||= Output.example
|
22
|
+
|
23
|
+
each_method do |method_name, args|
|
24
|
+
output.public_send(method_name, *args)
|
25
|
+
|
26
|
+
block.(method_name, args) unless block.nil?
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.each_method(&block)
|
31
|
+
result = Controls::Result.example
|
32
|
+
path = Controls::TestFile.path
|
33
|
+
fixture = Controls::Fixture.example
|
34
|
+
caller_location = Controls::CallerLocation.example
|
35
|
+
error = Controls::Error.example
|
36
|
+
comment_text = 'Some comment'
|
37
|
+
test_title = 'Some test'
|
38
|
+
context_title = 'Some Context'
|
39
|
+
|
40
|
+
{
|
41
|
+
:start => [],
|
42
|
+
:finish => [result],
|
43
|
+
:enter_file => [path],
|
44
|
+
:exit_file => [path, result],
|
45
|
+
:start_fixture => [fixture],
|
46
|
+
:finish_fixture => [fixture, result],
|
47
|
+
:assert => [result, caller_location],
|
48
|
+
:enter_assert_block => [caller_location],
|
49
|
+
:exit_assert_block => [caller_location, result],
|
50
|
+
:comment => [comment_text],
|
51
|
+
:error => [error],
|
52
|
+
:start_test => [test_title],
|
53
|
+
:finish_test => [test_title, result],
|
54
|
+
:skip_test => [test_title],
|
55
|
+
:enter_context => [context_title],
|
56
|
+
:exit_context => [context_title, result],
|
57
|
+
:skip_context => [context_title]
|
58
|
+
}.each(&block)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module TestBench
|
2
|
+
module Fixture
|
3
|
+
module Controls
|
4
|
+
module Result
|
5
|
+
def self.example
|
6
|
+
Pass.example
|
7
|
+
end
|
8
|
+
|
9
|
+
module Pass
|
10
|
+
def self.example
|
11
|
+
true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
module Failure
|
16
|
+
def self.example
|
17
|
+
false
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module TestBench
|
2
|
+
module Fixture
|
3
|
+
module Controls
|
4
|
+
module TestFile
|
5
|
+
def self.example(filename: nil, text: nil, directory: nil)
|
6
|
+
filename ||= self.filename
|
7
|
+
text ||= text
|
8
|
+
|
9
|
+
basename, extension, _ = filename.partition('.rb')
|
10
|
+
|
11
|
+
file = Tempfile.new([basename, extension], directory)
|
12
|
+
file.write(text)
|
13
|
+
file.close
|
14
|
+
|
15
|
+
tempfiles << file
|
16
|
+
|
17
|
+
file.path
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.filename
|
21
|
+
'some_test_file.rb'
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.path
|
25
|
+
"test/automated/#{filename}"
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.text
|
29
|
+
'# Nothing'
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.tempfiles
|
33
|
+
@tempfiles ||= []
|
34
|
+
end
|
35
|
+
|
36
|
+
module Alternate
|
37
|
+
def self.example
|
38
|
+
TestFile.example(filename: filename)
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.filename
|
42
|
+
'other_test_file.rb'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
module Pass
|
47
|
+
def self.example(directory: nil)
|
48
|
+
TestFile.example(filename: filename, directory: directory)
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.filename
|
52
|
+
'some_passing_test.rb'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
module Failure
|
57
|
+
def self.example(directory: nil)
|
58
|
+
TestFile.example(text: text, filename: filename, directory: directory)
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.filename
|
62
|
+
'some_failing_test.rb'
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.text
|
66
|
+
"raise #{Error.name}.example"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|