servactory 2.9.0.rc6 → 2.9.0.rc8

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: c6a762f7cbe5f9ac88c14ef817109ee6b1e1f29e4c404ddd73b20520fd48705e
4
- data.tar.gz: 1205b74201b08c5191813f9c02e5da954609d20d66d9bbdb7815bbfeaa01a4c6
3
+ metadata.gz: cbd8f1aab15e1cfd99b746c96f357f075b15e494490ea4bcae946545b76b5e5b
4
+ data.tar.gz: 896768b2f5b685940ca50d40914a3ab5059f11c35d6b4d284daf2ca4e6cdfc17
5
5
  SHA512:
6
- metadata.gz: c3a02731634fa02a71318580051704310519fcbbee287ecadfa15f31ae567e4015b08d30cfb30513d4a21df75a5457a22aec22a4afc46350401c5f1a43dda5fc
7
- data.tar.gz: 6e157f714eab85943554d2a02a061b82b681c85ce1b1dcaab396d0f67e209db7ab40c334047cb849b500be1d8794f02d73e1d93267d3c27f1707ca3f522f250e
6
+ metadata.gz: 6ee297769b7a30216bb9e3cde31701a3660090cd3229510de6f632a5c350e007e90ff6c8920168d181a7551a101443e7c17e19c5858c8d16c814f31a74c27b15
7
+ data.tar.gz: c5a5ff1006fe27c33651546e6b42eb7e936dcbaacfb96034eeaa65f20800e43e1c17fe4317f26100864ebec51cdc9089e77114673f61cf8720ae614883aa7f88
@@ -4,36 +4,36 @@ module Servactory
4
4
  module TestKit
5
5
  module Rspec
6
6
  module Helpers
7
- def allow_service_as_success!(service_class_name, &block)
8
- allow_service!(service_class_name, :as_success, &block)
7
+ def allow_service_as_success!(service_class, with: nil, &block)
8
+ allow_service!(service_class, :as_success, with:, &block)
9
9
  end
10
10
 
11
- def allow_service_as_success(service_class_name, &block)
12
- allow_service(service_class_name, :as_success, &block)
11
+ def allow_service_as_success(service_class, with: nil, &block)
12
+ allow_service(service_class, :as_success, with:, &block)
13
13
  end
14
14
 
15
- def allow_service_as_failure!(service_class_name, &block)
16
- allow_service!(service_class_name, :as_failure, &block)
15
+ def allow_service_as_failure!(service_class, with: nil, &block)
16
+ allow_service!(service_class, :as_failure, with:, &block)
17
17
  end
18
18
 
19
- def allow_service_as_failure(service_class_name, &block)
20
- allow_service(service_class_name, :as_failure, &block)
19
+ def allow_service_as_failure(service_class, with: nil, &block)
20
+ allow_service(service_class, :as_failure, with:, &block)
21
21
  end
22
22
 
23
23
  ########################################################################
24
24
 
25
- def allow_service!(service_class_name, result_type, &block)
26
- allow_servactory(service_class_name, :call!, result_type, &block)
25
+ def allow_service!(service_class, result_type, with: nil, &block)
26
+ allow_servactory(service_class, :call!, result_type, with:, &block)
27
27
  end
28
28
 
29
- def allow_service(service_class_name, result_type, &block)
30
- allow_servactory(service_class_name, :call, result_type, &block)
29
+ def allow_service(service_class, result_type, with: nil, &block)
30
+ allow_servactory(service_class, :call, result_type, with:, &block)
31
31
  end
32
32
 
33
33
  ########################################################################
34
34
 
35
35
  # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
36
- def allow_servactory(service_class_name, method_call, result_type)
36
+ def allow_servactory(service_class, method_call, result_type, with: nil)
37
37
  method_call = method_call.to_sym
38
38
  result_type = result_type.to_sym
39
39
 
@@ -66,7 +66,7 @@ module Servactory
66
66
 
67
67
  # puts
68
68
  # puts <<~RUBY
69
- # allow(#{service_class_name}).to(
69
+ # allow(#{service_class}).to(
70
70
  # receive(#{method_call.inspect})
71
71
  # .public_send(
72
72
  # #{and_return_or_raise.inspect},
@@ -76,8 +76,17 @@ module Servactory
76
76
  # RUBY
77
77
  # puts
78
78
 
79
- allow(service_class_name).to(
79
+ allow(service_class).to(
80
80
  receive(method_call)
81
+ .with(
82
+ if with.present?
83
+ with
84
+ elsif (input_names = service_class.info.inputs.keys).present?
85
+ input_names.to_h { |input_name| [input_name, anything] }
86
+ else
87
+ no_args
88
+ end
89
+ )
81
90
  .public_send(
82
91
  and_return_or_raise,
83
92
  if as_success
@@ -38,7 +38,7 @@ module Servactory
38
38
  @nested = values
39
39
  end
40
40
 
41
- chain :with do |value|
41
+ chain :contains do |value|
42
42
  @value = value
43
43
  end
44
44
 
@@ -50,6 +50,12 @@ module Servactory
50
50
  def match_for(actual, output_name)
51
51
  given_value = actual.public_send(output_name)
52
52
 
53
+ if defined?(@instance_of)
54
+ expect(given_value).to(
55
+ RSpec::Matchers::BuiltIn::BeAnInstanceOf.new(@instance_of)
56
+ )
57
+ end
58
+
53
59
  if defined?(@nested) && @nested.present?
54
60
  @nested.each do |method_name|
55
61
  next unless given_value.respond_to?(method_name)
@@ -58,16 +64,17 @@ module Servactory
58
64
  end
59
65
  end
60
66
 
67
+ return true if !defined?(@value) && @value.nil?
68
+
61
69
  expect(given_value).to(
62
- if defined?(@instance_of)
63
- RSpec::Matchers::BuiltIn::BeAnInstanceOf.new(@instance_of)
64
- elsif @value.is_a?(Array)
70
+ case @value
71
+ when Array
65
72
  RSpec::Matchers::BuiltIn::ContainExactly.new(@value)
66
- elsif @value.is_a?(Hash)
73
+ when Hash
67
74
  RSpec::Matchers::BuiltIn::Match.new(@value)
68
- elsif @value.is_a?(TrueClass) || @value.is_a?(FalseClass)
75
+ when TrueClass, FalseClass
69
76
  RSpec::Matchers::BuiltIn::Equal.new(@value)
70
- elsif @value.is_a?(NilClass)
77
+ when NilClass
71
78
  RSpec::Matchers::BuiltIn::BeNil.new(@value)
72
79
  else
73
80
  RSpec::Matchers::BuiltIn::Eq.new(@value)
@@ -5,7 +5,7 @@ module Servactory
5
5
  MAJOR = 2
6
6
  MINOR = 9
7
7
  PATCH = 0
8
- PRE = "rc6"
8
+ PRE = "rc8"
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH, PRE].compact.join(".")
11
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: servactory
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.9.0.rc6
4
+ version: 2.9.0.rc8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Sokolov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-13 00:00:00.000000000 Z
11
+ date: 2024-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport