razorrisk-razor-connectivity-testdoubles 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ddb802b853e69ca0a5bc6a07fae98d11752f440a
4
+ data.tar.gz: edf572120faaa841a323c470e80b3067902244bc
5
+ SHA512:
6
+ metadata.gz: d3ada8649bae663a3876dd6559646ea825559e9bac5fb6bd3328e2b32fea9093ff8c5ef4b7a8039b33533c750cd28f5f69c5b51849eb38e556e1b7f1bad453c8
7
+ data.tar.gz: eec9e137718ff1e5787831176880ad9cfca244efbc37fa40916ce3c4cae59b504f1816d226a93bb88f74ced1dad531eeaa04096011ebb502fd2fb00f1dac5d64
data/Rakefile ADDED
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ # ######################################################################## #
4
+ #
5
+ # Copyright (c) 2019 Razor Risk Technologies Pty Limited. All rights reserved.
6
+ #
7
+ # ######################################################################## #
8
+
9
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), 'lib')
10
+
11
+ # ##########################################################
12
+ # bundler
13
+
14
+ require 'rubygems'
15
+ require 'bundler/setup'
16
+
17
+ # ######################################################################## #
18
+ # requires
19
+
20
+ require 'razor_risk/razor/control/rake_helpers/diagnostic_tasks'
21
+ require 'razor_risk/razor/control/rake_helpers/gem_tasks'
22
+ require 'razor_risk/razor/control/rake_helpers/task_helpers'
23
+
24
+ require 'rake'
25
+ require 'rake/clean'
26
+
27
+ # ##########################################################
28
+ # includes
29
+
30
+ include ::RazorRisk::Razor::Control # rubocop:todo Style/MixinUsage
31
+ include ::Pantheios # rubocop:todo Style/MixinUsage
32
+
33
+ # ##########################################################
34
+ # Constants
35
+
36
+ Spec = ::Gem::Specification.load(Dir['*.gemspec'].first)
37
+ LogDir = 'log' # rubocop:todo Naming/ConstantName
38
+ # rubocop:todo Naming/ConstantName
39
+ LogThresholds = %i[informational informational].freeze
40
+ # rubocop:enable Naming/ConstantName
41
+
42
+ # ##########################################################
43
+ # clean/clobber
44
+
45
+ Dir[
46
+ 'log',
47
+ 'doc',
48
+ ].each { |f| CLEAN << f }
49
+ Dir[
50
+ '.bundle',
51
+ 'vendor',
52
+ 'GEM_HOME',
53
+ '*.gem',
54
+ ].each { |f| CLOBBER << f }
55
+
56
+ # ##########################################################
57
+ # Tasks
58
+
59
+ desc 'Run tests'
60
+ task test: [:'gem:unit_test']
61
+
62
+ desc 'Build gem'
63
+ task :build_gem, [:path] => :'gem:build'
64
+
65
+ desc 'Builds the Razor EntityConnector Gem'
66
+ task :build, [:path] => [:build_gem]
67
+
68
+ desc 'Push the gem to the gem server.'
69
+ task deploy: :'gem:push'
70
+
71
+ # ##########################################################
72
+ # Hooks
73
+
74
+ task :default do
75
+ puts 'Run \'bundler exec rake --tasks\' to see available tasks'
76
+ end
77
+
78
+ task :first do
79
+ ::Rake::Task[:'diagnostics:init'].execute(
80
+ name: Spec.name,
81
+ version: Spec.version.to_s,
82
+ directory: LogDir,
83
+ thresholds: LogThresholds
84
+ )
85
+ end
86
+
87
+ RakeHelpers::TaskHelpers.add_hooks
88
+
89
+ # ############################## end of file ############################# #
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ # ######################################################################## #
4
+ # File: lib/razor_risk/razor/connectivity/test_doubles/razor_requester/raises_on_send.rb
5
+ #
6
+ # Purpose: Stub module
7
+ #
8
+ # Created: 21st March 2018
9
+ # Updated: 14th August 2018
10
+ #
11
+ # Author: Matthew Wilson
12
+ #
13
+ # Copyright (c) 2018, Razor Risk Technologies Pty Ltd
14
+ # All rights reserved.
15
+ #
16
+ # ######################################################################## #
17
+
18
+ require 'razor_risk/razor/connectivity/test_doubles/razor_requester/stub'
19
+
20
+ module RazorRisk
21
+ module Razor
22
+ module Connectivity
23
+ module TestDoubles
24
+ module RazorRequester
25
+ # Stub for RazorRequester, which throws an exception when the +send_request+
26
+ # method is invoked
27
+ class RaisesOnSend
28
+ include Stub
29
+
30
+ # Creates an instance, according to the given +options+
31
+ #
32
+ # === Signature
33
+ #
34
+ # * *Options:*
35
+ #
36
+ # @option +:exception+ (::Class) An exception class to be thrown. If not
37
+ # specified an instance of +::RuntimeError+ will be thrown
38
+ # @option +:exception_message+ (::String) A string to be used as the
39
+ # thrown exception's message. If not specified, the message
40
+ # +'expected'+ will be used
41
+ #
42
+ def initialize(config, environment, **options)
43
+ super
44
+
45
+ @exception = check_option(options, :exception, type: ::Class, allow_nil: true) || ::RuntimeError
46
+
47
+ @exception_message = check_option(options, :exception_message, type: ::String, allow_nil: true) || 'expected'
48
+ end
49
+
50
+ # Emulates a send-request, subject to the given options
51
+ #
52
+ # === Signature
53
+ #
54
+ # * *Parameters:*
55
+ #
56
+ # * *Options:*
57
+ #
58
+ # @option +:check_request+:: Determines whether the request should be
59
+ # checked. If truey, then the following values are recognised: +:xml+
60
+ # means that the request must be valid XML
61
+ def send_request(request, **options)
62
+ super
63
+
64
+ raise @exception, @exception_message
65
+ end
66
+ # rubocop:todo Style/CommentedKeyword
67
+ end # class RaisesOnSend
68
+ # rubocop:enable Style/CommentedKeyword
69
+ # rubocop:todo Style/CommentedKeyword
70
+ end # module RazorRequester
71
+ # rubocop:enable Style/CommentedKeyword
72
+ end
73
+ end
74
+ end
75
+ end
76
+
77
+ # ############################## end of file ############################# #
@@ -0,0 +1,96 @@
1
+ # frozen_string_literal: true
2
+
3
+ # ######################################################################## #
4
+ # File: lib/razor_risk/razor/connectivity/test_doubles/razor_requester/returns_given_response.rb
5
+ #
6
+ # Purpose: Stub module
7
+ #
8
+ # Created: 7th June 2018
9
+ # Updated: 14th August 2018
10
+ #
11
+ # Author: Matthew Wilson
12
+ #
13
+ # Copyright (c) 2018, Razor Risk Technologies Pty Ltd
14
+ # All rights reserved.
15
+ #
16
+ # ######################################################################## #
17
+
18
+ require 'razor_risk/razor/connectivity/test_doubles/razor_requester/stub'
19
+
20
+ module RazorRisk
21
+ module Razor
22
+ module Connectivity
23
+ module TestDoubles
24
+ module RazorRequester
25
+ # rubocop:todo Style/Documentation
26
+ class ReturnsGivenResponse
27
+ include Stub
28
+
29
+ ACCEPTED_OPTIONS = %w[
30
+
31
+ allow_nil
32
+ given_response
33
+ ].map(&:to_sym)
34
+
35
+ # Creates an instance, according to the given +options+
36
+ #
37
+ # === Signature
38
+ #
39
+ # * *Options:*
40
+ #
41
+ # @option +:given_response+:: (::Object) An object whose string form will
42
+ # be emitted. May not be +nil+, unless +options[:allow_nil]+
43
+ # @option +:allow_nil+:: (boolean) Determines whether the value of
44
+ # +:given_response+ may be +nil+
45
+ #
46
+ def initialize(config, environment, **options)
47
+ super
48
+
49
+ @given_response = check_option(options, :given_response, allow_nil: options[:allow_nil])
50
+
51
+ @latest_request = nil
52
+ end
53
+
54
+ # The latest request submitted to +#send_request+
55
+ attr_reader :latest_request
56
+
57
+ # Emulates a send-request, subject to the given options
58
+ #
59
+ # === Signature
60
+ #
61
+ # * *Parameters:*
62
+ #
63
+ # * *Options:*
64
+ #
65
+ # @option +:check_request+:: Determines whether the request should be
66
+ # checked. If truey, then the following values are recognised: +:xml+
67
+ # means that the request must be valid XML
68
+ def send_request(request, **options)
69
+ super
70
+
71
+ @latest_request = request
72
+
73
+ case options[:check_request]
74
+ when :xml
75
+
76
+ raise ::ArgumentError, 'request may not be nil' if request.nil?
77
+ unless %w[Nokogiri::XML::Document Nokogiri::XML::Element Nokogiri::XML::Node].include? request.class.to_s
78
+ raise ::TypeError, 'request must be instance of Nokogiri XML node'
79
+ end
80
+ end
81
+
82
+ @given_response
83
+ end
84
+ # rubocop:todo Style/CommentedKeyword
85
+ end # class ReturnsGivenResponse
86
+ # rubocop:enable Style/CommentedKeyword
87
+ # rubocop:enable Style/Documentation
88
+ # rubocop:todo Style/CommentedKeyword
89
+ end # module RazorRequester
90
+ # rubocop:enable Style/CommentedKeyword
91
+ end
92
+ end
93
+ end
94
+ end
95
+
96
+ # ############################## end of file ############################# #
@@ -0,0 +1,102 @@
1
+ # frozen_string_literal: true
2
+
3
+ # ######################################################################## #
4
+ # File: lib/razor_risk/razor/connectivity/test_doubles/razor_requester/returns_given_responses.rb
5
+ #
6
+ # Purpose: Stub module
7
+ #
8
+ # Created: 10th August 2018
9
+ # Updated: 14th August 2018
10
+ #
11
+ # Author: Matthew Wilson
12
+ #
13
+ # Copyright (c) 2018, Razor Risk Technologies Pty Ltd
14
+ # All rights reserved.
15
+ #
16
+ # ######################################################################## #
17
+
18
+ require 'razor_risk/razor/connectivity/test_doubles/razor_requester/stub'
19
+
20
+ module RazorRisk
21
+ module Razor
22
+ module Connectivity
23
+ module TestDoubles
24
+ module RazorRequester
25
+ # rubocop:todo Style/Documentation
26
+ class ReturnsGivenResponses
27
+ include Stub
28
+
29
+ ACCEPTED_OPTIONS = %w[
30
+
31
+ given_responses
32
+ ].map(&:to_sym)
33
+
34
+ # Creates an instance, according to the given +options+
35
+ #
36
+ # === Signature
37
+ #
38
+ # * *Options:*
39
+ #
40
+ # @option +:given_responses+:: (::Array) An array of objects that will
41
+ # be emitted in a wrapping sequence. May not be nil or empty
42
+ #
43
+ def initialize(config, environment, **options)
44
+ super
45
+
46
+ @given_responses = check_option(options, :given_responses, type: ::Array, reject_empty: true)
47
+ @response_count = 0
48
+
49
+ @requests = []
50
+ end
51
+
52
+ # The latest request submitted to +#send_request+
53
+ attr_reader :requests
54
+
55
+ # Emulates a send-request, subject to the given options
56
+ #
57
+ # === Signature
58
+ #
59
+ # * *Parameters:*
60
+ #
61
+ # * *Options:*
62
+ #
63
+ # @option +:check_request+:: Determines whether the request should be
64
+ # checked. If truey, then the following values are recognised: +:xml+
65
+ # means that the request must be valid XML
66
+ # rubocop:todo Metrics/MethodLength
67
+ def send_request(request, **options)
68
+ super
69
+
70
+ @requests << request
71
+
72
+ options = @options.merge options
73
+
74
+ case options[:check_request]
75
+ when :xml
76
+
77
+ raise ::ArgumentError, 'request may not be nil' if request.nil?
78
+ unless %w[Nokogiri::XML::Document Nokogiri::XML::Element Nokogiri::XML::Node].include? request.class.to_s
79
+ raise ::TypeError, 'request must be instance of Nokogiri XML node'
80
+ end
81
+ end
82
+
83
+ r = @given_responses[@response_count % @given_responses.size]
84
+
85
+ @response_count += 1
86
+
87
+ r
88
+ end
89
+ # rubocop:enable Metrics/MethodLength
90
+ # rubocop:todo Style/CommentedKeyword
91
+ end # class ReturnsGivenResponses
92
+ # rubocop:enable Style/CommentedKeyword
93
+ # rubocop:enable Style/Documentation
94
+ # rubocop:todo Style/CommentedKeyword
95
+ end # module RazorRequester
96
+ # rubocop:enable Style/CommentedKeyword
97
+ end
98
+ end
99
+ end
100
+ end
101
+
102
+ # ############################## end of file ############################# #
@@ -0,0 +1,103 @@
1
+ # frozen_string_literal: true
2
+
3
+ # ######################################################################## #
4
+ # File: lib/razor_risk/razor/connectivity/test_doubles/razor_requester/stub.rb
5
+ #
6
+ # Purpose: Stub module
7
+ #
8
+ # Created: 14th August 2018
9
+ # Updated: 14th August 2018
10
+ #
11
+ # Author: Matthew Wilson
12
+ #
13
+ # Copyright (c) 2018, Razor Risk Technologies Pty Ltd
14
+ # All rights reserved.
15
+ #
16
+ # ######################################################################## #
17
+
18
+ require 'xqsr3/quality/parameter_checking'
19
+
20
+ module RazorRisk
21
+ module Razor
22
+ module Connectivity
23
+ module TestDoubles
24
+ module RazorRequester
25
+ # Mixin for RazorRequester stubs, providing +config+, +environment+,
26
+ # +init_options+, +send_options+, +merge_options+, +latest_request+, as well
27
+ # as checking unknown initialisation options
28
+ module Stub
29
+ include ::Xqsr3::Quality::ParameterChecking
30
+
31
+ # Initialises the instance
32
+ #
33
+ # === Signature
34
+ #
35
+ # * *Parameters:*
36
+ # @param config (::String) The configuration
37
+ # @param environment (::String) The environment
38
+ # @param options (::Hash) Options
39
+ #
40
+ # * *Options:*
41
+ #
42
+ # @option +:exception+ (::Class) An exception class to be thrown. If not
43
+ # specified an instance of +::RuntimeError+ will be thrown
44
+ # @option +:exception_message+ (::String) A string to be used as the
45
+ # thrown exception's message. If not specified, the message
46
+ # +'expected'+ will be used
47
+ #
48
+ def initialize(config, environment, **options)
49
+ if self.class.const_defined? :ACCEPTED_OPTIONS
50
+
51
+ invalid_options = options.keys - self.class::ACCEPTED_OPTIONS
52
+
53
+ unless invalid_options.empty?
54
+ warn "#{self.class}##{__method__}() : options contains one or more invalid keys: #{invalid_options}"
55
+ end
56
+ end
57
+
58
+ @config = config
59
+
60
+ @environment = environment
61
+
62
+ @options = {}.merge options
63
+
64
+ @init_options = options.dup
65
+ end
66
+
67
+ # The +config+ passed to the initialiser
68
+ attr_reader :config
69
+ # The +environment+ passed to the initialiser
70
+ attr_reader :environment
71
+ # The options passed to the initialiser
72
+ attr_reader :init_options
73
+ # The options passed to the +send_request+
74
+ attr_reader :send_options
75
+ # The merging of +send_request+ options and initialiser options
76
+ attr_reader :merged_options
77
+
78
+ # Emulates a send-request, subject to the given options
79
+ #
80
+ # === Signature
81
+ #
82
+ # * *Parameters:*
83
+ #
84
+ # * *Options:*
85
+ #
86
+ # @option +:check_request+:: Determines whether the request should be
87
+ # checked. If truey, then the following values are recognised: +:xml+
88
+ # means that the request must be valid XML
89
+ def send_request(_request, **options)
90
+ @send_options = options.dup
91
+
92
+ @merged_options = @options.merge @send_options
93
+ end
94
+ end # module Stub # rubocop:todo Style/CommentedKeyword
95
+ # rubocop:todo Style/CommentedKeyword
96
+ end # module RazorRequester
97
+ # rubocop:enable Style/CommentedKeyword
98
+ end # module TestDoubles # rubocop:todo Style/CommentedKeyword
99
+ end # module Connectivity # rubocop:todo Style/CommentedKeyword
100
+ end
101
+ end
102
+
103
+ # ############################## end of file ############################# #
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'razor_risk/razor/connectivity/test_doubles/razor_requester/raises_on_send'
4
+ require 'razor_risk/razor/connectivity/test_doubles/razor_requester/returns_given_response'
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ # ##########################################################################
4
+ #
5
+ # Version for RazorRisk.Core.Razor.Connectivity.TestDoubles library
6
+ #
7
+ # Copyright (c) 2018 Razor Risk Technologies Pty Limited. All rights reserved.
8
+ #
9
+ # ##########################################################################
10
+
11
+ module RazorRisk
12
+ module Razor
13
+ module Connectivity
14
+ module TestDoubles # rubocop:todo Style/Documentation
15
+ # Current version of the RazorRisk::Razor::Connectivity::TestDoubles library
16
+ VERSION = '0.4.5'
17
+
18
+ private # rubocop:todo Lint/UselessAccessModifier
19
+
20
+ VERSION_PARTS_ = VERSION.split(/[.]/).collect(&:to_i)
21
+
22
+ public # rubocop:todo Lint/UselessAccessModifier
23
+
24
+ # Major version of the RazorRisk::Razor::Connectivity::TestDoubles library
25
+ VERSION_MAJOR = VERSION_PARTS_[0]
26
+ # Minor version of the RazorRisk::Razor::Connectivity::TestDoubles library
27
+ VERSION_MINOR = VERSION_PARTS_[1]
28
+ # Patch version of the RazorRisk::Razor::Connectivity::TestDoubles library
29
+ VERSION_PATCH = VERSION_PARTS_[2]
30
+ # Commit version of the RazorRisk::Razor::Connectivity::TestDoubles library
31
+ VERSION_COMMIT = VERSION_PARTS_[3] || 0
32
+
33
+ # The description of the framework
34
+ DESCRIPTION = "Razor Risk's Cassini Web-framework's Initialisation Daemon"
35
+ end # module TestDoubles # rubocop:todo Style/CommentedKeyword
36
+ end # module Connectivity # rubocop:todo Style/CommentedKeyword
37
+ end # module Razor # rubocop:todo Style/CommentedKeyword
38
+ end # module RazorRisk # rubocop:todo Style/CommentedKeyword
39
+
40
+ # ############################## end of file ############################# #
@@ -0,0 +1,105 @@
1
+ #! /usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # ##########################################################################
5
+ #
6
+ # Copyright (c) 2018 Razor Risk Technologies Pty Limited. All rights reserved.
7
+ #
8
+ # ##########################################################################
9
+
10
+ # ##########################################################
11
+ # load path
12
+
13
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), *(['..'] * 3), 'lib')
14
+
15
+ # ##########################################################
16
+ # diagnostics
17
+
18
+ unless $DEBUG
19
+
20
+ require 'pantheios/globals'
21
+ require 'pantheios/services/null_log_service'
22
+
23
+ ::Pantheios::Globals.INITIAL_SERVICE_CLASSES = [::Pantheios::Services::NullLogService]
24
+ end
25
+
26
+ # ##########################################################
27
+ # code coverage
28
+
29
+ require 'simplecov'
30
+
31
+ # ##########################################################
32
+ # requires
33
+
34
+ require 'razor_risk/razor/connectivity/test_doubles/razor_requester/raises_on_send'
35
+
36
+ require 'xqsr3/extensions/test/unit'
37
+
38
+ require 'test/unit'
39
+
40
+ # ##########################################################
41
+ # tests
42
+
43
+ # rubocop:todo Style/Documentation
44
+ # rubocop:todo Naming/ClassAndModuleCamelCase
45
+ class Test_RazorRequester_RaisesOnSend_types_exist < Test::Unit::TestCase
46
+ include ::RazorRisk::Razor::Connectivity::TestDoubles::RazorRequester
47
+
48
+ def test_has_RazorRisk_module # rubocop:todo Naming/MethodName
49
+ assert Object.const_defined? :RazorRisk
50
+ end
51
+
52
+ def test_has_RazorRisk_Risk_module # rubocop:todo Naming/MethodName
53
+ assert ::RazorRisk.const_defined? :Razor
54
+ end
55
+
56
+ # rubocop:todo Naming/MethodName
57
+ def test_has_RazorRisk_Risk_Connectivity_module
58
+ assert ::RazorRisk::Razor.const_defined? :Connectivity
59
+ end
60
+ # rubocop:enable Naming/MethodName
61
+
62
+ # rubocop:todo Naming/MethodName
63
+ def test_has_RazorRisk_Risk_Connectivity_TestDoubles_module
64
+ assert ::RazorRisk::Razor::Connectivity.const_defined? :TestDoubles
65
+ end
66
+ # rubocop:enable Naming/MethodName
67
+
68
+ # rubocop:todo Naming/MethodName
69
+ def test_has_RazorRisk_Risk_Connectivity_TestDoubles_RazorRequester_module
70
+ assert ::RazorRisk::Razor::Connectivity::TestDoubles.const_defined? :RazorRequester
71
+ end
72
+ # rubocop:enable Naming/MethodName
73
+
74
+ def test_has_RaisesOnSend_class # rubocop:todo Naming/MethodName
75
+ assert ::RazorRisk::Razor::Connectivity::TestDoubles::RazorRequester.const_defined? :RaisesOnSend
76
+ end
77
+
78
+ def test_has_RaisesOnSend_is_a_class # rubocop:todo Naming/MethodName
79
+ assert_kind_of ::Class, ::RazorRisk::Razor::Connectivity::TestDoubles::RazorRequester::RaisesOnSend
80
+ end
81
+ end
82
+ # rubocop:enable Naming/ClassAndModuleCamelCase
83
+ # rubocop:enable Style/Documentation
84
+
85
+ # rubocop:todo Style/Documentation
86
+ # rubocop:todo Naming/ClassAndModuleCamelCase
87
+ class Test_RazorRequester_RaisesOnSend < Test::Unit::TestCase
88
+ include ::RazorRisk::Razor::Connectivity::TestDoubles::RazorRequester
89
+
90
+ def test_raises_default_exception_and_default_message
91
+ assert_raise_with_message(::RuntimeError, 'expected') { RaisesOnSend.new(nil, nil).send_request(nil) }
92
+ end
93
+
94
+ def test_raises_default_exception_and_custom_message
95
+ assert_raise_with_message(::RuntimeError, 'unexpected') { RaisesOnSend.new(nil, nil, exception_message: 'unexpected').send_request(nil) }
96
+ end
97
+
98
+ def test_raises_custom_exception_and_default_message
99
+ assert_raise_with_message(::ArgumentError, 'expected') { RaisesOnSend.new(nil, nil, exception: ::ArgumentError).send_request(nil) }
100
+ end
101
+ end
102
+ # rubocop:enable Naming/ClassAndModuleCamelCase
103
+ # rubocop:enable Style/Documentation
104
+
105
+ # ############################## end of file ############################# #
@@ -0,0 +1,114 @@
1
+ #! /usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # ##########################################################################
5
+ #
6
+ # Copyright (c) 2018 Razor Risk Technologies Pty Limited. All rights reserved.
7
+ #
8
+ # ##########################################################################
9
+
10
+ # ##########################################################
11
+ # load path
12
+
13
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), *(['..'] * 3), 'lib')
14
+
15
+ # ##########################################################
16
+ # diagnostics
17
+
18
+ unless $DEBUG
19
+
20
+ require 'pantheios/globals'
21
+ require 'pantheios/services/null_log_service'
22
+
23
+ ::Pantheios::Globals.INITIAL_SERVICE_CLASSES = [::Pantheios::Services::NullLogService]
24
+ end
25
+
26
+ # ##########################################################
27
+ # code coverage
28
+
29
+ require 'simplecov'
30
+
31
+ # ##########################################################
32
+ # requires
33
+
34
+ require 'razor_risk/razor/connectivity/test_doubles/razor_requester/returns_given_response'
35
+
36
+ require 'xqsr3/extensions/test/unit'
37
+
38
+ require 'test/unit'
39
+
40
+ # ##########################################################
41
+ # tests
42
+
43
+ # rubocop:todo Style/Documentation
44
+ # rubocop:todo Naming/ClassAndModuleCamelCase
45
+ class Test_RazorRequester_ReturnsGivenResponse_types_exist < Test::Unit::TestCase
46
+ include ::RazorRisk::Razor::Connectivity::TestDoubles::RazorRequester
47
+
48
+ def test_has_RazorRisk_module # rubocop:todo Naming/MethodName
49
+ assert Object.const_defined? :RazorRisk
50
+ end
51
+
52
+ def test_has_RazorRisk_Risk_module # rubocop:todo Naming/MethodName
53
+ assert ::RazorRisk.const_defined? :Razor
54
+ end
55
+
56
+ # rubocop:todo Naming/MethodName
57
+ def test_has_RazorRisk_Risk_Connectivity_module
58
+ assert ::RazorRisk::Razor.const_defined? :Connectivity
59
+ end
60
+ # rubocop:enable Naming/MethodName
61
+
62
+ # rubocop:todo Naming/MethodName
63
+ def test_has_RazorRisk_Risk_Connectivity_TestDoubles_module
64
+ assert ::RazorRisk::Razor::Connectivity.const_defined? :TestDoubles
65
+ end
66
+ # rubocop:enable Naming/MethodName
67
+
68
+ # rubocop:todo Naming/MethodName
69
+ def test_has_RazorRisk_Risk_Connectivity_TestDoubles_RazorRequester_module
70
+ assert ::RazorRisk::Razor::Connectivity::TestDoubles.const_defined? :RazorRequester
71
+ end
72
+ # rubocop:enable Naming/MethodName
73
+
74
+ def test_has_ReturnsGivenResponse_class # rubocop:todo Naming/MethodName
75
+ assert ::RazorRisk::Razor::Connectivity::TestDoubles::RazorRequester.const_defined? :ReturnsGivenResponse
76
+ end
77
+
78
+ # rubocop:todo Naming/MethodName
79
+ def test_has_ReturnsGivenResponse_is_a_class
80
+ assert_kind_of ::Class, ::RazorRisk::Razor::Connectivity::TestDoubles::RazorRequester::ReturnsGivenResponse
81
+ end
82
+ # rubocop:enable Naming/MethodName
83
+ end
84
+ # rubocop:enable Naming/ClassAndModuleCamelCase
85
+ # rubocop:enable Style/Documentation
86
+
87
+ # rubocop:todo Style/Documentation
88
+ # rubocop:todo Naming/ClassAndModuleCamelCase
89
+ class Test_RazorRequester_ReturnsGivenResponse < Test::Unit::TestCase
90
+ include ::RazorRisk::Razor::Connectivity::TestDoubles::RazorRequester
91
+
92
+ def test_send_request_with_invalid_input
93
+ assert_raise_with_message(::ArgumentError, /given_response.*nil/) { ReturnsGivenResponse.new('config', 'environment', given_response: nil) }
94
+ assert_raise_with_message(::ArgumentError, /given_response.*nil/) { ReturnsGivenResponse.new('config', 'environment', given_response: nil, allow_nil: false) }
95
+ end
96
+
97
+ # rubocop:todo Metrics/AbcSize
98
+ def test_send_request_with_various_simple_contents
99
+ assert_equal nil, ReturnsGivenResponse.new('config', 'environment', given_response: nil, allow_nil: true).send_request(nil)
100
+ assert_equal :contents, ReturnsGivenResponse.new('config', 'environment', given_response: :contents).send_request(nil)
101
+ assert_equal false, ReturnsGivenResponse.new('config', 'environment', given_response: false).send_request(nil)
102
+ assert_equal true, ReturnsGivenResponse.new('config', 'environment', given_response: true).send_request(nil)
103
+ assert_equal '', ReturnsGivenResponse.new('config', 'environment', given_response: '').send_request(nil)
104
+ assert_equal 'contents', ReturnsGivenResponse.new('config', 'environment', given_response: 'contents').send_request(nil)
105
+ assert_equal '<document />', ReturnsGivenResponse.new('config', 'environment', given_response: '<document />').send_request(nil)
106
+ end
107
+ # rubocop:enable Metrics/AbcSize
108
+
109
+ def test_; end
110
+ end
111
+ # rubocop:enable Naming/ClassAndModuleCamelCase
112
+ # rubocop:enable Style/Documentation
113
+
114
+ # ############################## end of file ############################# #
@@ -0,0 +1,131 @@
1
+ #! /usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # ##########################################################################
5
+ #
6
+ # Copyright (c) 2018 Razor Risk Technologies Pty Limited. All rights reserved.
7
+ #
8
+ # ##########################################################################
9
+
10
+ # ##########################################################
11
+ # load path
12
+
13
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), *(['..'] * 3), 'lib')
14
+
15
+ # ##########################################################
16
+ # diagnostics
17
+
18
+ unless $DEBUG
19
+
20
+ require 'pantheios/globals'
21
+ require 'pantheios/services/null_log_service'
22
+
23
+ ::Pantheios::Globals.INITIAL_SERVICE_CLASSES = [::Pantheios::Services::NullLogService]
24
+ end
25
+
26
+ # ##########################################################
27
+ # code coverage
28
+
29
+ require 'simplecov'
30
+
31
+ # ##########################################################
32
+ # requires
33
+
34
+ require 'razor_risk/razor/connectivity/test_doubles/razor_requester/returns_given_responses'
35
+
36
+ require 'xqsr3/extensions/test/unit'
37
+
38
+ require 'test/unit'
39
+
40
+ # ##########################################################
41
+ # tests
42
+
43
+ # rubocop:todo Style/Documentation
44
+ # rubocop:todo Naming/ClassAndModuleCamelCase
45
+ class Test_RazorRequester_ReturnsGivenResponses_types_exist < Test::Unit::TestCase
46
+ include ::RazorRisk::Razor::Connectivity::TestDoubles::RazorRequester
47
+
48
+ def test_has_RazorRisk_module # rubocop:todo Naming/MethodName
49
+ assert Object.const_defined? :RazorRisk
50
+ end
51
+
52
+ def test_has_RazorRisk_Risk_module # rubocop:todo Naming/MethodName
53
+ assert ::RazorRisk.const_defined? :Razor
54
+ end
55
+
56
+ # rubocop:todo Naming/MethodName
57
+ def test_has_RazorRisk_Risk_Connectivity_module
58
+ assert ::RazorRisk::Razor.const_defined? :Connectivity
59
+ end
60
+ # rubocop:enable Naming/MethodName
61
+
62
+ # rubocop:todo Naming/MethodName
63
+ def test_has_RazorRisk_Risk_Connectivity_TestDoubles_module
64
+ assert ::RazorRisk::Razor::Connectivity.const_defined? :TestDoubles
65
+ end
66
+ # rubocop:enable Naming/MethodName
67
+
68
+ # rubocop:todo Naming/MethodName
69
+ def test_has_RazorRisk_Risk_Connectivity_TestDoubles_RazorRequester_module
70
+ assert ::RazorRisk::Razor::Connectivity::TestDoubles.const_defined? :RazorRequester
71
+ end
72
+ # rubocop:enable Naming/MethodName
73
+
74
+ def test_has_ReturnsGivenResponses_class # rubocop:todo Naming/MethodName
75
+ assert ::RazorRisk::Razor::Connectivity::TestDoubles::RazorRequester.const_defined? :ReturnsGivenResponses
76
+ end
77
+
78
+ # rubocop:todo Naming/MethodName
79
+ def test_has_ReturnsGivenResponses_is_a_class
80
+ assert_kind_of ::Class, ::RazorRisk::Razor::Connectivity::TestDoubles::RazorRequester::ReturnsGivenResponses
81
+ end
82
+ # rubocop:enable Naming/MethodName
83
+ end
84
+ # rubocop:enable Naming/ClassAndModuleCamelCase
85
+ # rubocop:enable Style/Documentation
86
+
87
+ # rubocop:todo Style/Documentation
88
+ # rubocop:todo Naming/ClassAndModuleCamelCase
89
+ class Test_RazorRequester_ReturnsGivenResponses < Test::Unit::TestCase
90
+ include ::RazorRisk::Razor::Connectivity::TestDoubles::RazorRequester
91
+
92
+ def test_send_request_with_invalid_input
93
+ assert_raise_with_message(::ArgumentError, /given_responses.*nil/) { ReturnsGivenResponses.new('config', 'environment', given_responses: nil) }
94
+ end
95
+
96
+ # rubocop:todo Metrics/AbcSize
97
+ def test_send_request_with_various_simple_contents
98
+ assert_equal :contents, ReturnsGivenResponses.new('config', 'environment', given_responses: [:contents]).send_request(nil)
99
+ assert_equal false, ReturnsGivenResponses.new('config', 'environment', given_responses: [false]).send_request(nil)
100
+ assert_equal true, ReturnsGivenResponses.new('config', 'environment', given_responses: [true]).send_request(nil)
101
+ assert_equal '', ReturnsGivenResponses.new('config', 'environment', given_responses: ['']).send_request(nil)
102
+ assert_equal 'contents', ReturnsGivenResponses.new('config', 'environment', given_responses: ['contents']).send_request(nil)
103
+ assert_equal '<document />', ReturnsGivenResponses.new('config', 'environment', given_responses: ['<document />']).send_request(nil)
104
+ end
105
+ # rubocop:enable Metrics/AbcSize
106
+
107
+ def test_send_request_with_multiple_responses
108
+ rgr = ReturnsGivenResponses.new('config', 'environment', given_responses: %i[first_response second_response third_response])
109
+
110
+ assert_equal :first_response, rgr.send_request(nil)
111
+ assert_equal :second_response, rgr.send_request(nil)
112
+ assert_equal :third_response, rgr.send_request(nil)
113
+ assert_equal :first_response, rgr.send_request(nil)
114
+ assert_equal :second_response, rgr.send_request(nil)
115
+ assert_equal :third_response, rgr.send_request(nil)
116
+ end
117
+
118
+ def test_send_request_with_many_responses
119
+ rgr = ReturnsGivenResponses.new('config', 'environment', given_responses: (0..999).to_a)
120
+
121
+ 10.times do
122
+ (0..999).each do |n|
123
+ assert_equal n, rgr.send_request(nil)
124
+ end
125
+ end
126
+ end
127
+ end
128
+ # rubocop:enable Naming/ClassAndModuleCamelCase
129
+ # rubocop:enable Style/Documentation
130
+
131
+ # ############################## end of file ############################# #
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: razorrisk-razor-connectivity-testdoubles
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.5
5
+ platform: ruby
6
+ authors:
7
+ - Razor Risk
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-06-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: razorrisk-core-baseutilities
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: razorrisk-core-diagnostics
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: nokogiri
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pantheios-ruby
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.20.2
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.20.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: recls-ruby
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.9'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.9'
83
+ - !ruby/object:Gem::Dependency
84
+ name: xqsr3
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.30'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.30'
97
+ description: Razor Risk's Cassini Web-framework's Initialisation Daemon
98
+ email: operations@razor-risk.com
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - Rakefile
104
+ - lib/razor_risk/razor/connectivity/test_doubles/razor_requester.rb
105
+ - lib/razor_risk/razor/connectivity/test_doubles/razor_requester/raises_on_send.rb
106
+ - lib/razor_risk/razor/connectivity/test_doubles/razor_requester/returns_given_response.rb
107
+ - lib/razor_risk/razor/connectivity/test_doubles/razor_requester/returns_given_responses.rb
108
+ - lib/razor_risk/razor/connectivity/test_doubles/razor_requester/stub.rb
109
+ - lib/razor_risk/razor/connectivity/test_doubles/version.rb
110
+ - test/unit/razor_requester/tc_raises_on_send.rb
111
+ - test/unit/razor_requester/tc_returns_given_response.rb
112
+ - test/unit/razor_requester/tc_returns_given_responses.rb
113
+ homepage: https://razor-risk.com/
114
+ licenses: []
115
+ metadata: {}
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '2.0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project:
132
+ rubygems_version: 2.6.14
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: RazorRisk.Core.Razor.Connectivity.TestDoubles
136
+ test_files: []