pax_global_header00006660000000000000000000000064136745044110014517gustar00rootroot0000000000000052 comment=87d350b1539e42cbf51c17dc1f025e28c8963e6f ruby-rspec-stubbed-env-1.0.0/000077500000000000000000000000001367450441100160245ustar00rootroot00000000000000ruby-rspec-stubbed-env-1.0.0/.pryrc000066400000000000000000000005621367450441100171670ustar00rootroot00000000000000# frozen_string_literal: true if defined?(PryByebug) Pry.commands.alias_command 'c', 'continue' Pry.commands.alias_command 's', 'step' Pry.commands.alias_command 'n', 'next' Pry.commands.alias_command 'trace', 'backtrace' end # Hit Enter to repeat last command Pry::Commands.command /^$/, 'repeat last command' do _pry_.run_command Pry.history.to_a.last end ruby-rspec-stubbed-env-1.0.0/.rspec000066400000000000000000000000651367450441100171420ustar00rootroot00000000000000--format documentation --color --require spec_helper ruby-rspec-stubbed-env-1.0.0/.ruby-version000066400000000000000000000000131367450441100204630ustar00rootroot00000000000000ruby-2.5.1 ruby-rspec-stubbed-env-1.0.0/.travis.yml000066400000000000000000000012221367450441100201320ustar00rootroot00000000000000--- env: global: - JRUBY_OPTS="-Xcli.debug=true --debug" - CC_TEST_REPORTER_ID=3ed1c79841ccc5d053b995c63c0ead562427a77dba728601b8d19f02b16ac0f2 before_script: - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter - chmod +x ./cc-test-reporter - ./cc-test-reporter before-build script: - bundle exec rake after_script: - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT before_install: - gem update --system - gem install bundler -v 1.16.5 install: - bundle install bundler_args: --no-deployment --jobs 3 --retry 3 language: ruby cache: bundler rvm: - 2.3.7 - 2.4.4 - 2.5.1 ruby-rspec-stubbed-env-1.0.0/CODE_OF_CONDUCT.md000066400000000000000000000062361367450441100206320ustar00rootroot00000000000000# Contributor Covenant Code of Conduct ## Our Pledge In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. ## Our Standards Examples of behavior that contributes to creating a positive environment include: * Using welcoming and inclusive language * Being respectful of differing viewpoints and experiences * Gracefully accepting constructive criticism * Focusing on what is best for the community * Showing empathy towards other community members Examples of unacceptable behavior by participants include: * The use of sexualized language or imagery and unwelcome sexual attention or advances * Trolling, insulting/derogatory comments, and personal or political attacks * Public or private harassment * Publishing others' private information, such as a physical or electronic address, without explicit permission * Other conduct which could reasonably be considered inappropriate in a professional setting ## Our Responsibilities Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. ## Scope This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at peter.boling@gmail.com. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. ## Attribution This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] [homepage]: http://contributor-covenant.org [version]: http://contributor-covenant.org/version/1/4/ ruby-rspec-stubbed-env-1.0.0/Gemfile000066400000000000000000000003141367450441100173150ustar00rootroot00000000000000# frozen_string_literal: true source 'https://rubygems.org' git_source(:github) { |repo_name| "https://github.com/#{repo_name}" } # Specify your gem's dependencies in rspec-stubbed_env.gemspec gemspec ruby-rspec-stubbed-env-1.0.0/LICENSE000066400000000000000000000020571367450441100170350ustar00rootroot00000000000000Copyright 2018 Peter Boling of railsbling.com Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ruby-rspec-stubbed-env-1.0.0/README.md000066400000000000000000000130511367450441100173030ustar00rootroot00000000000000# RSpec::StubbedEnv ENV stubbing via a shared context for more powerful tests. ```ruby 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['FOO']).to eq('is bar') end end ``` | Project | RSpec::StubbedEnv | |------------------------ | ----------------------- | | gem name | [rspec-stubbed_env](https://rubygems.org/gems/rspec-stubbed_env) | | license | [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT) | | download rank | [![Downloads Today](https://img.shields.io/gem/rd/rspec-stubbed_env.svg)](https://github.com/pboling/rspec-stubbed_env) | | version | [![Version](https://img.shields.io/gem/v/rspec-stubbed_env.svg)](https://rubygems.org/gems/rspec-stubbed_env) | | continuous integration | [![Build Status](https://travis-ci.org/pboling/rspec-stubbed_env.svg?branch=master)](https://travis-ci.org/pboling/rspec-stubbed_env) | | test coverage | [![Test Coverage](https://api.codeclimate.com/v1/badges/07a1d53634c61154efae/test_coverage)](https://codeclimate.com/github/pboling/rspec-stubbed_env/test_coverage) | | maintainability | [![Maintainability](https://api.codeclimate.com/v1/badges/07a1d53634c61154efae/maintainability)](https://codeclimate.com/github/pboling/rspec-stubbed_env/maintainability) | | dependencies | [![Depfu](https://badges.depfu.com/badges/a48948dd503f23a440f2c17910563f43/count.svg)](https://depfu.com/github/pboling/rspec-stubbed_env?project_id=5884) | | code triage | [![Open Source Helpers](https://www.codetriage.com/pboling/rspec-stubbed_env/badges/users.svg)](https://www.codetriage.com/pboling/rspec-stubbed_env) | | homepage | [on Github.com][homepage], [on Railsbling.com][blogpage] | | documentation | [on RDoc.info][documentation] | | Spread ~♡ⓛⓞⓥⓔ♡~ | [🌍 🌎 🌏](https://about.me/peter.boling), [🍚](https://www.crowdrise.com/helprefugeeswithhopefortomorrowliberia/fundraiser/peterboling), [➕](https://plus.google.com/+PeterBoling/posts), [👼](https://angel.co/peter-boling), [🐛](https://www.topcoder.com/members/pboling/), [:shipit:](http://coderwall.com/pboling), [![Tweet Peter](https://img.shields.io/twitter/follow/galtzo.svg?style=social&label=Follow)](http://twitter.com/galtzo) | ## Installation Add this line to your application's Gemfile: ```ruby 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. ```ruby RSpec.configure do |config| config.expect_with :rspec do |c| c.syntax = :expect end end ``` ## 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. ```ruby # This is normal, without stubbing, ENV is not set describe 'vanilla' do it 'has no ENV stub' do 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['FOO']).to eq('is bar') end end ``` ## 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](https://rubygems.org). ## Contributing Bug reports and pull requests are welcome on GitHub at https://github.com/pboling/rspec-stubbed_env. ## 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](https://github.com/pboling/rspec-stubbed_env/blob/master/CODE_OF_CONDUCT.md). ## Versioning This library aims to adhere to [Semantic Versioning 2.0.0][semver]. 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][pvc] with two digits of precision. For example: ```ruby spec.add_dependency 'rspec-stubbed_env', '~> 1.0' ``` ## License * Copyright (c) 2018 [Peter H. Boling][peterboling] of [Rails Bling][railsbling] [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT) [license]: LICENSE [semver]: http://semver.org/ [pvc]: http://guides.rubygems.org/patterns/#pessimistic-version-constraint [railsbling]: http://www.railsbling.com [peterboling]: http://www.peterboling.com [documentation]: http://rdoc.info/github/pboling/rspec-stubbed_env/frames [homepage]: https://github.com/pboling/rspec-stubbed_env/ [blogpage]: http://www.railsbling.com/tags/rspec-stubbed_env/ ruby-rspec-stubbed-env-1.0.0/Rakefile000066400000000000000000000002211367450441100174640ustar00rootroot00000000000000# frozen_string_literal: true require 'bundler/gem_tasks' require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) task default: :spec ruby-rspec-stubbed-env-1.0.0/bin/000077500000000000000000000000001367450441100165745ustar00rootroot00000000000000ruby-rspec-stubbed-env-1.0.0/bin/console000077500000000000000000000005761367450441100201740ustar00rootroot00000000000000#!/usr/bin/env ruby # frozen_string_literal: true require 'bundler/setup' require 'rspec/stubbed_env' # You can add fixtures and/or initialization code here to make experimenting # with your gem easier. You can also use a different console, if you like. # (If you use this, don't forget to add pry to your Gemfile!) # require "pry" # Pry.start require 'irb' IRB.start(__FILE__) ruby-rspec-stubbed-env-1.0.0/bin/setup000077500000000000000000000002031367450441100176550ustar00rootroot00000000000000#!/usr/bin/env bash set -euo pipefail IFS=$'\n\t' set -vx bundle install # Do any other automated setup that you need to do here ruby-rspec-stubbed-env-1.0.0/lib/000077500000000000000000000000001367450441100165725ustar00rootroot00000000000000ruby-rspec-stubbed-env-1.0.0/lib/rspec/000077500000000000000000000000001367450441100177065ustar00rootroot00000000000000ruby-rspec-stubbed-env-1.0.0/lib/rspec/stubbed_env.rb000066400000000000000000000010221367450441100225260ustar00rootroot00000000000000# frozen_string_literal: true require 'rspec/stubbed_env/version' # External Gems require 'rspec' # This Gem require 'rspec/stubbed_env/test_helpers' require 'rspec/stubbed_env/config' # # ENV stubbing is opt-in, via a shared context, rather than global # # describe 'my stubbed test' do # include_context 'with stubbed env' # before do # stub_env('FOO' => 'is bar') # end # it 'does a thing' do # expect(ENV['FOO']).to eq('is bar') # end # end # module RSpec # Gem Namespace module StubbedEnv end end ruby-rspec-stubbed-env-1.0.0/lib/rspec/stubbed_env/000077500000000000000000000000001367450441100222065ustar00rootroot00000000000000ruby-rspec-stubbed-env-1.0.0/lib/rspec/stubbed_env/config.rb000066400000000000000000000006331367450441100240020ustar00rootroot00000000000000# frozen_string_literal: true # # ENV stubbing is opt-in, via a shared context, rather than global # # Usage: # # describe 'my stubbed test' do # include_context 'with stubbed env' # before do # stub_env('FOO' => 'is bar') # end # it 'does a thing' do # expect(ENV['FOO']).to eq('is bar') # end # end # RSpec.shared_context 'with stubbed env' do include RSpec::StubbedEnv::TestHelpers end ruby-rspec-stubbed-env-1.0.0/lib/rspec/stubbed_env/test_helpers.rb000066400000000000000000000031121367450441100252310ustar00rootroot00000000000000# frozen_string_literal: true # # ENV stubbing is opt-in, via a shared context, rather than global # # Usage: # # describe 'my stubbed test' do # include_context 'with stubbed env' # before do # stub_env('FOO' => 'is bar') # end # it 'does a thing' do # expect(ENV['FOO']).to eq('is bar') # end # end # module RSpec module StubbedEnv # Helpers to unobtrusively stub ENV module TestHelpers # Can be called with all key value pairs to be stubbed as a hash: # # stub_env('A' => 'B', 'C' => 'D', 'E' => 'F') # # Alternatively can be called one per ENV key-value pair to stub: # # stub_env('A', 'B') # stub_env('C', 'D') # stub_env('E', 'F') def stub_env(key_or_hash, value = nil) init_stub unless env_stubbed? if key_or_hash.is_a? Hash key_or_hash.each { |k, v| add_stubbed_value(k, v) } else add_stubbed_value key_or_hash, value end end private STUBBED_KEY = '__STUBBED__' def add_stubbed_value(key, value) allow(ENV).to receive(:[]).with(key).and_return(value) allow(ENV).to receive(:fetch).with(key).and_return(value) allow(ENV).to receive(:fetch).with(key, anything) do |_, default_val| value || default_val end end def env_stubbed? ENV[STUBBED_KEY] end def init_stub allow(ENV).to receive(:[]).and_call_original allow(ENV).to receive(:fetch).and_call_original add_stubbed_value(STUBBED_KEY, true) end end end end ruby-rspec-stubbed-env-1.0.0/lib/rspec/stubbed_env/version.rb000066400000000000000000000001401367450441100242130ustar00rootroot00000000000000# frozen_string_literal: true module RSpec module StubbedEnv VERSION = '1.0.0' end end ruby-rspec-stubbed-env-1.0.0/rspec-stubbed_env.gemspec000066400000000000000000000025661367450441100230140ustar00rootroot00000000000000# frozen_string_literal: true lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'rspec/stubbed_env/version' Gem::Specification.new do |spec| spec.name = 'rspec-stubbed_env' spec.version = RSpec::StubbedEnv::VERSION spec.authors = ['Peter Boling'] spec.email = ['peter.boling@gmail.com'] spec.summary = 'Unobtrusively stub ENV keys and values during testing' spec.description = %[Stub environment variables in a scoped context for testing stub_env( 'AWS_REGION' => 'us-east-1', 'REDIS_URL' => 'redis://localhost:6379/' )] spec.homepage = 'https://github.com/pboling/rspec-stubbed_env' spec.license = 'MIT' # Specify which files should be added to the gem when it is released. # The `git ls-files -z` loads the files in the RubyGem that have been added into git. spec.files = Dir.chdir(File.expand_path(__dir__)) do `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } end spec.bindir = 'exe' spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ['lib'] spec.add_runtime_dependency 'rspec', '>= 3.0' spec.add_development_dependency 'bundler', '~> 1.16' spec.add_development_dependency 'rake', '~> 12.3' spec.add_development_dependency 'simplecov', '~> 0.16' end