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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cc001b82ac9ea1f454084cb5eae8d7d1d6a210e394da970c90ca1867aa0720da
4
- data.tar.gz: 6e6b9d88655aac2b360a89e08325b07ea2837ec3a55acc0aa145e6700cd1d615
3
+ metadata.gz: 452df63916f2797909fcaf1fa88fa3796e30f62ae8e76b474f88f44deca9c0a7
4
+ data.tar.gz: d20658bd59994d577596d14c1f6d4bba7159e8278e8a8e2f3e44fdf70e939630
5
5
  SHA512:
6
- metadata.gz: 1e9b30ca2c58bc2a113ad378111addff10e348a76115ce467479942c37a46fecad65571e6fff52d1392fbc64bb6173cf57da6e073a52e337a04af0a4df91a2a7
7
- data.tar.gz: 51e9b333a51d131d5419bad17105e6b3cd71e660ae35823f627748a06f21a52416db220e14954d6ed7c87ef0a9cd5fab0163eee403789c16de2de802cb6ba413
6
+ metadata.gz: 94780148b301e586fc8aa263e6563afa2329d0c4f9cf4a44e9c65e50a4d2316055795cf268d090ab88874801086137937f94d50b531c477001e0db0f49f36c62
7
+ data.tar.gz: e9ea4a7400c93b9086214d1b5dfb86b663c1db0ff729a61bb362f4eba8247205e86e89bcf0342bd3db7833705d04b60864829995ff2e4397da49b31467e9b5c0
@@ -0,0 +1,95 @@
1
+ module TestBench
2
+ module Fixture
3
+ module Actuate
4
+ module Class
5
+ Error = ::Class.new(RuntimeError)
6
+
7
+ def self.call(fixture_class, *, session: nil, **, &block)
8
+ if test_block?(fixture_class)
9
+ test_block = block
10
+ else
11
+ block_actuator = block
12
+ end
13
+
14
+ fixture = build_fixture(fixture_class, *, **, &test_block)
15
+
16
+ Session.configure(fixture, session:, attr_name: :test_session)
17
+
18
+ actuate(fixture, &block_actuator)
19
+
20
+ fixture
21
+ end
22
+
23
+ def self.actuate(fixture, &block_actuator)
24
+ if fixture.respond_to?(:call)
25
+ fixture_actuator = fixture
26
+ end
27
+
28
+ if block_actuator && fixture_actuator
29
+ raise Error, "Block argument given to fixture that has an actuator (Fixture Class: #{fixture.class})"
30
+ end
31
+
32
+ if block_actuator.nil? && fixture_actuator.nil?
33
+ raise Error, "No actuator"
34
+ end
35
+
36
+ if not block_actuator.nil?
37
+ block_actuator.(fixture)
38
+ else
39
+ fixture_actuator.()
40
+ end
41
+ end
42
+
43
+ def self.build_fixture(fixture_class, ...)
44
+ constructor = constructor(fixture_class)
45
+
46
+ fixture_class.public_send(constructor, ...)
47
+ end
48
+
49
+ def self.test_block?(fixture_class)
50
+ assure_fixture(fixture_class)
51
+
52
+ constructor = constructor(fixture_class)
53
+
54
+ if constructor == :build
55
+ constructor_method = fixture_class.method(:build)
56
+ else
57
+ constructor_method = fixture_class.instance_method(:initialize)
58
+ end
59
+
60
+ constructor_parameters = constructor_method.parameters
61
+
62
+ constructor_parameters.any? do |(type, _)|
63
+ type == :block
64
+ end
65
+ end
66
+
67
+ def self.constructor(fixture_class)
68
+ assure_fixture(fixture_class)
69
+
70
+ if fixture_class.respond_to?(:build)
71
+ :build
72
+ else
73
+ :new
74
+ end
75
+ end
76
+
77
+ def self.assure_fixture(fixture_class)
78
+ is_class = fixture_class.instance_of?(::Class)
79
+
80
+ if not is_class
81
+ raise Error, "Not a class (Class: #{fixture_class})"
82
+ end
83
+
84
+ if is_class
85
+ is_fixture_class = fixture_class.included_modules.include?(Fixture)
86
+ end
87
+
88
+ if not is_fixture_class
89
+ raise Error, "Not a fixture class (Class: #{fixture_class})"
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,91 @@
1
+ module TestBench
2
+ module Fixture
3
+ module Actuate
4
+ module Object
5
+ ModuleError = ::Class.new(RuntimeError)
6
+
7
+ def self.call(object, *modules, session: nil, &block_actuator)
8
+ extend(object, *modules)
9
+
10
+ Session.configure(object, session:, attr_name: :test_session)
11
+
12
+ block_actuator.(object)
13
+ end
14
+
15
+ def self.extend(object, *modules)
16
+ if modules.empty?
17
+ fixture_modules = fixture_modules(object)
18
+ else
19
+ fixture_modules = modules.map do |mod|
20
+ assure_included(object, mod)
21
+
22
+ fixture_module(mod)
23
+ end
24
+ end
25
+
26
+ if fixture_modules.empty?
27
+ raise ModuleError, "No Fixture modules found -- #{object.inspect}"
28
+ end
29
+
30
+ fixture_modules.each do |fixture_module|
31
+ object.extend(fixture_module)
32
+ end
33
+
34
+ object.extend(Fixture)
35
+ end
36
+
37
+ def self.assure_included(object, mod)
38
+ if not object.is_a?(mod)
39
+ raise ModuleError, "Object doesn't include module -- #{mod.inspect}"
40
+ end
41
+ end
42
+
43
+ def self.fixture_modules(object)
44
+ fixture_modules = []
45
+
46
+ targets = included_modules(object)
47
+
48
+ targets << object
49
+
50
+ targets.select do |target|
51
+ if fixture_module?(target)
52
+ fixture_module = fixture_module(target)
53
+ fixture_modules << fixture_module
54
+ end
55
+ end
56
+
57
+ fixture_modules
58
+ end
59
+
60
+ def self.fixture_module(object)
61
+ if not fixture_module?(object)
62
+ raise ModuleError, "Couldn't resolve a Fixture module -- #{object.inspect}"
63
+ end
64
+
65
+ target = fixture_module_target(object)
66
+
67
+ target.const_get(:Fixture, false)
68
+ end
69
+
70
+ def self.fixture_module?(object)
71
+ target = fixture_module_target(object)
72
+
73
+ target.const_defined?(:Fixture, false)
74
+ end
75
+
76
+ def self.fixture_module_target(object)
77
+ if object.is_a?(Module)
78
+ object
79
+ else
80
+ object.class
81
+ end
82
+ end
83
+
84
+ def self.included_modules(object)
85
+ modules = (object.class.included_modules | object.singleton_class.included_modules) - ::Object.included_modules
86
+ modules.sort_by(&:name)
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,7 @@
1
+ module TestBench
2
+ module Fixture
3
+ module Controls
4
+ Exception = TestBench::Session::Controls::Exception
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,86 @@
1
+ module TestBench
2
+ module Fixture
3
+ module Controls
4
+ module Fixture
5
+ module Class
6
+ Example = Fixture::Example
7
+
8
+ class BuildMethod
9
+ include TestBench::Fixture
10
+
11
+ attr_accessor :some_argument
12
+ attr_accessor :some_keyword_argument
13
+
14
+ def self.build(some_argument=nil, some_keyword_argument: nil)
15
+ instance = new
16
+ instance.some_argument = some_argument
17
+ instance.some_keyword_argument = some_keyword_argument
18
+ instance
19
+ end
20
+ end
21
+
22
+ class NoBuildMethod
23
+ include TestBench::Fixture
24
+
25
+ attr_reader :some_argument
26
+ attr_reader :some_keyword_argument
27
+
28
+ def initialize(some_argument=nil, some_keyword_argument: nil)
29
+ @some_argument = some_argument
30
+ @some_keyword_argument = some_keyword_argument
31
+ end
32
+ end
33
+
34
+ class TestBlock
35
+ include TestBench::Fixture
36
+
37
+ attr_reader :test_block
38
+
39
+ def initialize(&test_block)
40
+ @test_block = test_block
41
+ end
42
+
43
+ NoBuildMethod = TestBlock
44
+
45
+ class BuildMethod
46
+ include TestBench::Fixture
47
+
48
+ attr_reader :test_block
49
+
50
+ def initialize(test_block)
51
+ @test_block = test_block
52
+ end
53
+
54
+ def self.build(&test_block)
55
+ new(test_block)
56
+ end
57
+ end
58
+
59
+ None = Fixture::Class::BuildMethod
60
+ end
61
+
62
+ class Actuator
63
+ include TestBench::Fixture
64
+
65
+ attr_accessor :actuated
66
+ def actuated? = !!actuated
67
+
68
+ def call
69
+ self.actuated = true
70
+ end
71
+
72
+ class TestBlock < Actuator
73
+ attr_reader :test_block
74
+
75
+ def initialize(&test_block)
76
+ @test_block = test_block
77
+ end
78
+ end
79
+ end
80
+
81
+ NoActuator = Example
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,39 @@
1
+ module TestBench
2
+ module Fixture
3
+ module Controls
4
+ module Fixture
5
+ module Object
6
+ module Modules
7
+ def self.included
8
+ [Extended, Included, NoFixture]
9
+ end
10
+
11
+ module Included
12
+ def self.example
13
+ self
14
+ end
15
+
16
+ module Fixture
17
+ end
18
+ end
19
+
20
+ module Extended
21
+ def self.example
22
+ self
23
+ end
24
+
25
+ module Fixture
26
+ end
27
+ end
28
+
29
+ module NoFixture
30
+ def self.example
31
+ self
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,31 @@
1
+ module TestBench
2
+ module Fixture
3
+ module Controls
4
+ module Fixture
5
+ module Object
6
+ def self.example
7
+ object = Example.new
8
+ object.extend(Modules::Extended)
9
+ object
10
+ end
11
+
12
+ def self.fixture_modules
13
+ [
14
+ Modules::Extended::Fixture,
15
+ Modules::Included::Fixture,
16
+ Example::Fixture
17
+ ]
18
+ end
19
+
20
+ class Example
21
+ include Modules::Included
22
+ include Modules::NoFixture
23
+
24
+ module Fixture
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -6,79 +6,21 @@ module TestBench
6
6
  Example.new
7
7
  end
8
8
 
9
- def self.example_class(&block)
10
- Class.new do
11
- include TestBench::Fixture
9
+ def self.call(output=nil, &block)
10
+ output ||= Output.example
12
11
 
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
12
+ fixture = Example.new
39
13
 
40
- module FactoryMethod
41
- def self.example
42
- Example.build
43
- end
14
+ fixture.test_session.telemetry.register(output)
44
15
 
45
- Example = Fixture.example_class do
46
- attr_accessor :build_method_called
47
- alias_method :build_method_called?, :build_method_called
16
+ block.(fixture)
48
17
 
49
- def self.build
50
- instance = new
51
- instance.build_method_called = true
52
- instance
53
- end
54
- end
18
+ fixture
55
19
  end
56
20
 
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
21
+ class Example
22
+ include TestBench::Fixture
79
23
  end
80
-
81
- Example = InstanceActuator::Example
82
24
  end
83
25
  end
84
26
  end
@@ -1,64 +1,7 @@
1
1
  module TestBench
2
2
  module Fixture
3
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
- detail_text = 'Some detail'
38
- test_title = 'Some test'
39
- context_title = 'Some Context'
40
-
41
- {
42
- :start => [],
43
- :enter_file => [path],
44
- :exit_file => [path, result],
45
- :start_fixture => [fixture],
46
- :finish_fixture => [fixture, result],
47
- :assert => [result, caller_location],
48
- :comment => [comment_text],
49
- :detail => [detail_text],
50
- :error => [error],
51
- :start_test => [test_title],
52
- :finish_test => [test_title, result],
53
- :skip_test => [test_title],
54
- :enter_context => [context_title],
55
- :exit_context => [context_title, result],
56
- :skip_context => [context_title],
57
- :finish => [result]
58
- }.each(&block)
59
- end
60
- end
61
- end
4
+ Output = TestBench::Session::Controls::Output
62
5
  end
63
6
  end
64
7
  end
@@ -0,0 +1,7 @@
1
+ module TestBench
2
+ module Fixture
3
+ module Controls
4
+ Random = Output::Controls::Random
5
+ end
6
+ end
7
+ end
@@ -1,23 +1,7 @@
1
1
  module TestBench
2
2
  module Fixture
3
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
4
+ Result = TestBench::Session::Controls::Result
21
5
  end
22
6
  end
23
7
  end
@@ -0,0 +1,7 @@
1
+ module TestBench
2
+ module Fixture
3
+ module Controls
4
+ Title = TestBench::Session::Controls::Title
5
+ end
6
+ end
7
+ end
@@ -1,13 +1,13 @@
1
- unless RUBY_ENGINE == 'mruby'
2
- require 'tempfile'
3
- end
1
+ require 'test_bench/session/controls'
4
2
 
5
- require 'test_bench/fixture/controls/caller_location'
6
- require 'test_bench/fixture/controls/error/backtrace'
7
- require 'test_bench/fixture/controls/error'
8
- require 'test_bench/fixture/controls/fixture'
3
+ require 'test_bench/fixture/controls/random'
9
4
  require 'test_bench/fixture/controls/result'
10
- require 'test_bench/fixture/controls/test_file'
5
+ require 'test_bench/fixture/controls/exception'
6
+ require 'test_bench/fixture/controls/title'
7
+
8
+ require 'test_bench/fixture/controls/fixture'
9
+ require 'test_bench/fixture/controls/fixture/class'
10
+ require 'test_bench/fixture/controls/fixture/object/modules'
11
+ require 'test_bench/fixture/controls/fixture/object'
11
12
 
12
13
  require 'test_bench/fixture/controls/output'
13
- require 'test_bench/fixture/controls/output/log'
@@ -0,0 +1,29 @@
1
+ module TestBench
2
+ module Fixture
3
+ class Evaluate
4
+ include Fixture
5
+
6
+ attr_reader :block
7
+
8
+ def initialize(block)
9
+ @block = block
10
+ end
11
+
12
+ def self.build(session:, &block)
13
+ instance = new(block)
14
+ Session.configure(instance, session:, attr_name: :test_session)
15
+ instance
16
+ end
17
+
18
+ def self.call(session: nil, &block)
19
+ instance = build(session:, &block)
20
+ instance.()
21
+ instance
22
+ end
23
+
24
+ def call
25
+ instance_exec(&block)
26
+ end
27
+ end
28
+ end
29
+ end