minitest_httplog 0.2.0 → 0.3.0

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: 6ff02c4de4661d1a5d5df25a5127ce92295e7a222ed0a73ab894e594b995326b
4
- data.tar.gz: 9b2a45fb2162d25a64c00d6decc6aaee652fda88fe6258d01c5f9641d06f8d81
3
+ metadata.gz: 6b08a626237c7f9c86893ad915da4326d98f8daacf35fd8dcaa74d18aa11184f
4
+ data.tar.gz: 9cfff94b91a806937d178c1a6ca461b84d1315f3ee8f8ea1b7ae32299a3e5faa
5
5
  SHA512:
6
- metadata.gz: bc735417440a196a532a4ddb33e8cd6b83b8348b8f30db3eb5c192b73a632511cd8951c6f580f19549a54cfdd069e4b16f360c5582255eedd2d16cacf5ddebc5
7
- data.tar.gz: 39ba57880e054283350301d6eeb141b46351024c43b635fdac4de3c4e5a80efa8a6f8f860b309cc376ca16bdf7f74a05f88a8197e638bd3a6ea1c700915e877a
6
+ metadata.gz: a379a71fa3d7a2ebb2b2751973b3a6104489349894ee0bd73e5ec74eb4ee6ffb12a8cc17d312b87fdfc7d4ca704d94b79de4302b5bbc81878d2df927215b5244
7
+ data.tar.gz: 9487ce982a36a5391c859b8db2d3be5d377902d9e821baba7a7d70df22703dbf7109255d5f837a4c648da37f59e983a68ade7b31c3df0a541880db9095675d36
@@ -0,0 +1,11 @@
1
+ # To get started with Dependabot version updates, you'll need to specify which
2
+ # package ecosystems to update and where the package manifests are located.
3
+ # Please see the documentation for all configuration options:
4
+ # https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
5
+
6
+ version: 2
7
+ updates:
8
+ - package-ecosystem: "bundler" # See documentation for possible values
9
+ directory: "/" # Location of package manifests
10
+ schedule:
11
+ interval: "weekly"
data/.gitignore CHANGED
@@ -1,9 +1,69 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
1
+ *.rbc
2
+ capybara-*.html
3
+ .rspec
4
+ /db/*.sqlite3
5
+ /db/*.sqlite3-journal
6
+ /db/*.sqlite3-[0-9]*
7
+ /public/system
4
8
  /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
- *.gem
9
+ /spec/tmp
10
+ *.orig
11
+ rerun.txt
12
+ pickle-email-*.html
13
+
14
+ # Ignore all logfiles and tempfiles.
15
+ /log/*
16
+ /tmp/*
17
+ !/log/.keep
18
+ !/tmp/.keep
19
+
20
+ # TODO Comment out this rule if you are OK with secrets being uploaded to the repo
21
+ config/initializers/secret_token.rb
22
+ config/master.key
23
+
24
+ # Only include if you have production secrets in this file, which is no longer a Rails default
25
+ # config/secrets.yml
26
+
27
+ # dotenv, dotenv-rails
28
+ # TODO Comment out these rules if environment variables can be committed
29
+ .env
30
+ .env*.local
31
+
32
+ ## Environment normalization:
33
+ /.bundle
34
+ /vendor/bundle
35
+
36
+ # these should all be checked in to normalize the environment:
37
+ # Gemfile.lock, .ruby-version, .ruby-gemset
38
+
39
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
40
+ .rvmrc
41
+
42
+ # if using bower-rails ignore default bower_components path bower.json files
43
+ /vendor/assets/bower_components
44
+ *.bowerrc
45
+ bower.json
46
+
47
+ # Ignore pow environment settings
48
+ .powenv
49
+
50
+ # Ignore Byebug command history file.
51
+ .byebug_history
52
+
53
+ # Ignore node_modules
54
+ node_modules/
55
+
56
+ # Ignore precompiled javascript packs
57
+ /public/packs
58
+ /public/packs-test
59
+ /public/assets
60
+
61
+ # Ignore yarn files
62
+ /yarn-error.log
63
+ yarn-debug.log*
64
+ .yarn-integrity
65
+
66
+ # Ignore uploaded files in development
67
+ /storage/*
68
+ !/storage/.keep
69
+ /public/uploads
@@ -1,6 +1,6 @@
1
- The MIT License (MIT)
1
+ MIT License
2
2
 
3
- Copyright (c) 2024 Guilherme Stefanelli
3
+ Copyright (c) 2024 guinaldi
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -9,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
9
  copies of the Software, and to permit persons to whom the Software is
10
10
  furnished to do so, subject to the following conditions:
11
11
 
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
14
 
15
15
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
16
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
17
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,8 +1,13 @@
1
1
  # MinitestHttplog
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/minitest_httplog`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Ruby gem designed to detect unmocked HTTP requests during tests using [Minitest](https://github.com/seattlerb/minitest) and [HttpLog](https://github.com/trusche/httplog). It intercepts HTTP requests made during tests and logs failures if any unmocked requests are detected, ensuring all external calls are properly mocked, thus improving the reliability and predictability of tests.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ ## Features
6
+
7
+ * Automatic Detection: Automatically intercepts and detects all unmocked HTTP requests during tests.
8
+ * Minitest Integration: Logs failures in Minitest when an unmocked request is detected, ensuring the error is visible in test results.
9
+ * Detailed Logging: Logs detailed messages about unmocked requests, including the HTTP method, URI, and the test name.
10
+ * Easy Configuration: Simple configuration and conditional activation only in the test environment.
6
11
 
7
12
  ## Installation
8
13
 
@@ -22,13 +27,52 @@ Or install it yourself as:
22
27
 
23
28
  ## Usage
24
29
 
25
- TODO: Write usage instructions here
30
+ To use `minitest_httplog` in your tests, you need to require it in your test helper file. This gem will help you detect any unmocked HTTP requests in your tests.
31
+
32
+ Here's a simple example of how to use it:
33
+
34
+ 1. Add the following line to your test helper file:
35
+
36
+ ```ruby
37
+ require 'minitest/httplog'
38
+ ```
39
+
40
+ 2. Now, when you run your tests, `minitest_httplog` will raise an exception log on any HTTP requests and raise an error if they are not mocked.
41
+
42
+ ```console
43
+ Failure:
44
+ test [path]:
45
+ Unmocked HTTP request detected: POST http://test.url during test: test_
46
+ ```
47
+ ## Configuration
48
+
49
+ MinitestHttplog provides an option to ignore HTTP requests during specific test scenarios, such as when recording new VCR cassettes. This can be configured by setting the MinitestHttplog.ignore_requests attribute.
50
+
51
+ Example using VCR gem:
52
+
53
+ ```ruby
54
+ VCR.configure do |config|
55
+ config.cassette_library_dir = 'test/vcr_cassettes'
56
+ config.hook_into :webmock
57
+ config.ignore_localhost = true
58
+ config.allow_http_connections_when_no_cassette = false
59
+
60
+ # Configure VCR to ignore requests during recording
61
+ config.before_record do |i|
62
+ MinitestHttplog.ignore_requests = true
63
+ end
64
+
65
+ config.after_record do |i|
66
+ MinitestHttplog.ignore_requests = false
67
+ end
68
+ end
69
+ ```
26
70
 
27
71
  ## Development
28
72
 
29
73
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
74
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
75
+ To install this gem onto your local machine, run `bundle exec rake install`.
32
76
 
33
77
  ## Contributing
34
78
 
data/bin/console CHANGED
File without changes
data/bin/setup CHANGED
File without changes
@@ -1,3 +1,3 @@
1
1
  module MinitestHttplog
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -1,11 +1,12 @@
1
1
  require 'httplog'
2
2
  require 'minitest'
3
3
 
4
- module HttpLogMinitest
4
+ module MinitestHttplog
5
5
  class << self
6
- attr_accessor :current_test
6
+ attr_accessor :current_test, :ignore_requests
7
7
 
8
8
  def init
9
+ @ignore_requests = false
9
10
  HttpLog.configure do |config|
10
11
  config.logger = create_logger_decorator(config.logger)
11
12
  end
@@ -42,8 +43,8 @@ module HttpLogMinitest
42
43
  uri = extract_uri(message)
43
44
  method = extract_method(message)
44
45
 
45
- if uri && method
46
- full_message = "Unmocked HTTP request detected: #{method} #{uri} during test: #{HttpLogMinitest.current_test}"
46
+ if uri && method && !MinitestHttplog.ignore_requests
47
+ full_message = "Unmocked HTTP request detected: #{method} #{uri} during test: #{MinitestHttplog.current_test}"
47
48
 
48
49
  raise Minitest::Assertion, full_message
49
50
  end
@@ -64,16 +65,16 @@ module HttpLogMinitest
64
65
  end
65
66
  end
66
67
 
67
- HttpLogMinitest.init
68
+ MinitestHttplog.init
68
69
 
69
70
  module Minitest
70
71
  class Test
71
72
  alias_method :run_without_httplog, :run
72
73
 
73
74
  def run(*args, &block)
74
- HttpLogMinitest.current_test = self.name
75
+ MinitestHttplog.current_test = self.name
75
76
  result = run_without_httplog(*args, &block)
76
- HttpLogMinitest.current_test = nil
77
+ MinitestHttplog.current_test = nil
77
78
  result
78
79
  end
79
80
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minitest_httplog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guilherme Stefanelli
@@ -115,12 +115,12 @@ executables: []
115
115
  extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
+ - ".github/dependabot.yml"
118
119
  - ".gitignore"
119
- - ".travis.yml"
120
120
  - CODE_OF_CONDUCT.md
121
121
  - Gemfile
122
122
  - Gemfile.lock
123
- - LICENSE.txt
123
+ - LICENSE
124
124
  - README.md
125
125
  - Rakefile
126
126
  - bin/console
data/.travis.yml DELETED
@@ -1,6 +0,0 @@
1
- ---
2
- language: ruby
3
- cache: bundler
4
- rvm:
5
- - 2.7.6
6
- before_install: gem install bundler -v 2.1.4