Module: EnvBranch::TestHelper

Defined in:
lib/env_branch/test_helper.rb

Overview

Test helper for branch with environment variables

Class Method Summary collapse

Class Method Details

.restore_env_branchvoid

This method returns an undefined value.

Restore original environment variables for branch.

Examples:

with test-unit

require 'env_branch/test_helper'

class TestExample < Test::Unit::TestCase
  extend ::EnvBranch::TestHelper

  def self.shutdown
    restore_env_branch
  end
end

See Also:



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/env_branch/test_helper.rb', line 52

def restore_env_branch
  original_travis_branch = (defined?(@original_travis_branch) && @original_travis_branch) || nil
  original_circle_branch = (defined?(@original_circle_branch) && @original_circle_branch) || nil
  original_bitrise_branch = (defined?(@original_bitrise_branch) && @original_bitrise_branch) || nil
  original_github_pull_request_builder_plugin_branch = (defined?(@original_github_pull_request_builder_plugin_branch) && @original_github_pull_request_builder_plugin_branch) || nil
  original_git_plugin_branch = (defined?(@original_git_plugin_branch) && @original_git_plugin_branch) || nil
  ENV['TRAVIS_BRANCH'] = original_travis_branch
  ENV['CIRCLE_BRANCH'] = original_circle_branch
  ENV['BITRISE_GIT_BRANCH'] = original_bitrise_branch
  ENV['ghprbSourceBranch'] = original_github_pull_request_builder_plugin_branch
  ENV['GIT_BRANCH'] = original_git_plugin_branch
end

.stash_env_branchvoid

This method returns an undefined value.

Stash original environment variables for branch. And delete for testing.

Examples:

with test-unit

require 'env_branch/test_helper'

class TestExample < Test::Unit::TestCase
  extend ::EnvBranch::TestHelper

  def self.startup
    stash_env_branch
  end
end

See Also:



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/env_branch/test_helper.rb', line 23

def stash_env_branch
  @original_travis_branch = ENV['TRAVIS_BRANCH']
  @original_circle_branch = ENV['CIRCLE_BRANCH']
  @original_bitrise_branch = ENV['BITRISE_GIT_BRANCH']
  @original_github_pull_request_builder_plugin_branch = ENV['ghprbSourceBranch']
  @original_git_plugin_branch = ENV['GIT_BRANCH']
  ENV.delete 'TRAVIS_BRANCH'
  ENV.delete 'CIRCLE_BRANCH'
  ENV.delete 'BITRISE_GIT_BRANCH'
  ENV.delete 'ghprbSourceBranch'
  ENV.delete 'GIT_BRANCH'
end