File: prepend_environment_variable.feature

package info (click to toggle)
ruby-aruba 0.14.8-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,216 kB
  • sloc: ruby: 7,951; sh: 21; makefile: 12
file content (128 lines) | stat: -rw-r--r-- 4,112 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
Feature: Prepend environment variable

  It is quite handy to modify the environment of a process. To make this
  possible, `aruba` provides several methods. One of these is
  `#prepend_environment_variable`. Using this variable prepends a given value to
  an existing one. If the variable does not exist, it is created with the given
  value.

  Each variable name and each value is converted to a string. Otherwise `ruby`
  would complain about an invalid argument. To make use of a variable you can
  either use `#run_command` and the like or `#with_environment`.

  Background:
    Given I use the fixture "cli-app"

  Scenario: Non-existing variable
    Given a file named "spec/environment_spec.rb" with:
    """ruby
    require 'spec_helper'

    RSpec.describe 'Long running command', :type => :aruba do
      before(:each) { prepend_environment_variable 'LONG_LONG_VARIABLE', 'a' }

      before(:each) { run_command('env') }
      before(:each) { stop_all_commands }

      it { expect(last_command_started.output).to include 'LONG_LONG_VARIABLE=a' }
    end
    """
    When I run `rspec`
    Then the specs should all pass

  Scenario: Existing inner variable
    Given a file named "spec/environment_spec.rb" with:
    """ruby
    require 'spec_helper'

    RSpec.describe 'Long running command', :type => :aruba do
      before(:each) { prepend_environment_variable 'LONG_LONG_VARIABLE', 'a' }
      before(:each) { prepend_environment_variable 'LONG_LONG_VARIABLE', 'b' }

      before(:each) { run_command('env') }
      before(:each) { stop_all_commands }

      it { expect(last_command_started.output).to include 'LONG_LONG_VARIABLE=ba' }
    end
    """
    When I run `rspec`
    Then the specs should all pass


  Scenario: Existing outer variable
    Given a file named "spec/environment_spec.rb" with:
    """ruby
    require 'spec_helper'

    ENV['REALLY_LONG_LONG_VARIABLE'] = 'a'

    RSpec.describe 'Long running command', :type => :aruba do
      before(:each) { prepend_environment_variable 'REALLY_LONG_LONG_VARIABLE', 'b' }

      before(:each) { run_command('env') }
      before(:each) { stop_all_commands }

      it { expect(last_command_started.output).to include 'REALLY_LONG_LONG_VARIABLE=ba' }

      # Has no effect here, is not in block and not a command `run`
      it { expect(ENV['REALLY_LONG_LONG_VARIABLE']).to eq 'a' }
    end
    """
    When I run `rspec`
    Then the specs should all pass

  Scenario: Run some ruby code with previously set environment
    Given a file named "spec/environment_spec.rb" with:
    """ruby
    require 'spec_helper'

    ENV['REALLY_LONG_LONG_VARIABLE'] = 'a'

    RSpec.describe 'Long running command', :type => :aruba do
      before(:each) { prepend_environment_variable 'REALLY_LONG_LONG_VARIABLE', 'b' }

      before(:each) { run_command('env') }
      before(:each) { stop_all_commands }

      it do
        with_environment do
          expect(ENV['REALLY_LONG_LONG_VARIABLE']).to eq 'ba'
        end
      end

      # Has no effect here, is not in block and not a command `run`
      it { expect(ENV['REALLY_LONG_LONG_VARIABLE']).to eq 'a' }
    end
    """
    When I run `rspec`
    Then the specs should all pass

  Scenario: Run some ruby code with local environment

    If you pass the same variable to the block it will not be prepended, but
    overwrites the variable

    Given a file named "spec/environment_spec.rb" with:
    """ruby
    require 'spec_helper'

    ENV['REALLY_LONG_LONG_VARIABLE'] = 'a'

    RSpec.describe 'Long running command', :type => :aruba do
      before(:each) { prepend_environment_variable 'REALLY_LONG_LONG_VARIABLE', 'b' }

      before(:each) { run_command('env') }
      before(:each) { stop_all_commands }

      it do
        with_environment 'REALLY_LONG_LONG_VARIABLE' => 'a' do
          expect(ENV['REALLY_LONG_LONG_VARIABLE']).to eq 'a'
        end
      end

      # Has no effect here, is not in block and not a command `run`
      it { expect(ENV['REALLY_LONG_LONG_VARIABLE']).to eq 'a' }
    end
    """
    When I run `rspec`
    Then the specs should all pass