Giter Site home page Giter Site logo

climate_control's Introduction

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: '[email protected]' do
  sign_up_as '[email protected]'
  confirm_account_for_email '[email protected]'
  current_email.should bcc_to('[email protected]')
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-2014 Joshua Clayton and thoughtbot, inc. It is free software and may be redistributed under the terms specified in the LICENSE.txt file.

climate_control's People

Contributors

balexand avatar joshuaclayton avatar mike-burns avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.