mini_mock 0.0.1 → 0.0.3

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/mini_mock.rb +10 -15
  3. metadata +19 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9e96d52e166cf0503f9a5e09800f9aa87accf0ae89d649e3e7554afb4a619a46
4
- data.tar.gz: b320f3f91aca310659abb3391c8bac039b9b435797cbdd36e9626c3a66fd0a0b
3
+ metadata.gz: 24cd4f83e34603cf050cee2143661bcb855f050acbca63834c54e4853f4a3847
4
+ data.tar.gz: 9cddee347207daa3a42535e6b9ad3190205627496c4d4ee5338b4bb9395b52b3
5
5
  SHA512:
6
- metadata.gz: f3d2097d3ab1bc147126578f6495e4b300036e5c7ad1405cf346e2457a0c4c2f20c1d241b357edc231b1431fd7f3580d0732a9147e32bde8710292bf40a6b6d5
7
- data.tar.gz: 758fa946b59033b18e7d42dc97c0dba27b574a4d725944d0ce65fa853092c26696739396a70e1ee78fb47707431fb8d954693f6f66ac2212690186411f536f6a
6
+ metadata.gz: f6caa16053e2f77fd847e573d9ffd5b490423482570754e2c7f49d96b172ae310c42eccf7b9c9367fe8d6c4c67100357382db8796358ac3a983db4cdd38d15af
7
+ data.tar.gz: c7fd27ab84f6e09b2dc5a1ea9aee089a4e55b17cd0bcb09c3aab95c11856be037c1d81ef118e99ea4a4199c500d3a033b170edfc51ee7fd9290113eecdf8fd04
data/lib/mini_mock.rb CHANGED
@@ -1,10 +1,10 @@
1
+ require "typhoeus"
1
2
  class MiniMock
2
- RECORDINGS_PATH = 'mini_mock'
3
+ RECORDINGS_PATH = "mini_mock"
3
4
  DEFAULT_FILE = "mocks"
4
5
 
5
6
  class << self
6
-
7
- def record file_name=DEFAULT_FILE
7
+ def record file_name = DEFAULT_FILE
8
8
  FileUtils.mkdir_p(RECORDINGS_PATH)
9
9
  @@file_name = file_name
10
10
  Typhoeus::Config.block_connection = false
@@ -12,7 +12,7 @@ class MiniMock
12
12
  true
13
13
  end
14
14
 
15
- def replay file_name=DEFAULT_FILE
15
+ def replay file_name = DEFAULT_FILE
16
16
  Typhoeus::Config.block_connection = true
17
17
  remove_callback
18
18
  load "#{RECORDINGS_PATH}/#{file_name}.rb"
@@ -21,11 +21,13 @@ class MiniMock
21
21
 
22
22
  def off
23
23
  Typhoeus::Config.block_connection = false
24
+ Typhoeus::Expectation.clear
24
25
  remove_callback
25
26
  true
26
27
  end
27
28
 
28
29
  private
30
+
29
31
  def add_callback
30
32
  unless Typhoeus.on_complete.include?(AFTER_REQUEST_CALLBACK)
31
33
  Typhoeus.on_complete << AFTER_REQUEST_CALLBACK
@@ -33,26 +35,19 @@ class MiniMock
33
35
  end
34
36
 
35
37
  def remove_callback
36
- Typhoeus.on_complete.delete_if {|v| v == AFTER_REQUEST_CALLBACK }
38
+ Typhoeus.on_complete.delete_if { |v| v == AFTER_REQUEST_CALLBACK }
37
39
  end
38
-
39
40
  end
40
41
 
41
- AFTER_REQUEST_CALLBACK = Proc.new do |response|
42
+ AFTER_REQUEST_CALLBACK = proc do |response|
42
43
  code = <<~RUBY
43
44
  response = Typhoeus::Response.new(
44
- code: #{response.code},
45
- status_message: "#{response.status_message}",
46
- body: #{response.body.inspect},
47
- headers: #{response.headers},
48
- effective_url: #{response.effective_url.inspect},
49
- options: #{response.options.tap{|a| a[:debug_info] = ""}.inspect}
45
+ #{response.options.except(:debug_info).inspect}
50
46
  )
51
47
  Typhoeus.stub(#{response.request.base_url.inspect}, #{response.request.original_options})
52
48
  .and_return(response)
53
49
 
54
50
  RUBY
55
- File.write "#{RECORDINGS_PATH}/#{@@file_name}.rb", code, mode: 'a+'
51
+ File.write "#{RECORDINGS_PATH}/#{@@file_name}.rb", code, mode: "a+"
56
52
  end
57
-
58
53
  end
metadata CHANGED
@@ -1,16 +1,28 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mini_mock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felipe Mesquita
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2023-03-12 00:00:00.000000000 Z
12
- dependencies: []
13
- description:
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: typhoeus
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
14
26
  email: felipemesquita@hey.com
15
27
  executables: []
16
28
  extensions: []
@@ -21,7 +33,6 @@ homepage: https://github.com/felipedmesquita/mini_mock
21
33
  licenses:
22
34
  - MIT
23
35
  metadata: {}
24
- post_install_message:
25
36
  rdoc_options: []
26
37
  require_paths:
27
38
  - lib
@@ -36,8 +47,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
36
47
  - !ruby/object:Gem::Version
37
48
  version: '0'
38
49
  requirements: []
39
- rubygems_version: 3.3.3
40
- signing_key:
50
+ rubygems_version: 3.6.9
41
51
  specification_version: 4
42
- summary: Record and replay Typhoeus requests
52
+ summary: Record and replay requests using Typhoeus built-in stubbing functionality.
43
53
  test_files: []