Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rspec-stubbed_env

Package Overview
Dependencies
Maintainers
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rspec-stubbed_env

  • 1.0.1
  • Rubygems
  • Socket score

Version published
Maintainers
2
Created
Source

RSpec::StubbedEnv

ENV stubbing via a shared context for more powerful tests. Now you don't need to add dotenv just for your spec suite.

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"))
  end
end
ProjectRSpec::StubbedEnv
gem namerspec-stubbed_env
licenseLicense: MIT
download rankDownloads Today
versionVersion
dependenciesDepfu
continuous integrationCurrent Heads Style
test coverageTest Coverage
maintainabilityMaintainability
code triageOpen Source Helpers
homepageon Github.com, on Railsbling.com
documentationon RDoc.info
Spread ♡ⓛⓞⓥⓔ♡Liberapay Goal Progress, 🧊, 🛖, 🧪, 🌏, 👼, ⚗️, Tweet @galtzo

Installation

Add this line to your application's Gemfile:

gem "rspec-stubbed_env", :group => :test

And then execute:

$ bundle

Or install it yourself as:

$ gem install rspec-stubbed_env

You must configure RSpec to use the :expect syntax, or some compatible alternative.

RSpec.configure do |config|
  config.expect_with(:rspec) do |c|
    c.syntax = :expect
  end
end

Require the library in your spec/test helper somewhere:

require "rspec/stubbed_env"

Usage

ENV stubbing:

  • is opt-in, via a shared context, rather than global.
  • does not affect the real ENV at all. It is a true stub.
  • has the same scope as a before, subject, or let at the same level.

See the spec suite for detailed examples.

# 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)
  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"))
  end
end

Switcch to main branch

We recently migrated from master to main as the default branch. If this affected your local checkout:

git branch -m master main
git fetch origin
git branch -u origin/main main
git remote set-head origin -a

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

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.

Authors

Contributing

See CONTRIBUTING.md. contributing: https://gitlab.com/pboling/rspec-stubbed_env/-/blob/main/CONTRIBUTING.md

Code of Conduct

Everyone interacting in the AnonymousActiveRecord project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

Versioning

This library aims to adhere to Semantic Versioning 2.0.0. Violations of this scheme should be reported as bugs. Specifically, if a minor or patch version is released that breaks backward compatibility, a new version should be immediately released that restores compatibility. Breaking changes to the public API will only be introduced with new major versions.

As a result of this policy, you can (and should) specify a dependency on this gem using the Pessimistic Version Constraint with two digits of precision.

For example in a Gemfile:

gem 'rspec-stubbed_env', '~> 1.0', group: [:development, :test]

or in a gemspec

spec.add_development_dependency 'rspec-stubbed_env', '~> 1.0'

License

License: MIT

FAQs

Package last updated on 01 Apr 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc