This repository has been archived by the owner on Mar 1, 2019. It is now read-only.
forked from cucumber/aruba
-
Notifications
You must be signed in to change notification settings - Fork 1
/
append_environment_variable.feature
128 lines (96 loc) · 3.96 KB
/
append_environment_variable.feature
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: Append 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
`#append_environment_variable`. Using this variable appends 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` 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) { append_environment_variable 'LONG_LONG_VARIABLE', 'a' }
before(:each) { run('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) { append_environment_variable 'LONG_LONG_VARIABLE', 'a' }
before(:each) { append_environment_variable 'LONG_LONG_VARIABLE', 'b' }
before(:each) { run('env') }
before(:each) { stop_all_commands }
it { expect(last_command_started.output).to include 'LONG_LONG_VARIABLE=ab' }
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) { append_environment_variable 'REALLY_LONG_LONG_VARIABLE', 'b' }
before(:each) { run('env') }
before(:each) { stop_all_commands }
it { expect(last_command_started.output).to include 'REALLY_LONG_LONG_VARIABLE=ab' }
# 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) { append_environment_variable 'REALLY_LONG_LONG_VARIABLE', 'b' }
before(:each) { run('env') }
before(:each) { stop_all_commands }
it do
with_environment do
expect(ENV['REALLY_LONG_LONG_VARIABLE']).to eq 'ab'
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 appended, 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) { append_environment_variable 'REALLY_LONG_LONG_VARIABLE', 'b' }
before(:each) { run('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