A summary of data about the Ruby ecosystem.

https://github.com/thoughtbot/climate_control

Modify your ENV
https://github.com/thoughtbot/climate_control

Keywords

ruby testing

Keywords from Contributors

rubygems rspec activerecord mvc activejob feature-flag crash-reporting factories thoughtbot fixtures

Last synced: about 17 hours ago
JSON representation

Repository metadata

Modify your ENV

README.md

Climate Control

GitHub Actions CI

Easily manage your environment.

Installation

Add this line to your application's Gemfile:

gem 'climate_control'

And then execute:

$ bundle

Or install it yourself as:

$ gem install climate_control

Usage

Climate Control can be used to temporarily assign environment variables
within a block:

ClimateControl.modify CONFIRMATION_INSTRUCTIONS_BCC: 'confirmation_bcc@example.com' do
  sign_up_as 'john@example.com'

  confirm_account_for_email 'john@example.com'

  expect(current_email).to bcc_to('confirmation_bcc@example.com')
end

To modify multiple environment variables:

ClimateControl.modify CONFIRMATION_INSTRUCTIONS_BCC: 'confirmation_bcc@example.com',
                      MAIL_FROM: 'us@example.com' do
  sign_up_as 'john@example.com'

  confirm_account_for_email 'john@example.com'

  expect(current_email).to bcc_to('confirmation_bcc@example.com')
  expect(current_email).to be_from('us@example.com')
end

To temporarily unset an environment variable, pass nil as the value:

ClimateControl.modify API_KEY: nil do
  # ENV["API_KEY"] will be nil within this block
  # It will be restored to its original value (or remain unset if it was never set)
  # after the block ends
end

To use with RSpec, you could define this in your spec:

def with_modified_env(options = {}, &block)
  ClimateControl.modify(options, &block)
end

This would allow for more straightforward way to modify the environment:

require 'spec_helper'

describe Thing, 'name' do
  it 'appends ADDITIONAL_NAME' do
    with_modified_env ADDITIONAL_NAME: 'bar' do
      expect(Thing.new.name).to eq('John Doe Bar')
    end
  end

  def with_modified_env(options, &block)
    ClimateControl.modify(options, &block)
  end
end

To modify the environment for an entire set of tests in RSpec, use an around
block:

describe Thing, 'name' do
  # ... tests

  around do |example|
    ClimateControl.modify FOO: 'bar' do
      example.run
    end
  end
end

Environment variables assigned within the block will be preserved;
essentially, the code should behave exactly the same with and without the
block, except for the overrides. Transparency is crucial because the code
executed within the block is not for ClimateControl to manage or modify. See
the tests for more detail about the specific behaviors.

Why Use Climate Control?

By following guidelines regarding environment variables outlined by the
twelve-factor app, testing code in an isolated
manner becomes more difficult:

  • avoiding modifications and testing values, we introduce mystery guests
  • making modifications and testing values, we introduce risk as environment
    variables represent global state

Climate Control modifies environment variables only within the context of the
block, ensuring values are managed properly and consistently.

Thread-safety

When using threads, for instance when running tests concurrently in the same
process, you may need to wrap your code inside ClimateControl.modify blocks,
e.g.:

first_thread = Thread.new do
  ClimateControl.modify(SECRET: "1") do
    p ENV["SECRET"] # => "1"
    sleep 2
    p ENV["SECRET"] # => "1"
  end
end

second_thread = Thread.new do
  ClimateControl.modify({}) do
    sleep 1
    p ENV["SECRET"] # => nil
    sleep 1
    p ENV["SECRET"] # => nil
  end
end

first_thread.join
second_thread.join

The modification wraps ENV in a mutex. If there's contention (the env being used - including potentially mutating values), it blocks until the value is freed (we shift out of the Ruby block).

Josh Clayton

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

This project uses StandardRB to ensure formatting.

License

climate_control is copyright © 2012 Joshua Clayton and thoughtbot, inc. It is free software and may be redistributed under the terms specified in the LICENSE file.

About thoughtbot

thoughtbot

This repo is maintained and funded by thoughtbot, inc.
The names and logos for thoughtbot are trademarks of thoughtbot, inc.

We love open source software!
See our other projects.
We are available for hire.


Owner metadata


GitHub Events

Total
Last Year

Committers metadata

Last synced: about 17 hours ago

Total Commits: 103
Total Committers: 27
Avg Commits per committer: 3.815
Development Distribution Score (DDS): 0.524

Commits in past year: 7
Committers in past year: 4
Avg Commits per committer in past year: 1.75
Development Distribution Score (DDS) in past year: 0.714

Name Email Commits
Joshua Clayton j****n@t****m 49
Dorian Marié d****n@t****m 14
github-actions[bot] g****] 5
Dorian Marié d****n@d****m 3
Tamás Michelberger t****l@g****m 3
Stefanni Brasil s****l@g****m 2
Brian Penguin b****0@g****m 2
Geoff Harcourt g****t@g****m 2
Matheus Richard m****t@g****m 2
Olle Jonsson o****n@g****m 2
Yutaka Kamei k****i@y****e 2
dependabot[bot] 4****] 2
Adarsh Pandit a****h@t****m 1
Bruno Casali b****i@g****m 1
Filipe Brandenburger f****n@g****m 1
Ian Hall i****9@g****m 1
Joe Ferris j****s@t****m 1
Ken Dreyer k****r@k****m 1
Mike Burns m****e@m****m 1
Neil Carvalho me@n****o 1
Nick Schonning n****i@g****m 1
Patrik Ragnarsson p****k@s****t 1
Peter Goldstein p****n@g****m 1
Stefanni Brasil s****l@p****e 1
Thomas Orozco t****s@o****r 1
Yudai Takada 1****h 1
balexand b****d@g****m 1

Committer domains:


Issue and Pull Request metadata

Last synced: 3 months ago

Total issues: 16
Total pull requests: 75
Average time to close issues: 4 months
Average time to close pull requests: 3 months
Total issue authors: 16
Total pull request authors: 30
Average comments per issue: 2.13
Average comments per pull request: 0.95
Merged pull request: 55
Bot issues: 0
Bot pull requests: 13

Past year issues: 0
Past year pull requests: 10
Past year average time to close issues: N/A
Past year average time to close pull requests: about 1 month
Past year issue authors: 0
Past year pull request authors: 4
Past year average comments per issue: 0
Past year average comments per pull request: 0.4
Past year merged pull request: 7
Past year bot issues: 0
Past year bot pull requests: 6

More stats: https://issues.ecosyste.ms/repositories/lookup?url=https://github.com/thoughtbot/climate_control

Top Issue Authors

  • nikita-v (1)
  • dup2 (1)
  • sapslaj (1)
  • collegeimprovements (1)
  • dentarg (1)
  • sofianegargouri (1)
  • dorianmariefr (1)
  • lightning02 (1)
  • emaiax (1)
  • mcmire (1)
  • psmod2 (1)
  • kfernald (1)
  • joshuaclayton (1)
  • felixonmars (1)
  • dylanpiera (1)

Top Pull Request Authors

  • github-actions[bot] (11)
  • stefannibrasil (10)
  • dorianmariecom (8)
  • dorianmariefr (6)
  • joshuaclayton (6)
  • yykamei (3)
  • ktdreyer (3)
  • geoffharcourt (2)
  • brimatteng (2)
  • balexand (2)
  • dependabot[bot] (2)
  • neilvcarvalho (2)
  • ydah (1)
  • adarsh (1)
  • bkuhlmann (1)

Top Issue Labels

  • bug (1)

Top Pull Request Labels

  • dependencies (2)
  • github_actions (2)
  • enhancement (1)

Package metadata

gem.coop: climate_control

Modify your ENV

  • Homepage: https://github.com/thoughtbot/climate_control
  • Documentation: http://www.rubydoc.info/gems/climate_control/
  • Licenses: MIT
  • Latest release: 1.2.0 (published over 3 years ago)
  • Last Synced: 2026-02-28T18:31:09.330Z (3 days ago)
  • Versions: 10
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 130,890,923 Total
  • Docker Downloads: 85,338,311
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 0.185%
    • Downloads: 0.186%
    • Docker downloads count: 0.555%
  • Maintainers (3)
rubygems.org: climate_control

Modify your ENV

  • Homepage: https://github.com/thoughtbot/climate_control
  • Documentation: http://www.rubydoc.info/gems/climate_control/
  • Licenses: MIT
  • Latest release: 1.2.0 (published over 3 years ago)
  • Last Synced: 2026-03-02T06:02:33.075Z (1 day ago)
  • Versions: 10
  • Dependent Packages: 139
  • Dependent Repositories: 38,827
  • Downloads: 130,922,884 Total
  • Docker Downloads: 85,338,311
  • Rankings:
    • Dependent repos count: 0.166%
    • Downloads: 0.171%
    • Dependent packages count: 0.254%
    • Docker downloads count: 1.106%
    • Average: 1.576%
    • Stargazers count: 2.477%
    • Forks count: 5.279%
  • Maintainers (3)
proxy.golang.org: github.com/thoughtbot/climate_control

  • Homepage:
  • Documentation: https://pkg.go.dev/github.com/thoughtbot/climate_control#section-documentation
  • Licenses: mit
  • Latest release: v1.2.0 (published over 3 years ago)
  • Last Synced: 2026-02-28T21:01:09.797Z (3 days ago)
  • Versions: 10
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Stargazers count: 2.645%
    • Forks count: 4.501%
    • Average: 6.871%
    • Dependent packages count: 9.56%
    • Dependent repos count: 10.779%
debian-10: ruby-climate-control

  • Homepage: https://github.com/thoughtbot/climate_control
  • Documentation: https://packages.debian.org/buster/ruby-climate-control
  • Licenses:
  • Latest release: 0.0.3-1 (published 20 days ago)
  • Last Synced: 2026-02-13T04:19:53.965Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
ubuntu-23.04: ruby-climate-control

  • Homepage: https://github.com/thoughtbot/climate_control
  • Licenses:
  • Latest release: 0.0.3-1.1 (published 20 days ago)
  • Last Synced: 2026-02-11T06:36:58.538Z (20 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
ubuntu-20.04: ruby-climate-control

  • Homepage: https://github.com/thoughtbot/climate_control
  • Licenses: mit
  • Latest release: 0.0.3-1build1 (published 18 days ago)
  • Last Synced: 2026-02-13T07:11:24.132Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
ubuntu-23.10: ruby-climate-control

  • Homepage: https://github.com/thoughtbot/climate_control
  • Licenses:
  • Latest release: 0.0.3-1.1 (published 18 days ago)
  • Last Synced: 2026-02-13T18:16:37.573Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
ubuntu-24.10: ruby-climate-control

  • Homepage: https://github.com/thoughtbot/climate_control
  • Licenses:
  • Latest release: 0.0.3-1.1 (published 22 days ago)
  • Last Synced: 2026-02-09T16:18:12.901Z (22 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
debian-11: ruby-climate-control

  • Homepage: https://github.com/thoughtbot/climate_control
  • Documentation: https://packages.debian.org/bullseye/ruby-climate-control
  • Licenses:
  • Latest release: 0.0.3-1.1 (published 21 days ago)
  • Last Synced: 2026-02-13T08:19:07.028Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
ubuntu-22.04: ruby-climate-control

  • Homepage: https://github.com/thoughtbot/climate_control
  • Licenses:
  • Latest release: 0.0.3-1.1 (published 18 days ago)
  • Last Synced: 2026-02-13T13:14:28.428Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
debian-12: ruby-climate-control

  • Homepage: https://github.com/thoughtbot/climate_control
  • Documentation: https://packages.debian.org/bookworm/ruby-climate-control
  • Licenses:
  • Latest release: 0.0.3-1.1 (published 19 days ago)
  • Last Synced: 2026-02-12T23:27:10.878Z (19 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
ubuntu-24.04: ruby-climate-control

  • Homepage: https://github.com/thoughtbot/climate_control
  • Licenses:
  • Latest release: 0.0.3-1.1 (published 25 days ago)
  • Last Synced: 2026-02-06T15:02:11.657Z (25 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
debian-13: ruby-climate-control

  • Homepage: https://github.com/thoughtbot/climate_control
  • Documentation: https://packages.debian.org/trixie/ruby-climate-control
  • Licenses:
  • Latest release: 0.0.3-1.1 (published 19 days ago)
  • Last Synced: 2026-02-13T13:14:07.688Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%

Dependencies

climate_control.gemspec rubygems
  • rake >= 0 development
  • rspec >= 0 development
  • simplecov >= 0 development
  • standard >= 0 development
.github/workflows/ci.yml actions
  • actions/checkout v3 composite
  • ruby/setup-ruby v1 composite
Gemfile rubygems
.github/workflows/dynamic-security.yml actions
.github/workflows/dynamic-readme.yml actions

Score: 29.54746892634597