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,77 +0,0 @@
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 ||= self.text
8
- directory ||= self.directory
9
-
10
- basename, extension, _ = filename.partition('.rb')
11
-
12
- file = Tempfile.new([basename, extension], directory)
13
- file.write(text)
14
- file.close
15
-
16
- tempfiles << file
17
-
18
- file.path
19
- end
20
-
21
- def self.filename
22
- 'some_test_file.rb'
23
- end
24
-
25
- def self.path
26
- "test/automated/#{filename}"
27
- end
28
-
29
- def self.text
30
- '# Nothing'
31
- end
32
-
33
- def self.directory
34
- '/tmp'
35
- end
36
-
37
- def self.tempfiles
38
- @tempfiles ||= []
39
- end
40
-
41
- module Alternate
42
- def self.example
43
- TestFile.example(filename: filename)
44
- end
45
-
46
- def self.filename
47
- 'other_test_file.rb'
48
- end
49
- end
50
-
51
- module Pass
52
- def self.example(directory: nil)
53
- TestFile.example(filename: filename, directory: directory)
54
- end
55
-
56
- def self.filename
57
- 'some_passing_test.rb'
58
- end
59
- end
60
-
61
- module Failure
62
- def self.example(directory: nil)
63
- TestFile.example(text: text, filename: filename, directory: directory)
64
- end
65
-
66
- def self.filename
67
- 'some_failing_test.rb'
68
- end
69
-
70
- def self.text
71
- "raise #{Error.name}.example"
72
- end
73
- end
74
- end
75
- end
76
- end
77
- end
@@ -1,75 +0,0 @@
1
- module TestBench
2
- module Fixture
3
- module ErrorPolicy
4
- def self.configure(receiver, policy: nil, attr_name: nil)
5
- attr_name ||= :error_policy
6
-
7
- instance = Build.(policy)
8
- receiver.public_send(:"#{attr_name}=", instance)
9
- instance
10
- end
11
-
12
- module Build
13
- PolicyError = Class.new(RuntimeError)
14
-
15
- def self.call(policy=nil)
16
- cls = policy_class(policy)
17
-
18
- cls.new
19
- end
20
-
21
- def self.policy_class(policy=nil)
22
- policy ||= Defaults.policy
23
-
24
- policies.fetch(policy) do
25
- *policies, final_policy = self.policies.keys
26
-
27
- policy_list = "#{policies.map(&:inspect).join(', ')} or #{final_policy.inspect}"
28
-
29
- raise PolicyError, "Policy #{policy.inspect} is unknown. It must be one of: #{policy_list}"
30
- end
31
- end
32
-
33
- def self.policies
34
- {
35
- :abort => Abort,
36
- :raise => Raise,
37
- :rescue => Rescue,
38
- :rescue_assert => RescueAssert
39
- }
40
- end
41
-
42
- module Defaults
43
- def self.policy
44
- :rescue_assert
45
- end
46
- end
47
- end
48
-
49
- class Abort
50
- def call(error)
51
- abort "TestBench is aborting (#{self.class})"
52
- end
53
- end
54
-
55
- class Raise
56
- def call(error)
57
- raise error
58
- end
59
- end
60
-
61
- class Rescue
62
- def call(error)
63
- end
64
- end
65
-
66
- class RescueAssert
67
- def call(error)
68
- unless error.instance_of?(AssertionFailure)
69
- raise error
70
- end
71
- end
72
- end
73
- end
74
- end
75
- end
@@ -1,131 +0,0 @@
1
- module TestBench
2
- module Fixture
3
- module Output
4
- class Capture
5
- include Fixture::Output
6
-
7
- def records
8
- @records ||= []
9
- end
10
-
11
- def current_context
12
- @current_context ||= []
13
- end
14
-
15
- def start
16
- record(:start)
17
- end
18
-
19
- def finish(result)
20
- record(:finish, result)
21
- end
22
-
23
- def enter_file(path)
24
- record(:enter_file, path)
25
- end
26
-
27
- def exit_file(path, result)
28
- record(:exit_file, path, result)
29
- end
30
-
31
- def start_fixture(fixture)
32
- record(:start_fixture, fixture)
33
- end
34
-
35
- def finish_fixture(fixture, result)
36
- record(:finish_fixture, fixture, result)
37
- end
38
-
39
- def assert(result, caller_location)
40
- record(:assert, result, caller_location)
41
- end
42
-
43
- def comment(text)
44
- record(:comment, text)
45
- end
46
-
47
- def detail(text)
48
- record(:detail, text)
49
- end
50
-
51
- def error(error)
52
- record(:error, error)
53
- end
54
-
55
- def start_test(title)
56
- record(:start_test, title)
57
- end
58
-
59
- def finish_test(title, result)
60
- record(:finish_test, title, result)
61
- end
62
-
63
- def skip_test(title)
64
- record(:skip_test, title)
65
- end
66
-
67
- def enter_context(title)
68
- record = record(:enter_context, title)
69
-
70
- unless title.nil?
71
- current_context.push(title)
72
- end
73
-
74
- record
75
- end
76
-
77
- def exit_context(title, result)
78
- unless title.nil?
79
- current_context.pop
80
- end
81
-
82
- record(:exit_context, title, result)
83
- end
84
-
85
- def skip_context(title)
86
- record(:skip_context, title)
87
- end
88
-
89
- def each_record(&block)
90
- records.each(&block)
91
- end
92
-
93
- def record(signal, *data)
94
- record = new_record(signal, data)
95
- records << record
96
- record
97
- end
98
-
99
- def new_record(signal, data)
100
- context = current_context.dup
101
-
102
- record = Record.build(signal, data, context)
103
- end
104
-
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
-
118
- def forward(receiver)
119
- receiver.public_send(signal, *data)
120
- end
121
-
122
- def ==(record)
123
- self.signal == record.signal &&
124
- self.data == record.data &&
125
- self.context == record.context
126
- end
127
- end
128
- end
129
- end
130
- end
131
- end
@@ -1,142 +0,0 @@
1
- module TestBench
2
- module Fixture
3
- module Output
4
- class Log
5
- include Output
6
-
7
- Error = Class.new(RuntimeError)
8
-
9
- attr_reader :logger
10
-
11
- def initialize(logger)
12
- @logger = logger
13
- end
14
-
15
- def self.build(device=nil, level: nil)
16
- device ||= $stderr
17
- level ||= self.default_level
18
-
19
- level_ordinal = level_ordinal(level)
20
-
21
- logger = Logger.new(device)
22
- logger.level = level_ordinal
23
-
24
- new(logger)
25
- end
26
-
27
- def self.configure(receiver, device=nil, level: nil, attr_name: nil)
28
- attr_name ||= :output
29
-
30
- instance = build(device, level: level)
31
- receiver.public_send(:"#{attr_name}=", instance)
32
- instance
33
- end
34
-
35
- def self.default_level
36
- :debug
37
- end
38
-
39
- def self.levels
40
- level_ordinals.keys
41
- end
42
-
43
- def self.level_ordinal(level)
44
- assure_level(level)
45
-
46
- level_ordinals.fetch(level)
47
- end
48
-
49
- def self.level_ordinals
50
- {
51
- :unknown => Logger::Severity::UNKNOWN,
52
- :fatal => Logger::Severity::FATAL,
53
- :error => Logger::Severity::ERROR,
54
- :warning => Logger::Severity::WARN,
55
- :info => Logger::Severity::INFO,
56
- :debug => Logger::Severity::DEBUG
57
- }
58
- end
59
-
60
- def self.assure_level(level)
61
- unless level_ordinals.key?(level)
62
- raise Error, "Unknown log level #{level.inspect} (Valid levels: #{levels.map(&:inspect).join(', ')})"
63
- end
64
- end
65
-
66
- def start
67
- logger.debug { "Start" }
68
- end
69
-
70
- def finish(result)
71
- logger.info { "Finish (Result: #{result})" }
72
- end
73
-
74
- def enter_file(path)
75
- logger.debug { "Enter file (Path: #{path})" }
76
- end
77
-
78
- def exit_file(path, result)
79
- logger.info { "Exit file (Path: #{path}, Result: #{result})" }
80
- end
81
-
82
- def start_fixture(fixture)
83
- logger.debug { "Start fixture (Fixture: #{fixture.inspect})" }
84
- end
85
-
86
- def finish_fixture(fixture, result)
87
- logger.info { "Finish fixture (Fixture: #{fixture.inspect}, Result: #{result})" }
88
- end
89
-
90
- def assert(result, caller_location)
91
- logger.info { "Assertion (Result: #{result}, Caller Location: #{caller_location})" }
92
- end
93
-
94
- def comment(text)
95
- logger.info { "Comment (Text: #{text})" }
96
- end
97
-
98
- def detail(text)
99
- logger.debug { "Detail (Text: #{text})" }
100
- end
101
-
102
- def error(error)
103
- logger.error { "Error (Error: #{error})" }
104
- end
105
-
106
- def start_test(title)
107
- logger.debug { "Starting test (Title: #{title || '(none)'})" }
108
- end
109
-
110
- def finish_test(title, result)
111
- logger.info { "Finished test (Title: #{title || '(none)'}, Result: #{result})" }
112
- end
113
-
114
- def skip_test(title)
115
- logger.info { "Skipped test (Title: #{title || '(none)'})" }
116
- end
117
-
118
- def enter_context(title)
119
- logger.debug { "Entering context (Title: #{title || '(none)'})" }
120
- end
121
-
122
- def exit_context(title, result)
123
- logger.info { "Exited context (Title: #{title || '(none)'}, Result: #{result})" }
124
- end
125
-
126
- def skip_context(title)
127
- logger.info { "Skipped context (Title: #{title || '(none)'})" }
128
- end
129
-
130
- def device?(device)
131
- self.device == device
132
- end
133
-
134
- def device
135
- logger.instance_exec do
136
- @logdev.dev
137
- end
138
- end
139
- end
140
- end
141
- end
142
- end
@@ -1,42 +0,0 @@
1
- module TestBench
2
- module Fixture
3
- module Output
4
- class Multiple
5
- include Output
6
-
7
- def outputs
8
- @outputs ||= []
9
- end
10
- attr_writer :outputs
11
-
12
- def self.build(*outputs)
13
- outputs = Array(outputs)
14
-
15
- instance = new
16
-
17
- outputs.each do |output|
18
- instance.register(output)
19
- end
20
-
21
- instance
22
- end
23
-
24
- Output.instance_methods.each do |method_name|
25
- define_method(method_name) do |*args|
26
- outputs.map do |output|
27
- output.public_send(method_name, *args)
28
- end
29
- end
30
- end
31
-
32
- def register(output)
33
- outputs << output
34
- end
35
-
36
- def registered?(output)
37
- outputs.include?(output)
38
- end
39
- end
40
- end
41
- end
42
- end
@@ -1,9 +0,0 @@
1
- module TestBench
2
- module Fixture
3
- module Output
4
- class Null
5
- include Output
6
- end
7
- end
8
- end
9
- end
@@ -1,26 +0,0 @@
1
- module TestBench
2
- module Fixture
3
- module Output
4
- module Substitute
5
- class Output
6
- class Scope < Output
7
- attr_writer :records
8
-
9
- def self.build(records)
10
- instance = new
11
- instance.records = records
12
- instance
13
- end
14
-
15
- def combine(scope)
16
- combined_records = self.records + scope.records
17
-
18
- Scope.build(combined_records)
19
- end
20
- alias_method :+, :combine
21
- end
22
- end
23
- end
24
- end
25
- end
26
- end
@@ -1,114 +0,0 @@
1
- module TestBench
2
- module Fixture
3
- module Output
4
- module Substitute
5
- def self.build
6
- Output.new
7
- end
8
-
9
- MatchError = Class.new(RuntimeError)
10
-
11
- class Output < Capture
12
- alias_method :raw_records, :records
13
-
14
- def scope(*contexts, &block)
15
- records = records(*contexts, &block)
16
-
17
- Scope.build(records)
18
- end
19
-
20
- def recorded_once?(*contexts, &block)
21
- record = one_record(*contexts, &block)
22
-
23
- record ? true : false
24
- end
25
-
26
- def recorded?(*contexts, &block)
27
- records = match_records(*contexts, &block)
28
-
29
- records.any?
30
- end
31
-
32
- def one_record(*contexts, &block)
33
- matching_records = match_records(*contexts, &block)
34
-
35
- return if matching_records.empty?
36
-
37
- unless matching_records.one?
38
- raise MatchError, "More than one records match"
39
- end
40
-
41
- matching_records.shift
42
- end
43
-
44
- def records(*contexts, &block)
45
- if contexts.empty? && block.nil?
46
- return raw_records
47
- end
48
-
49
- match_records(*contexts, &block)
50
- end
51
-
52
- def match_records(*contexts, &block)
53
- block ||= proc { true }
54
-
55
- raw_records.select do |record|
56
- context_iterator = record.context.to_enum
57
-
58
- contexts_match = contexts.all? do |context|
59
- until context_iterator.peek == context
60
- context_iterator.next
61
- end
62
- true
63
-
64
- rescue StopIteration
65
- false
66
- end
67
-
68
- contexts_match &&
69
- block.(record.signal, *record.data, record.context)
70
- end
71
- end
72
-
73
- Fixture::Output.signals.each do |signal|
74
- signal_records_method = :"#{signal}_records" # e.g. comment_records
75
- define_method(signal_records_method) do |*contexts, &block|
76
- match_records(*contexts) do |recorded_signal, *data|
77
- if recorded_signal == signal
78
- block.nil? || block.(*data)
79
- end
80
- end
81
- end
82
-
83
- one_signal_method = :"one_#{signal}_record" # e.g. one_comment_record
84
- define_method(one_signal_method) do |*contexts, &block|
85
- one_record(*contexts) do |recorded_signal, *data|
86
- if recorded_signal == signal
87
- block.nil? || block.(*data)
88
- end
89
- end
90
- end
91
-
92
- signal_recorded_method = :"#{signal}_recorded?" # e.g. comment_recorded?
93
- define_method(signal_recorded_method) do |*contexts, &block|
94
- recorded?(*contexts) do |recorded_signal, *data|
95
- if recorded_signal == signal
96
- block.nil? || block.(*data)
97
- end
98
- end
99
- end
100
-
101
- signal_recorded_once_method = :"#{signal}_recorded_once?" # e.g. comment_recorded_once?
102
- define_method(signal_recorded_once_method) do |*contexts, &block|
103
- recorded_once?(*contexts) do |recorded_signal, *data|
104
- if recorded_signal == signal
105
- block.nil? || block.(*data)
106
- end
107
- end
108
- end
109
- end
110
- end
111
- end
112
- end
113
- end
114
- end
@@ -1,57 +0,0 @@
1
- module TestBench
2
- module Fixture
3
- module Output
4
- def self.signals
5
- instance_methods(false)
6
- end
7
-
8
- def start
9
- end
10
-
11
- def finish(result)
12
- end
13
-
14
- def enter_file(path)
15
- end
16
-
17
- def exit_file(path, result)
18
- end
19
-
20
- def start_fixture(fixture)
21
- end
22
-
23
- def finish_fixture(fixture, result)
24
- end
25
-
26
- def assert(result, caller_location)
27
- end
28
-
29
- def comment(text)
30
- end
31
-
32
- def detail(text)
33
- end
34
-
35
- def error(error)
36
- end
37
-
38
- def start_test(title)
39
- end
40
-
41
- def finish_test(title, result)
42
- end
43
-
44
- def skip_test(title)
45
- end
46
-
47
- def enter_context(title)
48
- end
49
-
50
- def exit_context(title, result)
51
- end
52
-
53
- def skip_context(title)
54
- end
55
- end
56
- end
57
- end