|
| 1 | +# RSpec::StubbedEnv |
| 2 | + |
| 3 | +ENV stubbing via a shared context for more powerful tests. |
| 4 | + |
| 5 | +```ruby |
| 6 | +describe 'my stubbed test' do |
| 7 | + include_context 'with stubbed env' |
| 8 | + before do |
| 9 | + stub_env('FOO' => 'is bar') |
| 10 | + end |
| 11 | + it 'has a value' do |
| 12 | + expect(ENV['FOO']).to eq('is bar') |
| 13 | + end |
| 14 | +end |
| 15 | +``` |
| 16 | + |
| 17 | +| Project | RSpec::StubbedEnv | |
| 18 | +|------------------------ | ----------------------- | |
| 19 | +| gem name | [rspec-stubbed_env](https://rubygems.org/gems/rspec-stubbed_env) | |
| 20 | +| license | [](https://opensource.org/licenses/MIT) | |
| 21 | +| download rank | [](https://github.com/pboling/rspec-stubbed_env) | |
| 22 | +| version | [](https://rubygems.org/gems/rspec-stubbed_env) | |
| 23 | +| continuous integration | [](https://travis-ci.org/pboling/rspec-stubbed_env) | |
| 24 | +| test coverage | [](https://codeclimate.com/github/pboling/rspec-stubbed_env/test_coverage) | |
| 25 | +| maintainability | [](https://codeclimate.com/github/pboling/rspec-stubbed_env/maintainability) | |
| 26 | +| dependencies | [](https://depfu.com/github/pboling/rspec-stubbed_env?project_id=5828) | |
| 27 | +| code triage | [](https://www.codetriage.com/pboling/rspec-stubbed_env) | |
| 28 | +| homepage | [on Github.com][homepage], [on Railsbling.com][blogpage] | |
| 29 | +| documentation | [on RDoc.info][documentation] | |
| 30 | +| 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), [](http://twitter.com/galtzo) | |
| 31 | + |
| 32 | + |
| 33 | +## Installation |
| 34 | + |
| 35 | +Add this line to your application's Gemfile: |
| 36 | + |
| 37 | +```ruby |
| 38 | +gem 'rspec-stubbed_env', group: :test |
| 39 | +``` |
| 40 | + |
| 41 | +And then execute: |
| 42 | + |
| 43 | + $ bundle |
| 44 | + |
| 45 | +Or install it yourself as: |
| 46 | + |
| 47 | + $ gem install rspec-stubbed_env |
| 48 | + |
| 49 | + |
| 50 | +You must configure RSpec to use the `:expect` syntax, or some compatible alternative. |
| 51 | + |
| 52 | +```ruby |
| 53 | +RSpec.configure do |config| |
| 54 | + config.expect_with :rspec do |c| |
| 55 | + c.syntax = :expect |
| 56 | + end |
| 57 | +end |
| 58 | +``` |
| 59 | + |
| 60 | +## Usage |
| 61 | + |
| 62 | +ENV stubbing: |
| 63 | + |
| 64 | + - is opt-in, via a shared context, rather than global. |
| 65 | + - *does not* affect the real ENV at all. It is a true stub. |
| 66 | + - has the same scope as a `before`, `subject`, or `let` at the same level. |
| 67 | + |
| 68 | +See the spec suite for detailed examples. |
| 69 | + |
| 70 | +```ruby |
| 71 | +# This is normal, without stubbing, ENV is not set |
| 72 | +describe 'vanilla' do |
| 73 | + it 'has no ENV stub' do |
| 74 | + expect(ENV['FOO']).to be_nil |
| 75 | + end |
| 76 | +end |
| 77 | + |
| 78 | +# With a stubbed ENV! |
| 79 | +describe 'my stubbed test' do |
| 80 | + include_context 'with stubbed env' |
| 81 | + before do |
| 82 | + stub_env('FOO' => 'is bar') |
| 83 | + end |
| 84 | + it 'has a value' do |
| 85 | + expect(ENV['FOO']).to eq('is bar') |
| 86 | + end |
| 87 | +end |
| 88 | +``` |
| 89 | + |
| 90 | +## Development |
| 91 | + |
| 92 | +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. |
| 93 | + |
| 94 | +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). |
| 95 | + |
| 96 | +## Contributing |
| 97 | + |
| 98 | +Bug reports and pull requests are welcome on GitHub at https://github.com/pboling/rspec-stubbed_env. |
| 99 | + |
| 100 | +## Code of Conduct |
| 101 | + |
| 102 | +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). |
| 103 | + |
| 104 | +## Versioning |
| 105 | + |
| 106 | +This library aims to adhere to [Semantic Versioning 2.0.0][semver]. |
| 107 | +Violations of this scheme should be reported as bugs. Specifically, |
| 108 | +if a minor or patch version is released that breaks backward |
| 109 | +compatibility, a new version should be immediately released that |
| 110 | +restores compatibility. Breaking changes to the public API will |
| 111 | +only be introduced with new major versions. |
| 112 | + |
| 113 | +As a result of this policy, you can (and should) specify a |
| 114 | +dependency on this gem using the [Pessimistic Version Constraint][pvc] with two digits of precision. |
| 115 | + |
| 116 | +For example: |
| 117 | + |
| 118 | +```ruby |
| 119 | +spec.add_dependency 'rspec-stubbed_env', '~> 1.0' |
| 120 | +``` |
| 121 | + |
| 122 | +## License |
| 123 | + |
| 124 | +* Copyright (c) 2018 [Peter H. Boling][peterboling] of [Rails Bling][railsbling] |
| 125 | + |
| 126 | +[](https://opensource.org/licenses/MIT) |
| 127 | + |
| 128 | +[license]: LICENSE |
| 129 | +[semver]: http://semver.org/ |
| 130 | +[pvc]: http://guides.rubygems.org/patterns/#pessimistic-version-constraint |
| 131 | +[railsbling]: http://www.railsbling.com |
| 132 | +[peterboling]: http://www.peterboling.com |
| 133 | +[documentation]: http://rdoc.info/github/pboling/rspec-stubbed_env/frames |
| 134 | +[homepage]: https://github.com/pboling/rspec-stubbed_env/ |
| 135 | +[blogpage]: http://www.railsbling.com/tags/rspec-stubbed_env/ |
0 commit comments