oas_rails 0.2.1 → 0.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2424eec4c6a122256970ba124f71c0f5dfd9b4392875ac678d4868883cc233ae
4
- data.tar.gz: 182e2434b480920d8cabdd0899c96d48f6c7a69abe5432c33e27f4bc845f3a0c
3
+ metadata.gz: dff52d1f5445bbcd000de4c14988e919905c7e5ea1bd179b7ac7c458fde9570e
4
+ data.tar.gz: adba7ada7bc1658bf3b65f85731eef40c5f72ce930b3b087da5be23b4abd45a8
5
5
  SHA512:
6
- metadata.gz: f0437d44b6b053a3e95659ed43957d3455826ba2981f02140c23f323c5997434aa3c1adbe232188da55b6f62e3ff67e3c83a4a58d64973023555448f14ae964f
7
- data.tar.gz: 5f2edc1bc10dab27b4ff13c9a583bf73c3855dd65c06055dfd26b63d89034d607d5794cf331356b8759443b1a0e072cc0a96fbbc6260ea83641826c0ca66f96c
6
+ metadata.gz: 331be1bcbe64381095ab5f62b94154d394340740fe61a43c6463a544c8bc302ae2a89e30b30feedc698673ae4c7eca268b10d59b68e1f607b8eecfdb64917e9b
7
+ data.tar.gz: edfefc2472d3419045df61ce6ca9a37c48e87d61055b6225af54d7633c8cf08c0471ce15392967c564a866f1e24e322e10defed30ac05736d2b77bd1770fa629
@@ -20,23 +20,42 @@ module OasRails
20
20
  new(media_type: "", schema:, examples:)
21
21
  end
22
22
 
23
- def search_for_examples_in_tests(klass:)
24
- case Utils.detect_test_framework
23
+ # Searches for examples in test files based on the provided class and test framework.
24
+ #
25
+ # This method handles different test frameworks to fetch examples for the given class.
26
+ # Currently, it supports FactoryBot and fixtures.
27
+ #
28
+ # @param klass [Class] the class to search examples for.
29
+ # @param utils [Module] a utility module that provides the `detect_test_framework` method. Defaults to `Utils`.
30
+ # @return [Hash] a hash containing examples data or an empty hash if no examples are found.
31
+ # @example Usage with FactoryBot
32
+ # search_for_examples_in_tests(klass: User)
33
+ #
34
+ # @example Usage with fixtures
35
+ # search_for_examples_in_tests(klass: Project)
36
+ #
37
+ # @example Usage with a custom utils module
38
+ # custom_utils = Module.new do
39
+ # def self.detect_test_framework
40
+ # :factory_bot
41
+ # end
42
+ # end
43
+ # search_for_examples_in_tests(klass: User, utils: custom_utils)
44
+ def search_for_examples_in_tests(klass:, utils: Utils)
45
+ case utils.detect_test_framework
25
46
  when :factory_bot
26
47
  {}
27
48
  # TODO: create examples with FactoryBot
28
49
  when :fixtures
29
- # Handle fixtures scenario
30
50
  fixture_file = Rails.root.join('test', 'fixtures', "#{klass.to_s.pluralize.downcase}.yml")
31
- fixture_data = YAML.load_file(fixture_file).with_indifferent_access
32
51
 
33
- users_hash = {}
34
-
35
- # Convert the fixture data to a hash
36
- fixture_data.each do |name, attributes|
37
- users_hash[name] = { value: { klass.to_s.downcase => attributes } }
52
+ begin
53
+ fixture_data = YAML.load_file(fixture_file).with_indifferent_access
54
+ rescue Errno::ENOENT
55
+ return {}
38
56
  end
39
- users_hash
57
+
58
+ fixture_data.transform_values { |attributes| { value: { klass.to_s.downcase => attributes } } }
40
59
  else
41
60
  {}
42
61
  end
@@ -1,3 +1,3 @@
1
1
  module OasRails
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oas_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - a-chacon