1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553
|
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
File: README
— Documentation by YARD 0.9.37
</title>
<link rel="stylesheet" href="css/style.css" type="text/css" />
<link rel="stylesheet" href="css/common.css" type="text/css" />
<script type="text/javascript">
pathId = "README";
relpath = '';
</script>
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
</head>
<body>
<div class="nav_wrap">
<iframe id="nav" src="class_list.html?1"></iframe>
<div id="resizer"></div>
</div>
<div id="main" tabindex="-1">
<div id="header">
<div id="menu">
<a href="_index.html">Index</a> »
<span class="title">File: README</span>
</div>
<div id="search">
<a class="full_list_link" id="class_list_link"
href="class_list.html">
<svg width="24" height="24">
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
</svg>
</a>
</div>
<div class="clear"></div>
</div>
<div id="content"><div id='filecontents'><p><a href="https://github.com/galtzo-floss"><img src="https://logos.galtzo.com/assets/images/galtzo-floss/avatar-192px.svg" alt="Galtzo FLOSS Logo by Aboling0, CC BY-SA 4.0"></a> <a href="https://github.com/rspec"><img src="https://logos.galtzo.com/assets/images/rspec/avatar-192px.svg" alt="rspec Logo by Ninefold, a Macquarie Telecom company, CC BY-NC-SA 4.0"></a> <a href="https://github.com/ruby-lang"><img src="https://logos.galtzo.com/assets/images/ruby-lang/avatar-192px.svg" alt="ruby-lang Logo, Yukihiro Matsumoto, Ruby Visual Identity Team, CC BY-SA 2.5"></a> <a href="https://github.com/galtzo-floss/rspec-stubbed_env"><img src="https://logos.galtzo.com/assets/images/galtzo-floss/rspec-stubbed_env/avatar-192px.svg" alt="rspec-stubbed_env Logo by Aboling0, CC BY-SA 4.0"></a></p>
<h1 id="-rspecstubbedenv">🫥 RSpec::StubbedEnv</h1>
<p><a href="https://rubygems.org/gems/rspec-stubbed_env"><img src="https://img.shields.io/gem/v/rspec-stubbed_env.svg" alt="Version"></a> <a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-259D6C.svg" alt="License: MIT"></a> <a href="https://rubygems.org/gems/rspec-stubbed_env"><img src="https://img.shields.io/gem/rd/rspec-stubbed_env.svg" alt="Downloads Rank"></a> <a href="https://www.codetriage.com/galtzo-floss/rspec-stubbed_env"><img src="https://www.codetriage.com/galtzo-floss/rspec-stubbed_env/badges/users.svg" alt="Open Source Helpers"></a> <a href="https://depfu.com/github/galtzo-floss/rspec-stubbed_env?project_id=5884"><img src="https://badges.depfu.com/badges/a48948dd503f23a440f2c17910563f43/count.svg" alt="Depfu"></a> <a href="https://coveralls.io/github/galtzo-floss/rspec-stubbed_env?branch=main"><img src="https://coveralls.io/repos/github/galtzo-floss/rspec-stubbed_env/badge.svg?branch=main" alt="Coveralls Test Coverage"></a> <a href="https://codecov.io/gh/galtzo-floss/rspec-stubbed_env"><img src="https://codecov.io/gh/galtzo-floss/rspec-stubbed_env/graph/badge.svg?token=hRnUCPqxMu" alt="CodeCov Test Coverage"></a> <a href="https://qlty.sh/gh/galtzo-floss/projects/rspec-stubbed_env/metrics/code?sort=coverageRating"><img src="https://qlty.sh/gh/galtzo-floss/projects/rspec-stubbed_env/coverage.svg" alt="QLTY Test Coverage"></a> <a href="https://qlty.sh/gh/galtzo-floss/projects/rspec-stubbed_env"><img src="https://qlty.sh/gh/galtzo-floss/projects/rspec-stubbed_env/maintainability.svg" alt="QLTY Maintainability"></a> <a href="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/heads.yml"><img src="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/heads.yml/badge.svg" alt="CI Heads"></a> <a href="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/current.yml"><img src="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/current.yml/badge.svg" alt="CI Current"></a> <a href="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/truffle.yml"><img src="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/truffle.yml/badge.svg" alt="CI Truffle Ruby"></a> <a href="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/jruby.yml"><img src="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/jruby.yml/badge.svg" alt="CI JRuby"></a> <a href="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/deps_locked.yml"><img src="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/deps_locked.yml/badge.svg" alt="Deps Locked"></a> <a href="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/deps_unlocked.yml"><img src="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/deps_unlocked.yml/badge.svg" alt="Deps Unlocked"></a> <a href="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/supported.yml"><img src="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/supported.yml/badge.svg" alt="CI Supported"></a> <a href="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/legacy.yml"><img src="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/legacy.yml/badge.svg" alt="CI Legacy"></a> <a href="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/unsupported.yml"><img src="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/unsupported.yml/badge.svg" alt="CI Unsupported"></a> <a href="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/ancient.yml"><img src="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/ancient.yml/badge.svg" alt="CI Ancient"></a> <a href="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/coverage.yml"><img src="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/coverage.yml/badge.svg" alt="CI Test Coverage"></a> <a href="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/style.yml"><img src="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/style.yml/badge.svg" alt="CI Style"></a></p>
<hr>
<p><a href="https://liberapay.com/pboling/donate"><img src="https://img.shields.io/liberapay/goal/pboling.svg?logo=liberapay" alt="Liberapay Goal Progress"></a> <a href="https://github.com/sponsors/pboling"><img src="https://img.shields.io/badge/Sponsor_Me!-pboling.svg?style=social&logo=github" alt="Sponsor Me on Github"></a> <a href="https://www.buymeacoffee.com/pboling"><img src="https://img.shields.io/badge/buy_me_a_coffee-%E2%9C%93-yellow.svg?style=flat" alt="Buy me a coffee"></a> <a href="https://polar.sh/pboling"><img src="https://img.shields.io/badge/polar-donate-yellow.svg" alt="Donate on Polar"></a> <a href="https://ko-fi.com/O5O86SNP4"><img src="https://img.shields.io/badge/a_more_different_coffee-%E2%9C%93-yellow.svg" alt="Donate to my FLOSS or refugee efforts at ko-fi.com"></a> <a href="https://patreon.com/galtzo"><img src="https://img.shields.io/badge/patreon-donate-yellow.svg" alt="Donate to my FLOSS or refugee efforts using Patreon"></a></p>
<h2 id="-synopsis">🌻 Synopsis</h2>
<p>An <code>ENV</code> stubbing / hiding library for sophisticated RSpec test suites.</p>
<ul>
<li>ENV stubbing and hiding via shared contexts for more powerful tests
<ul>
<li>ENV hiding via <code>hide_env("FOO")</code> was added in v1.0.2</li>
</ul>
</li>
<li>No need to add <code>dotenv</code> just for the spec suite</li>
</ul>
<pre class="code language-ruby"><code class="language-ruby">describe "my stubbed test" do
include_context "with stubbed env"
include_context "with hidden env"
context "with FOO=is bar" do
before do
stub_env("FOO" => "is bar")
end
it "has a value" do
expect(ENV.fetch("FOO", nil)).to(eq("is bar"))
expect(ENV.fetch("FOO")).to(eq("is bar"))
expect(ENV["FOO"]).to(eq("is bar"))
end
end
context "without BAR set" do
before do
hide_env("BAR")
end
it "is nil" do
expect(ENV.fetch("BAR", nil)).to(be_nil)
expect(ENV["BAR"]).to(be_nil)
end
it "raises error" do
expect { ENV.fetch("BAR") }.to(raise_error(KeyNotFound))
end
end
end
</code></pre>
<p>This gem has no runtime dependencies.</p>
<h2 id="-info-you-can-shake-a-stick-at">💡 Info you can shake a stick at</h2>
<h3 id="federated-dvcs">Federated DVCS</h3>
<details>
<summary>Find this repo on other forges</summary>
| Federated [DVCS][💎d-in-dvcs] Repository | Status | Issues | PRs | Wiki | CI | Discussions |
|--------------------------------------------------------|-------------------------------------------------------------------|---------------------------|--------------------------|---------------------------|--------------------------|------------------------------|
| 🧪 [galtzo-floss/rspec-stubbed_env on GitLab][📜src-gl] | The Truth | [💚][🤝gl-issues] | [💚][🤝gl-pulls] | [💚][📜wiki] | 🏀 Tiny Matrix | ➖ |
| 🧊 [galtzo-floss/rspec-stubbed_env on CodeBerg][📜src-cb] | An Ethical Mirror ([Donate][🤝cb-donate]) | [💚][🤝cb-issues] | [💚][🤝cb-pulls] | ➖ | ⭕️ No Matrix | ➖ |
| 🐙 [galtzo-floss/rspec-stubbed_env on GitHub][📜src-gh] | A Dirty Mirror | [💚][🤝gh-issues] | [💚][🤝gh-pulls] | ➖ | 💯 Full Matrix | [💚][gh-discussions] |
| 🎮️ [Discord Server][✉️discord-invite] | [![Live Chat on Discord][✉️discord-invite-img]][✉️discord-invite] | [Let's][✉️discord-invite] | [talk][✉️discord-invite] | [about][✉️discord-invite] | [this][✉️discord-invite] | [library!][✉️discord-invite] |
</details>
<h3 id="enterprise-support">Enterprise Support</h3>
<details>
<summary>Need enterprise-level guarantees?</summary>
[![Get help from me on Tidelift][🏙️entsup-tidelift-img]][🏙️entsup-tidelift]
- 💡Subscribe for support guarantees covering _all_ FLOSS dependencies
- 💡Tidelift is part of [Sonar][🏙️entsup-tidelift-sonar]
- 💡Tidelift pays maintainers to maintain the software you depend on!<br>📊`@`Pointy Haired Boss: An [enterprise support][🏙️entsup-tidelift] subscription is "[never gonna let you down][🧮kloc]", and *supports* open source maintainers
Alternatively:
- [![Live Chat on Discord][✉️discord-invite-img]][✉️discord-invite]
- [![Get help from me on Upwork][👨🏼🏫expsup-upwork-img]][👨🏼🏫expsup-upwork]
- [![Get help from me on Codementor][👨🏼🏫expsup-codementor-img]][👨🏼🏫expsup-codementor]
</details>
<table>
<thead>
<tr>
<th>Tokens to Remember</th>
<th>
<a href="https://rubygems.org/gems/rspec-stubbed_env"><img src="https://img.shields.io/badge/name-rspec--stubbed__env-brightgreen.svg?style=flat&logo=rubygems&logoColor=red" alt="Gem name"></a> <a href="https://github.com/galtzo-floss/rspec-stubbed_env"><img src="https://img.shields.io/badge/namespace-RSpec%3A%3AStubbedEnv-brightgreen.svg?style=flat&logo=ruby&logoColor=white" alt="Gem namespace"></a>
</th>
</tr>
</thead>
<tbody>
<tr>
<td>Works with JRuby</td>
<td>
<a href="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/jruby.yml"><img src="https://img.shields.io/badge/JRuby-9.1-FBE742?style=for-the-badge&logo=ruby&logoColor=red" alt="JRuby 9.1 Compat"></a> <a href="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/jruby.yml"><img src="https://img.shields.io/badge/JRuby-9.2-FBE742?style=for-the-badge&logo=ruby&logoColor=red" alt="JRuby 9.2 Compat"></a> <a href="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/jruby.yml"><img src="https://img.shields.io/badge/JRuby-9.3-FBE742?style=for-the-badge&logo=ruby&logoColor=red" alt="JRuby 9.3 Compat"></a> <a href="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/jruby.yml"><img src="https://img.shields.io/badge/JRuby-9.4-FBE742?style=for-the-badge&logo=ruby&logoColor=red" alt="JRuby 9.4 Compat"></a> <a href="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/current.yml"><img src="https://img.shields.io/badge/JRuby-current-FBE742?style=for-the-badge&logo=ruby&logoColor=green" alt="JRuby 10.0 Compat"></a> <a href="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/heads.yml"><img src="https://img.shields.io/badge/JRuby-HEAD-FBE742?style=for-the-badge&logo=ruby&logoColor=blue" alt="JRuby HEAD Compat"></a>
</td>
</tr>
<tr>
<td>Works with Truffle Ruby</td>
<td>
<a href="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/truffle.yml"><img src="https://img.shields.io/badge/Truffle_Ruby-22.3-34BCB1?style=for-the-badge&logo=ruby&logoColor=pink" alt="Truffle Ruby 22.3 Compat"></a> <a href="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/truffle.yml"><img src="https://img.shields.io/badge/Truffle_Ruby-23.0-34BCB1?style=for-the-badge&logo=ruby&logoColor=pink" alt="Truffle Ruby 23.0 Compat"></a> <a href="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/truffle.yml"><img src="https://img.shields.io/badge/Truffle_Ruby-23.1-34BCB1?style=for-the-badge&logo=ruby&logoColor=pink" alt="Truffle Ruby 23.1 Compat"></a> <a href="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/current.yml"><img src="https://img.shields.io/badge/Truffle_Ruby-current-34BCB1?style=for-the-badge&logo=ruby&logoColor=green" alt="Truffle Ruby 24.1 Compat"></a>
</td>
</tr>
<tr>
<td>Works with MRI Ruby 3</td>
<td>
<a href="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/legacy.yml"><img src="https://img.shields.io/badge/Ruby-3.0-CC342D?style=for-the-badge&logo=ruby&logoColor=white" alt="Ruby 3.0 Compat"></a> <a href="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/supported.yml"><img src="https://img.shields.io/badge/Ruby-3.1-CC342D?style=for-the-badge&logo=ruby&logoColor=white" alt="Ruby 3.1 Compat"></a> <a href="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/supported.yml"><img src="https://img.shields.io/badge/Ruby-3.2-CC342D?style=for-the-badge&logo=ruby&logoColor=white" alt="Ruby 3.2 Compat"></a> <a href="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/supported.yml"><img src="https://img.shields.io/badge/Ruby-3.3-CC342D?style=for-the-badge&logo=ruby&logoColor=white" alt="Ruby 3.3 Compat"></a> <a href="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/current.yml"><img src="https://img.shields.io/badge/Ruby-current-CC342D?style=for-the-badge&logo=ruby&logoColor=green" alt="Ruby 3.4 Compat"></a> <a href="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/heads.yml"><img src="https://img.shields.io/badge/Ruby-HEAD-CC342D?style=for-the-badge&logo=ruby&logoColor=blue" alt="Ruby HEAD Compat"></a>
</td>
</tr>
<tr>
<td>Works with MRI Ruby 2</td>
<td>
<a href="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/ancient.yml"><img src="https://img.shields.io/badge/Ruby-2.3-DF00CA?style=for-the-badge&logo=ruby&logoColor=white" alt="Ruby 2.3 Compat"></a> <a href="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/ancient.yml"><img src="https://img.shields.io/badge/Ruby-2.4-DF00CA?style=for-the-badge&logo=ruby&logoColor=white" alt="Ruby 2.4 Compat"></a> <a href="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/ancient.yml"><img src="https://img.shields.io/badge/Ruby-2.5-DF00CA?style=for-the-badge&logo=ruby&logoColor=white" alt="Ruby 2.5 Compat"></a> <a href="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/unsupported.yml"><img src="https://img.shields.io/badge/Ruby-2.6-DF00CA?style=for-the-badge&logo=ruby&logoColor=white" alt="Ruby 2.6 Compat"></a> <a href="https://github.com/galtzo-floss/rspec-stubbed_env/actions/workflows/unsupported.yml"><img src="https://img.shields.io/badge/Ruby-2.7-DF00CA?style=for-the-badge&logo=ruby&logoColor=white" alt="Ruby 2.7 Compat"></a>
</td>
</tr>
<tr>
<td>Source</td>
<td>
<a href="https://gitlab.com/galtzo-floss/rspec-stubbed_env/"><img src="https://img.shields.io/badge/GitLab-FBA326?style=for-the-badge&logo=Gitlab&logoColor=orange" alt="Source on GitLab.com"></a> <a href="https://codeberg.org/galtzo-floss/rspec-stubbed_env"><img src="https://img.shields.io/badge/CodeBerg-4893CC?style=for-the-badge&logo=CodeBerg&logoColor=blue" alt="Source on CodeBerg.org"></a> <a href="https://github.com/galtzo-floss/rspec-stubbed_env"><img src="https://img.shields.io/badge/GitHub-238636?style=for-the-badge&logo=Github&logoColor=green" alt="Source on Github.com"></a> <a href="https://www.youtube.com/watch?v=dQw4w9WgXcQ"><img src="https://img.shields.io/badge/KLOC-0.073-FFDD67.svg?style=for-the-badge&logo=YouTube&logoColor=blue" alt="The best SHA: dQw4w9WgXcQ!"></a>
</td>
</tr>
<tr>
<td>Documentation</td>
<td>
<a href="http://rubydoc.info/gems/rspec-stubbed_env"><img src="https://img.shields.io/badge/RubyDoc-Current_Release-943CD2?style=for-the-badge&logo=readthedocs&logoColor=white" alt="Current release on RubyDoc.info"></a> <a href="https://rspec-stubbed-env.galtzo.com"><img src="https://img.shields.io/badge/YARD_on_Galtzo.com-HEAD-943CD2?style=for-the-badge&logo=readthedocs&logoColor=white" alt="YARD on Galtzo.com"></a> <a href="http://www.railsbling.com/tags/rspec-stubbed_env"><img src="https://img.shields.io/badge/blog-railsbling-0093D0.svg?style=for-the-badge&logo=rubyonrails&logoColor=orange" alt="BDFL Blog"></a> <a href="https://gitlab.com/galtzo-floss/rspec-stubbed_env/-/wikis/home"><img src="https://img.shields.io/badge/wiki-examples-943CD2.svg?style=for-the-badge&logo=Wiki&logoColor=white" alt="Wiki"></a>
</td>
</tr>
<tr>
<td>Compliance</td>
<td>
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-259D6C.svg" alt="License: MIT"></a> <a href="https://www.ilo.org/declaration/lang--en/index.htm"><img src="https://img.shields.io/badge/ILO_Fundamental_Principles-%E2%9C%93-259D6C.svg?style=flat" alt="📄ilo-declaration-img"></a> <a href="file.SECURITY.html" title="<img src="https://img.shields.io/badge/security-policy-259D6C.svg?style=flat" alt="Security Policy">"><img src="https://img.shields.io/badge/security-policy-259D6C.svg?style=flat" alt="Security Policy"></a> <a href="file.CODE_OF_CONDUCT.html" title="<img src="https://img.shields.io/badge/Contributor_Covenant-2.1-259D6C.svg" alt="Contributor Covenant 2.1">"><img src="https://img.shields.io/badge/Contributor_Covenant-2.1-259D6C.svg" alt="Contributor Covenant 2.1"></a> <a href="https://semver.org/spec/v2.0.0.html"><img src="https://img.shields.io/badge/semver-2.0.0-259D6C.svg?style=flat" alt="SemVer 2.0.0"></a>
</td>
</tr>
<tr>
<td>Style</td>
<td>
<a href="https://github.com/rubocop-lts/rubocop-lts"><img src="https://img.shields.io/badge/code_style_%26_linting-rubocop--lts-34495e.svg?plastic&logo=ruby&logoColor=white" alt="Enforced Code Style Linter"></a> <a href="https://keepachangelog.com/en/1.0.0/"><img src="https://img.shields.io/badge/keep--a--changelog-1.0.0-34495e.svg?style=flat" alt="Keep-A-Changelog 1.0.0"></a> <a href="https://gitmoji.dev"><img src="https://img.shields.io/badge/gitmoji_commits-%20%F0%9F%98%9C%20%F0%9F%98%8D-34495e.svg?style=flat-square" alt="Gitmoji Commits"></a>
</td>
</tr>
<tr>
<td>Support</td>
<td>
<a href="https://discord.gg/3qme4XHNKN"><img src="https://img.shields.io/discord/1373797679469170758?style=for-the-badge" alt="Live Chat on Discord"></a> <a href="https://www.upwork.com/freelancers/~014942e9b056abdf86?mp_source=share"><img src="https://img.shields.io/badge/UpWork-13544E?style=for-the-badge&logo=Upwork&logoColor=white" alt="Get help from me on Upwork"></a> <a href="https://www.codementor.io/peterboling?utm_source=github&utm_medium=button&utm_term=peterboling&utm_campaign=github"><img src="https://img.shields.io/badge/CodeMentor-Get_Help-1abc9c?style=for-the-badge&logo=CodeMentor&logoColor=white" alt="Get help from me on Codementor"></a>
</td>
</tr>
<tr>
<td>Comrade BDFL 🎖️</td>
<td>
<a href="http://www.linkedin.com/in/peterboling"><img src="https://img.shields.io/badge/PeterBoling-LinkedIn-0B66C2?style=flat&logo=newjapanprowrestling" alt="Follow Me on LinkedIn"></a> <a href="https://ruby.social/@galtzo"><img src="https://img.shields.io/mastodon/follow/109447111526622197?domain=https%3A%2F%2Fruby.social&style=flat&logo=mastodon&label=Ruby%20%40galtzo" alt="Follow Me on Ruby.Social"></a> <a href="https://bsky.app/profile/galtzo.com"><img src="https://img.shields.io/badge/@galtzo.com-0285FF?style=flat&logo=bluesky&logoColor=white" alt="Follow Me on Bluesky"></a> <a href="http://www.railsbling.com/contact"><img src="https://img.shields.io/badge/Contact-BDFL-0093D0.svg?style=flat&logo=rubyonrails&logoColor=red" alt="Contact BDFL"></a> <a href="https://dev.to/galtzo"><img src="https://img.shields.io/badge/dev.to-0A0A0A?style=flat&logo=devdotto&logoColor=white" alt="My technical writing"></a>
</td>
</tr>
<tr>
<td>
<code>...</code> 💖</td>
<td>
<a href="https://angel.co/u/peter-boling"><img src="https://img.shields.io/badge/peter--boling-orange?style=flat&logo=wellfound" alt="Find Me on WellFound:"></a> <a href="https://www.crunchbase.com/person/peter-boling"><img src="https://img.shields.io/badge/peter--boling-purple?style=flat&logo=crunchbase" alt="Find Me on CrunchBase"></a> <a href="https://linktr.ee/galtzo"><img src="https://img.shields.io/badge/galtzo-purple?style=flat&logo=linktree" alt="My LinkTree"></a> <a href="https://about.me/peter.boling"><img src="https://img.shields.io/badge/about.me-0A0A0A?style=flat&logo=aboutme&logoColor=white" alt="More About Me"></a> <a href="https://codeberg.org/pboling">🧊</a> <a href="https://github.org/pboling">🐙</a> <a href="https://sr.ht/~galtzo/">🛖</a> <a href="https://gitlab.com/pboling">🧪</a>
</td>
</tr>
</tbody>
</table>
<h2 id="-installation">✨ Installation</h2>
<p>Install the gem and add to the application’s Gemfile by executing:</p>
<pre class="code ruby"><code class="ruby">$ bundle add rspec-stubbed_env
</code></pre>
<p>If bundler is not being used to manage dependencies, install the gem by executing:</p>
<pre class="code ruby"><code class="ruby">$ gem install rspec-stubbed_env
</code></pre>
<h3 id="-secure-installation">🔒 Secure Installation</h3>
<details>
<summary>For Medium or High Security Installations</summary>
`rspec-stubbed_env` is cryptographically signed, and has verifiable [SHA-256 and SHA-512][💎SHA_checksums] checksums by
[stone_checksums][💎stone_checksums]. Be sure the gem you install hasn’t been tampered with
by following the instructions below.
Add my public key (if you haven’t already, expires 2045-04-29) as a trusted certificate:
```console
gem cert --add <(curl -Ls https://raw.github.com/galtzo-floss/certs/main/pboling.pem)
```
You only need to do that once. Then proceed to install with:
```console
gem install rspec-stubbed_env -P HighSecurity
```
The `HighSecurity` trust profile will verify signed gems, and not allow the installation of unsigned dependencies.
If you want to up your security game full-time:
```console
bundle config set --global trust-policy MediumSecurity
```
`MediumSecurity` instead of `HighSecurity` is necessary if not all the gems you use are signed.
NOTE: Be prepared to track down certs for signed gems and add them the same way you added mine.
</details>
<h2 id="-basic-usage">🔧 Basic Usage</h2>
<p>You must configure RSpec to use the <code>:expect</code> syntax, or some compatible alternative.</p>
<pre class="code language-ruby"><code class="language-ruby">RSpec.configure do |config|
config.expect_with(:rspec) do |c|
c.syntax = :expect
end
end
</code></pre>
<p>Require the library in your spec/test helper somewhere:</p>
<pre class="code language-ruby"><code class="language-ruby">require "rspec/stubbed_env"
</code></pre>
<h3 id="env-stubbing">ENV stubbing</h3>
<ul>
<li>is opt-in, via a shared context, rather than global.</li>
<li>
<em>does not</em> affect the real ENV at all. It is a true stub.</li>
<li>has the same scope as a <code>before</code>, <code>subject</code>, or <code>let</code> at the same level.</li>
</ul>
<p>See the spec suite for detailed examples.</p>
<pre class="code language-ruby"><code class="language-ruby"># This is normal, without stubbing, ENV is not set
describe "vanilla" do
it "has no ENV stub" do
expect(ENV.fetch("FOO", nil)).to(be_nil)
expect(ENV["FOO"]).to(be_nil)
end
end
# With a stubbed ENV!
describe "my stubbed test" do
include_context "with stubbed env"
before do
stub_env("FOO" => "is bar")
end
it "has a value" do
expect(ENV.fetch("FOO", nil)).to(eq("is bar"))
expect(ENV["FOO"]).to(eq("is bar"))
end
end
</code></pre>
<p>ENV can be stubbed trough the <code>stub_env</code> method, or key/value pairs to be stubbed can be<br>
provided directly to the <code>include_context</code> call:</p>
<pre class="code language-ruby"><code class="language-ruby">describe "my stubbed test" do
include_context "with stubbed env", "FOO" => "is bar"
it "has a value" do
expect(ENV.fetch("FOO", nil)).to(eq("is bar"))
expect(ENV["FOO"]).to(eq("is bar"))
end
end
</code></pre>
<p>If you want to make <code>stub_env</code> method available globally (without the <code>include_context</code> call),<br>
you can add in the <code>spec_helper</code>.</p>
<p>I do not recommend the <em>global</em> approach, as it results in a loss of clarity<br>
on which tests are testing ENV-based behaviors. Here’s a foot-gun if you want it.</p>
<pre class="code language-ruby"><code class="language-ruby">RSpec.configure do |config|
config.include(RSpec::StubbedEnv::StubHelpers)
# Or you could include the context globally
# config.include_context "with stubbed env"
end
</code></pre>
<h3 id="env-hiding">ENV hiding</h3>
<ul>
<li>is opt-in, via a shared context, rather than global.</li>
<li>
<em>does not</em> affect the real ENV at all. It is a true stub.</li>
<li>has the same scope as a <code>before</code>, <code>subject</code>, or <code>let</code> at the same level.</li>
</ul>
<p>See the spec suite for detailed examples.</p>
<pre class="code language-ruby"><code class="language-ruby"># This is normal, without hiding, ENV is set
ENV["MY_PATH"] = "/home/doodle"
describe "vanilla" do
it "has ENV with nothing hidden" do
expect(ENV.fetch("MY_PATH", nil)).to("/home/doodle")
expect(ENV["MY_PATH"]).to("/home/doodle")
end
end
# With a hidden ENV variable!
describe "my hidden test" do
include_context "with hidden env"
before do
hide_env("MY_PATH")
end
it "MY_PATH is not set" do
expect(ENV.fetch("MY_PATH", nil)).to(be_nil)
expect(ENV["MY_PATH"]).to(be_nil)
end
end
</code></pre>
<p>ENV variables can be hidden trough the <code>hide_env</code> method, or variable names to be hidden can be<br>
provided directly to the <code>include_context</code> call:</p>
<pre class="code language-ruby"><code class="language-ruby">describe "my hidden test" do
include_context "with hidden env", "MY_PATH"
it "MY_PATH is not set" do
expect(ENV.fetch("MY_PATH", nil)).to(be_nil)
expect(ENV["MY_PATH"]).to(be_nil)
end
end
</code></pre>
<p>If you want to make <code>hide_env</code> method available globally (without the <code>include_context</code> call),<br>
you can add in the <code>spec_helper</code>:</p>
<p>I do not recommend the <em>global</em> approach, as it results in a loss of clarity<br>
on which tests are testing ENV-based behaviors. Here’s a foot-gun if you want it.</p>
<pre class="code language-ruby"><code class="language-ruby">RSpec.configure do |config|
config.include(RSpec::StubbedEnv::HideHelpers)
# Or you could include the context globally
# config.include_context "with hidden env"
end
</code></pre>
<h2 id="-switch-to-main-branch">🚚 Switch to <code>main</code> branch</h2>
<p>We migrated from <code>master</code> to <code>main</code> as the default branch. If this affected your local checkout:</p>
<pre class="code language-console"><code class="language-console">git branch -m master main
git fetch origin
git branch -u origin/main main
git remote set-head origin -a
</code></pre>
<h3 id="-release-instructions">🚀 Release Instructions</h3>
<p>See <a href="file.CONTRIBUTING.html" title="CONTRIBUTING.md">CONTRIBUTING.md</a>.</p>
<h2 id="-security">🔐 Security</h2>
<p>See <a href="file.SECURITY.html" title="SECURITY.md">SECURITY.md</a>.</p>
<h2 id="-contributing">🤝 Contributing</h2>
<p>If you need some ideas of where to help, you could work on adding more code coverage,<br>
or if it is already 💯 (see <a href="#code-coverage">below</a>) check <a href="https://github.com/galtzo-floss/rspec-stubbed_env/issues">issues</a>, or <a href="https://github.com/galtzo-floss/rspec-stubbed_env/pulls">PRs</a>,<br>
or use the gem and think about how it could be better.</p>
<p>We <a href="https://keepachangelog.com/en/1.0.0/"><img src="https://img.shields.io/badge/keep--a--changelog-1.0.0-34495e.svg?style=flat" alt="Keep A Changelog"></a> so if you make changes, remember to update it.</p>
<p>See <a href="file.CONTRIBUTING.html" title="CONTRIBUTING.md">CONTRIBUTING.md</a> for more detailed instructions.</p>
<h3 id="code-coverage">Code Coverage</h3>
<p><a href="https://codecov.io/gh/galtzo-floss/rspec-stubbed_env"><img src="https://codecov.io/gh/galtzo-floss/rspec-stubbed_env/graphs/tree.svg?token=hRnUCPqxMu" alt="Coverage Graph"></a></p>
<p><a href="https://coveralls.io/github/galtzo-floss/rspec-stubbed_env?branch=main"><img src="https://coveralls.io/repos/github/galtzo-floss/rspec-stubbed_env/badge.svg?branch=main" alt="Coveralls Test Coverage"></a></p>
<h3 id="-code-of-conduct">🪇 Code of Conduct</h3>
<p>Everyone interacting in this project’s codebases, issue trackers,<br>
chat rooms and mailing lists is expected to follow the <a href="file.CODE_OF_CONDUCT.html" title="<img src="https://img.shields.io/badge/Contributor_Covenant-2.1-259D6C.svg" alt="Contributor Covenant 2.1">"><img src="https://img.shields.io/badge/Contributor_Covenant-2.1-259D6C.svg" alt="Contributor Covenant 2.1"></a>.</p>
<h2 id="-contributors">🌈 Contributors</h2>
<p><a href="https://github.com/galtzo-floss/rspec-stubbed_env/graphs/contributors"><img src="https://contrib.rocks/image?repo=galtzo-floss/rspec-stubbed_env" alt="Contributors"></a></p>
<p>Made with <a href="https://contrib.rocks">contributors-img</a>.</p>
<p>Also see GitLab Contributors: <a href="https://gitlab.com/galtzo-floss/rspec-stubbed_env/-/graphs/main">https://gitlab.com/galtzo-floss/rspec-stubbed_env/-/graphs/main</a></p>
<h2 id="️-star-history">⭐️ Star History</h2>
<p><a href="https://star-history.com/#galtzo-floss/rspec-stubbed_env&Date"></a></p>
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=galtzo-floss/rspec-stubbed_env&type=Date&theme=dark"></source>
<source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=galtzo-floss/rspec-stubbed_env&type=Date"></source>
<img alt="Star History Chart" src="https://api.star-history.com/svg?repos=galtzo-floss/rspec-stubbed_env&type=Date">
</picture>
<p></a></p>
<h2 id="-versioning">📌 Versioning</h2>
<p>This Library adheres to <a href="https://semver.org/spec/v2.0.0.html"><img src="https://img.shields.io/badge/semver-2.0.0-259D6C.svg?style=flat" alt="Semantic Versioning 2.0.0"></a>.<br>
Violations of this scheme should be reported as bugs.<br>
Specifically, if a minor or patch version is released that breaks backward compatibility,<br>
a new version should be immediately released that restores compatibility.<br>
Breaking changes to the public API will only be introduced with new major versions.</p>
<h3 id="-is-platform-support-part-of-the-public-api">📌 Is “Platform Support” part of the public API?</h3>
<p>Yes. But I’m obligated to include notes…</p>
<p>SemVer should, but doesn’t explicitly, say that dropping support for specific Platforms<br>
is a <em>breaking change</em> to an API.<br>
It is obvious to many, but not all, and since the spec is silent, the bike shedding is endless.</p>
<blockquote>
<p>dropping support for a platform is both obviously and objectively a breaking change</p>
</blockquote>
<ul>
<li>Jordan Harband (@ljharb, maintainer of SemVer) <a href="https://github.com/semver/semver/issues/716#issuecomment-869336139">in SemVer issue 716</a>
</li>
</ul>
<p>To get a better understanding of how SemVer is intended to work over a project’s lifetime,<br>
read this article from the creator of SemVer:</p>
<ul>
<li><a href="https://tom.preston-werner.com/2022/05/23/major-version-numbers-are-not-sacred.html">“Major Version Numbers are Not Sacred”</a></li>
</ul>
<p>As a result of this policy, and the interpretive lens used by the maintainer,<br>
you can (and should) specify a dependency on these libraries using<br>
the <a href="http://guides.rubygems.org/patterns/#pessimistic-version-constraint">Pessimistic Version Constraint</a> with two digits of precision.</p>
<p>For example:</p>
<pre class="code language-ruby"><code class="language-ruby">spec.add_dependency("rspec-stubbed_env", "~> 1.0")
</code></pre>
<p>See <a href="file.CHANGELOG.html" title="CHANGELOG.md">CHANGELOG.md</a> for list of releases.</p>
<h2 id="-license">📄 License</h2>
<p>The gem is available as open source under the terms of<br>
the <a href="file.LICENSE.html" title="MIT License">MIT License</a> <a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-259D6C.svg" alt="License: MIT"></a>.<br>
See <a href="file.LICENSE.html" title="LICENSE.txt">LICENSE.txt</a> for the official <a href="https://opensource.stackexchange.com/questions/5778/why-do-licenses-such-as-the-mit-license-specify-a-single-year">Copyright Notice</a>.</p>
<h3 id="-copyright">© Copyright</h3>
<ul>
<li>
Copyright (c) 2018-2020, 2024-2025 Peter H. Boling, of
<a href="https://discord.gg/3qme4XHNKN">
Galtzo.com
<picture>
<img src="https://logos.galtzo.com/assets/images/galtzo-floss/avatar-128px-blank.svg" alt="Galtzo.com Logo (Wordless) by Aboling0, CC BY-SA 4.0" width="24">
</picture>
</a>, and rspec-stubbed_env contributors
</li>
</ul>
<h2 id="-one-more-thing">🤑 One more thing</h2>
<p>Having arrived at the bottom of the page, please endure a final supplication.<br>
The primary maintainer of this gem, Peter Boling, wants<br>
Ruby to be a great place for people to solve problems, big and small.<br>
Please consider supporting his efforts via the giant yellow link below,<br>
or one of smaller ones, depending on button size preference.</p>
<p><a href="https://www.buymeacoffee.com/pboling"><img src="https://img.buymeacoffee.com/button-api/?text=Buy%20me%20a%20latte&emoji=&slug=pboling&button_colour=FFDD00&font_colour=000000&font_family=Cookie&outline_colour=000000&coffee_colour=ffffff" alt="Buy me a latte"></a></p>
<p><a href="https://liberapay.com/pboling/donate"><img src="https://img.shields.io/liberapay/goal/pboling.svg?logo=liberapay" alt="Liberapay Goal Progress"></a> <a href="https://github.com/sponsors/pboling"><img src="https://img.shields.io/badge/Sponsor_Me!-pboling.svg?style=social&logo=github" alt="Sponsor Me on Github"></a> <a href="https://polar.sh/pboling"><img src="https://img.shields.io/badge/polar-donate-yellow.svg" alt="Donate on Polar"></a> <a href="https://ko-fi.com/O5O86SNP4"><img src="https://img.shields.io/badge/a_more_different_coffee-%E2%9C%93-yellow.svg" alt="Donate to my FLOSS or refugee efforts at ko-fi.com"></a> <a href="https://patreon.com/galtzo"><img src="https://img.shields.io/badge/patreon-donate-yellow.svg" alt="Donate to my FLOSS or refugee efforts using Patreon"></a></p>
<p>P.S. If you need help️, or want to say thanks, 👇 Join the Discord.</p>
<p><a href="https://discord.gg/3qme4XHNKN"><img src="https://img.shields.io/discord/1373797679469170758?style=for-the-badge" alt="Live Chat on Discord"></a></p>
</div></div>
<div id="footer">
Generated on Mon Aug 4 22:57:10 2025 by
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.37 (ruby-3.4.5).
</div>
</div>
</body>
</html>
|