Technology moves fast! ⚡ Don't get left behind.🚶 Subscribe to our mailing list to keep up with latest and greatest in open source projects! 🏆


Subscribe to our mailing list

climate_control

Modify your ENV

Subscribe to updates I use climate_control


Statistics on climate_control

Number of watchers on Github 216
Number of open issues 1
Average time to close an issue 2 months
Main language Ruby
Average time to merge a PR 27 days
Open pull requests 3+
Closed pull requests 7+
Last commit about 2 years ago
Repo Created over 6 years ago
Repo Last Updated over 1 year ago
Size 39 KB
Homepage https://robots.th...
Organization / Authorthoughtbot
Contributors4
Page Updated
Do you use climate_control? Leave a review!
View climate_control activity
View on github
Fresh, new opensource launches 🚀🚀🚀
Trendy new open source projects in your inbox! View examples

Subscribe to our mailing list

Evaluating climate_control for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)

Climate Control

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'
  current_email.should bcc_to('confirmation_bcc@example.com')
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.

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

License

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

climate_control open issues Ask a question     (View All Issues)
  • almost 3 years ERROR: Error installing climate_control: activesupport requires Ruby version >= 2.2.2
  • over 3 years Modifiers on before and after
climate_control open pull requests (View All Pulls)
  • Create RSpec metadata
  • Document lack of thread safety
  • Remove activesupport dependency
climate_control list of languages used
Other projects in Ruby