aruba 0.7.4 → 0.8.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.nav +12 -0
- data/.rspec +1 -0
- data/.rubocop.yml +12 -0
- data/.simplecov +2 -0
- data/.travis.yml +5 -6
- data/Gemfile +53 -26
- data/History.md +17 -0
- data/LICENSE +1 -1
- data/README.md +45 -19
- data/Rakefile +12 -2
- data/TODO.md +3 -0
- data/aruba.gemspec +19 -8
- data/cucumber.yml +1 -1
- data/features/api/cd.feature +119 -0
- data/features/api/command/run.feature +37 -0
- data/features/api/command/which.feature +37 -0
- data/features/api/environment/append_environment_variable.feature +118 -0
- data/features/api/environment/prepend_environment_variable.feature +118 -0
- data/features/api/environment/set_environment_variable.feature +252 -0
- data/features/configuration/exit_timeout.feature +51 -0
- data/features/configuration/fixtures_directories.feature +31 -0
- data/features/configuration/fixtures_path_prefix.feature +24 -0
- data/features/configuration/io_timeout.feature +31 -0
- data/features/configuration/keep_ansi.feature +31 -0
- data/features/configuration/root_directory.feature +31 -0
- data/features/configuration/working_directory.feature +32 -0
- data/features/fixtures/cli-app/.gitignore +9 -0
- data/features/fixtures/cli-app/.rspec +2 -0
- data/features/fixtures/cli-app/README.md +34 -0
- data/features/fixtures/cli-app/Rakefile +1 -0
- data/features/fixtures/cli-app/bin/cli +6 -0
- data/features/fixtures/cli-app/cli-app.gemspec +26 -0
- data/features/fixtures/cli-app/features/support/env.rb +1 -0
- data/features/fixtures/cli-app/lib/cli/app.rb +13 -0
- data/features/fixtures/cli-app/lib/cli/app/version.rb +5 -0
- data/features/fixtures/cli-app/script/console +14 -0
- data/features/fixtures/cli-app/spec/cli/app_spec.rb +7 -0
- data/features/fixtures/cli-app/spec/spec_helper.rb +10 -0
- data/features/fixtures/copy/file.txt +1 -1
- data/features/hooks/after/command.feature +34 -0
- data/features/hooks/before/command.feature +61 -0
- data/features/matchers/directory/have_sub_directory.feature +110 -0
- data/features/matchers/file/be_existing_file.feature +82 -0
- data/features/matchers/file/have_file_content.feature +123 -0
- data/features/matchers/file/have_file_size.feature +107 -0
- data/features/matchers/path/be_an_absolute_path.feature +74 -0
- data/features/matchers/path/be_an_existing_path.feature +97 -0
- data/features/matchers/path/have_permissions.feature +118 -0
- data/features/matchers/timeouts.feature +48 -0
- data/features/step_definitions/aruba_dev_steps.rb +69 -1
- data/features/steps/commands/exit_statuses.feature +136 -0
- data/features/steps/commands/in_process.feature +129 -0
- data/features/steps/commands/run.feature +36 -0
- data/features/steps/environment/home_variable.feature +49 -0
- data/features/steps/environment/set_environment_variable.feature +34 -0
- data/features/support/aruba.rb +5 -0
- data/features/support/env.rb +8 -4
- data/lib/aruba.rb +20 -8
- data/lib/aruba/announcer.rb +1 -0
- data/lib/aruba/api.rb +18 -1179
- data/lib/aruba/api/command.rb +351 -0
- data/lib/aruba/api/core.rb +141 -0
- data/lib/aruba/api/deprecated.rb +549 -0
- data/lib/aruba/api/environment.rb +61 -0
- data/lib/aruba/api/filesystem.rb +305 -0
- data/lib/aruba/api/rvm.rb +39 -0
- data/lib/aruba/aruba_path.rb +75 -0
- data/lib/aruba/basic_configuration.rb +208 -0
- data/lib/aruba/basic_configuration/option.rb +25 -0
- data/lib/aruba/config.rb +43 -30
- data/lib/aruba/config/jruby.rb +14 -0
- data/lib/aruba/config_wrapper.rb +17 -0
- data/lib/aruba/contracts/relative_path.rb +13 -0
- data/lib/aruba/creators/aruba_file_creator.rb +32 -0
- data/lib/aruba/creators/aruba_fixed_size_file_creator.rb +32 -0
- data/lib/aruba/cucumber.rb +87 -53
- data/lib/aruba/cucumber/hooks.rb +65 -10
- data/lib/aruba/environment.rb +121 -0
- data/lib/aruba/errors.rb +3 -0
- data/lib/aruba/extensions/string/strip.rb +24 -0
- data/lib/aruba/hooks.rb +54 -0
- data/lib/aruba/jruby.rb +4 -9
- data/lib/aruba/matchers/command.rb +1 -79
- data/lib/aruba/matchers/command/be_successfully_executed.rb +30 -0
- data/lib/aruba/matchers/command/have_exit_status.rb +47 -0
- data/lib/aruba/matchers/command/have_finished_in_time.rb +42 -0
- data/lib/aruba/matchers/directory.rb +1 -59
- data/lib/aruba/matchers/directory/be_an_existing_directory.rb +34 -0
- data/lib/aruba/matchers/directory/have_sub_directory.rb +49 -0
- data/lib/aruba/matchers/file.rb +1 -177
- data/lib/aruba/matchers/file/be_an_existing_file.rb +34 -0
- data/lib/aruba/matchers/file/have_file_content.rb +58 -0
- data/lib/aruba/matchers/file/have_file_size.rb +43 -0
- data/lib/aruba/matchers/file/have_same_file_content.rb +44 -0
- data/lib/aruba/matchers/path.rb +1 -99
- data/lib/aruba/matchers/path/a_path_matching_pattern.rb +21 -0
- data/lib/aruba/matchers/path/be_an_absolute_path.rb +32 -0
- data/lib/aruba/matchers/path/be_an_existing_path.rb +33 -0
- data/lib/aruba/matchers/path/have_permissions.rb +60 -0
- data/lib/aruba/matchers/path/match_path_pattern.rb +41 -0
- data/lib/aruba/matchers/rspec.rb +0 -0
- data/lib/aruba/matchers/rspec_matcher_include_regexp.rb +1 -1
- data/lib/aruba/platform.rb +230 -0
- data/lib/aruba/process_monitor.rb +23 -5
- data/lib/aruba/processes/basic_process.rb +35 -1
- data/lib/aruba/processes/debug_process.rb +26 -15
- data/lib/aruba/processes/in_process.rb +21 -9
- data/lib/aruba/processes/spawn_process.rb +29 -19
- data/lib/aruba/reporting.rb +2 -0
- data/lib/aruba/rspec.rb +61 -13
- data/lib/aruba/runtime.rb +33 -0
- data/script/bootstrap +4 -6
- data/spec/aruba/api/runtime_spec.rb +28 -0
- data/spec/aruba/api_spec.rb +129 -126
- data/spec/aruba/aruba_path_spec.rb +65 -0
- data/spec/aruba/basic_configuration_spec.rb +5 -0
- data/spec/aruba/config_wrapper_spec.rb +25 -0
- data/spec/aruba/configuration_spec.rb +5 -0
- data/spec/aruba/jruby_spec.rb +34 -18
- data/spec/aruba/matchers/directory_spec.rb +6 -7
- data/spec/aruba/matchers/file_spec.rb +16 -20
- data/spec/aruba/matchers/path_spec.rb +14 -11
- data/spec/aruba/rspec_spec.rb +15 -0
- data/spec/aruba/runtime_spec.rb +29 -0
- data/spec/aruba/spawn_process_spec.rb +2 -2
- data/spec/spec_helper.rb +10 -2
- data/spec/support/configs/rspec.rb +1 -1
- data/spec/support/matchers/option.rb +35 -0
- data/spec/support/shared_contexts/aruba.rb +10 -8
- data/spec/support/shared_examples/configuration.rb +116 -0
- metadata +182 -33
- data/.rvmrc +0 -1
- data/features/before_cmd_hooks.feature +0 -61
- data/features/command_environment_variables.feature +0 -31
- data/features/custom_ruby_process.feature +0 -12
- data/features/exit_statuses.feature +0 -30
- data/features/support/custom_main.rb +0 -28
- data/lib/aruba/matchers/mode.rb +0 -52
- data/lib/aruba/utils.rb +0 -21
@@ -0,0 +1,37 @@
|
|
1
|
+
Feature: Run command
|
2
|
+
|
3
|
+
To run a command use the `#run`-method.
|
4
|
+
|
5
|
+
Background:
|
6
|
+
Given I use a fixture named "cli-app"
|
7
|
+
|
8
|
+
Scenario: Existing executable
|
9
|
+
Given an executable named "bin/cli" with:
|
10
|
+
"""
|
11
|
+
#!/bin/bash
|
12
|
+
exit 0
|
13
|
+
"""
|
14
|
+
And a file named "spec/which_spec.rb" with:
|
15
|
+
"""
|
16
|
+
require 'spec_helper'
|
17
|
+
|
18
|
+
RSpec.describe 'Run command', :type => :aruba do
|
19
|
+
before(:each) { run('cli') }
|
20
|
+
it { expect(last_command).to be_successfully_executed }
|
21
|
+
end
|
22
|
+
"""
|
23
|
+
When I run `rspec`
|
24
|
+
Then the specs should all pass
|
25
|
+
|
26
|
+
Scenario: Non-existing executable
|
27
|
+
Given a file named "bin/cli" does not exist
|
28
|
+
And a file named "spec/which_spec.rb" with:
|
29
|
+
"""
|
30
|
+
require 'spec_helper'
|
31
|
+
|
32
|
+
RSpec.describe 'Find path for command', :type => :aruba do
|
33
|
+
it { expect { run('cli') }.to raise_error Aruba::LaunchError, /Command "cli" not found in PATH-variable/ }
|
34
|
+
end
|
35
|
+
"""
|
36
|
+
When I run `rspec`
|
37
|
+
Then the specs should all pass
|
@@ -0,0 +1,37 @@
|
|
1
|
+
Feature: Get path to command
|
2
|
+
|
3
|
+
Sometimes you only know a commands name, but not where to find it. Here comes
|
4
|
+
`which` to the rescue.
|
5
|
+
|
6
|
+
Background:
|
7
|
+
Given I use a fixture named "cli-app"
|
8
|
+
|
9
|
+
Scenario: Existing executable
|
10
|
+
Given an executable named "bin/cli" with:
|
11
|
+
"""
|
12
|
+
#!/bin/bash
|
13
|
+
exit 0
|
14
|
+
"""
|
15
|
+
And a file named "spec/which_spec.rb" with:
|
16
|
+
"""
|
17
|
+
require 'spec_helper'
|
18
|
+
|
19
|
+
RSpec.describe 'Find path for command', :type => :aruba do
|
20
|
+
it { expect(which('cli')).to match %r{tmp/aruba/cli-app/bin/cli} }
|
21
|
+
end
|
22
|
+
"""
|
23
|
+
When I run `rspec`
|
24
|
+
Then the specs should all pass
|
25
|
+
|
26
|
+
Scenario: Non-existing executable
|
27
|
+
Given a file named "bin/cli" does not exist
|
28
|
+
And a file named "spec/which_spec.rb" with:
|
29
|
+
"""
|
30
|
+
require 'spec_helper'
|
31
|
+
|
32
|
+
RSpec.describe 'Find path for command', :type => :aruba do
|
33
|
+
it { expect(which('cli')).to be_nil }
|
34
|
+
end
|
35
|
+
"""
|
36
|
+
When I run `rspec`
|
37
|
+
Then the specs should all pass
|
@@ -0,0 +1,118 @@
|
|
1
|
+
Feature: Append environment variable
|
2
|
+
|
3
|
+
It is quite handy to modify the environment of a process. To make this
|
4
|
+
possible, `aruba` provides several methods. One of these is
|
5
|
+
`#append_environment_variable`. Using this variable appends a given value to
|
6
|
+
an existing one. If the variable does not exist, it is created with the given
|
7
|
+
value.
|
8
|
+
|
9
|
+
Each variable name and each value is converted to a string. Otherwise `ruby`
|
10
|
+
would complain about an invalid argument. To make use of a variable you can
|
11
|
+
either use `#run` and the like or `#with_environment`.
|
12
|
+
|
13
|
+
Background:
|
14
|
+
Given I use the fixture "cli-app"
|
15
|
+
|
16
|
+
Scenario: Non-existing variable
|
17
|
+
Given a file named "spec/environment_spec.rb" with:
|
18
|
+
"""
|
19
|
+
require 'spec_helper'
|
20
|
+
|
21
|
+
RSpec.describe 'Long running command', :type => :aruba do
|
22
|
+
before(:each) { append_environment_variable 'LONG_LONG_VARIABLE', 'a' }
|
23
|
+
before(:each) { run('env') }
|
24
|
+
|
25
|
+
it { expect(last_command.output).to include 'LONG_LONG_VARIABLE=a' }
|
26
|
+
end
|
27
|
+
"""
|
28
|
+
When I run `rspec`
|
29
|
+
Then the specs should all pass
|
30
|
+
|
31
|
+
Scenario: Existing inner variable
|
32
|
+
Given a file named "spec/environment_spec.rb" with:
|
33
|
+
"""
|
34
|
+
require 'spec_helper'
|
35
|
+
|
36
|
+
RSpec.describe 'Long running command', :type => :aruba do
|
37
|
+
before(:each) { append_environment_variable 'LONG_LONG_VARIABLE', 'a' }
|
38
|
+
before(:each) { append_environment_variable 'LONG_LONG_VARIABLE', 'b' }
|
39
|
+
before(:each) { run('env') }
|
40
|
+
|
41
|
+
it { expect(last_command.output).to include 'LONG_LONG_VARIABLE=ab' }
|
42
|
+
end
|
43
|
+
"""
|
44
|
+
When I run `rspec`
|
45
|
+
Then the specs should all pass
|
46
|
+
|
47
|
+
|
48
|
+
Scenario: Existing outer variable
|
49
|
+
Given a file named "spec/environment_spec.rb" with:
|
50
|
+
"""
|
51
|
+
require 'spec_helper'
|
52
|
+
|
53
|
+
ENV['REALLY_LONG_LONG_VARIABLE'] = 'a'
|
54
|
+
|
55
|
+
RSpec.describe 'Long running command', :type => :aruba do
|
56
|
+
before(:each) { append_environment_variable 'REALLY_LONG_LONG_VARIABLE', 'b' }
|
57
|
+
before(:each) { run('env') }
|
58
|
+
|
59
|
+
it { expect(last_command.output).to include 'REALLY_LONG_LONG_VARIABLE=ab' }
|
60
|
+
|
61
|
+
# Has no effect here, is not in block and not a command `run`
|
62
|
+
it { expect(ENV['REALLY_LONG_LONG_VARIABLE']).to eq 'a' }
|
63
|
+
end
|
64
|
+
"""
|
65
|
+
When I run `rspec`
|
66
|
+
Then the specs should all pass
|
67
|
+
|
68
|
+
Scenario: Run some ruby code with previously set environment
|
69
|
+
Given a file named "spec/environment_spec.rb" with:
|
70
|
+
"""
|
71
|
+
require 'spec_helper'
|
72
|
+
|
73
|
+
ENV['REALLY_LONG_LONG_VARIABLE'] = 'a'
|
74
|
+
|
75
|
+
RSpec.describe 'Long running command', :type => :aruba do
|
76
|
+
before(:each) { append_environment_variable 'REALLY_LONG_LONG_VARIABLE', 'b' }
|
77
|
+
before(:each) { run('env') }
|
78
|
+
|
79
|
+
it do
|
80
|
+
with_environment do
|
81
|
+
expect(ENV['REALLY_LONG_LONG_VARIABLE']).to eq 'ab'
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# Has no effect here, is not in block and not a command `run`
|
86
|
+
it { expect(ENV['REALLY_LONG_LONG_VARIABLE']).to eq 'a' }
|
87
|
+
end
|
88
|
+
"""
|
89
|
+
When I run `rspec`
|
90
|
+
Then the specs should all pass
|
91
|
+
|
92
|
+
Scenario: Run some ruby code with local environment
|
93
|
+
|
94
|
+
If you pass the same variable to the block it will not be appended, but
|
95
|
+
overwrites the variable
|
96
|
+
|
97
|
+
Given a file named "spec/environment_spec.rb" with:
|
98
|
+
"""
|
99
|
+
require 'spec_helper'
|
100
|
+
|
101
|
+
ENV['REALLY_LONG_LONG_VARIABLE'] = 'a'
|
102
|
+
|
103
|
+
RSpec.describe 'Long running command', :type => :aruba do
|
104
|
+
before(:each) { append_environment_variable 'REALLY_LONG_LONG_VARIABLE', 'b' }
|
105
|
+
before(:each) { run('env') }
|
106
|
+
|
107
|
+
it do
|
108
|
+
with_environment 'REALLY_LONG_LONG_VARIABLE' => 'a' do
|
109
|
+
expect(ENV['REALLY_LONG_LONG_VARIABLE']).to eq 'a'
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
# Has no effect here, is not in block and not a command `run`
|
114
|
+
it { expect(ENV['REALLY_LONG_LONG_VARIABLE']).to eq 'a' }
|
115
|
+
end
|
116
|
+
"""
|
117
|
+
When I run `rspec`
|
118
|
+
Then the specs should all pass
|
@@ -0,0 +1,118 @@
|
|
1
|
+
Feature: Prepend environment variable
|
2
|
+
|
3
|
+
It is quite handy to modify the environment of a process. To make this
|
4
|
+
possible, `aruba` provides several methods. One of these is
|
5
|
+
`#prepend_environment_variable`. Using this variable prepends a given value to
|
6
|
+
an existing one. If the variable does not exist, it is created with the given
|
7
|
+
value.
|
8
|
+
|
9
|
+
Each variable name and each value is converted to a string. Otherwise `ruby`
|
10
|
+
would complain about an invalid argument. To make use of a variable you can
|
11
|
+
either use `#run` and the like or `#with_environment`.
|
12
|
+
|
13
|
+
Background:
|
14
|
+
Given I use the fixture "cli-app"
|
15
|
+
|
16
|
+
Scenario: Non-existing variable
|
17
|
+
Given a file named "spec/environment_spec.rb" with:
|
18
|
+
"""
|
19
|
+
require 'spec_helper'
|
20
|
+
|
21
|
+
RSpec.describe 'Long running command', :type => :aruba do
|
22
|
+
before(:each) { prepend_environment_variable 'LONG_LONG_VARIABLE', 'a' }
|
23
|
+
before(:each) { run('env') }
|
24
|
+
|
25
|
+
it { expect(last_command.output).to include 'LONG_LONG_VARIABLE=a' }
|
26
|
+
end
|
27
|
+
"""
|
28
|
+
When I run `rspec`
|
29
|
+
Then the specs should all pass
|
30
|
+
|
31
|
+
Scenario: Existing inner variable
|
32
|
+
Given a file named "spec/environment_spec.rb" with:
|
33
|
+
"""
|
34
|
+
require 'spec_helper'
|
35
|
+
|
36
|
+
RSpec.describe 'Long running command', :type => :aruba do
|
37
|
+
before(:each) { prepend_environment_variable 'LONG_LONG_VARIABLE', 'a' }
|
38
|
+
before(:each) { prepend_environment_variable 'LONG_LONG_VARIABLE', 'b' }
|
39
|
+
before(:each) { run('env') }
|
40
|
+
|
41
|
+
it { expect(last_command.output).to include 'LONG_LONG_VARIABLE=ba' }
|
42
|
+
end
|
43
|
+
"""
|
44
|
+
When I run `rspec`
|
45
|
+
Then the specs should all pass
|
46
|
+
|
47
|
+
|
48
|
+
Scenario: Existing outer variable
|
49
|
+
Given a file named "spec/environment_spec.rb" with:
|
50
|
+
"""
|
51
|
+
require 'spec_helper'
|
52
|
+
|
53
|
+
ENV['REALLY_LONG_LONG_VARIABLE'] = 'a'
|
54
|
+
|
55
|
+
RSpec.describe 'Long running command', :type => :aruba do
|
56
|
+
before(:each) { prepend_environment_variable 'REALLY_LONG_LONG_VARIABLE', 'b' }
|
57
|
+
before(:each) { run('env') }
|
58
|
+
|
59
|
+
it { expect(last_command.output).to include 'REALLY_LONG_LONG_VARIABLE=ba' }
|
60
|
+
|
61
|
+
# Has no effect here, is not in block and not a command `run`
|
62
|
+
it { expect(ENV['REALLY_LONG_LONG_VARIABLE']).to eq 'a' }
|
63
|
+
end
|
64
|
+
"""
|
65
|
+
When I run `rspec`
|
66
|
+
Then the specs should all pass
|
67
|
+
|
68
|
+
Scenario: Run some ruby code with previously set environment
|
69
|
+
Given a file named "spec/environment_spec.rb" with:
|
70
|
+
"""
|
71
|
+
require 'spec_helper'
|
72
|
+
|
73
|
+
ENV['REALLY_LONG_LONG_VARIABLE'] = 'a'
|
74
|
+
|
75
|
+
RSpec.describe 'Long running command', :type => :aruba do
|
76
|
+
before(:each) { prepend_environment_variable 'REALLY_LONG_LONG_VARIABLE', 'b' }
|
77
|
+
before(:each) { run('env') }
|
78
|
+
|
79
|
+
it do
|
80
|
+
with_environment do
|
81
|
+
expect(ENV['REALLY_LONG_LONG_VARIABLE']).to eq 'ba'
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# Has no effect here, is not in block and not a command `run`
|
86
|
+
it { expect(ENV['REALLY_LONG_LONG_VARIABLE']).to eq 'a' }
|
87
|
+
end
|
88
|
+
"""
|
89
|
+
When I run `rspec`
|
90
|
+
Then the specs should all pass
|
91
|
+
|
92
|
+
Scenario: Run some ruby code with local environment
|
93
|
+
|
94
|
+
If you pass the same variable to the block it will not be prepended, but
|
95
|
+
overwrites the variable
|
96
|
+
|
97
|
+
Given a file named "spec/environment_spec.rb" with:
|
98
|
+
"""
|
99
|
+
require 'spec_helper'
|
100
|
+
|
101
|
+
ENV['REALLY_LONG_LONG_VARIABLE'] = 'a'
|
102
|
+
|
103
|
+
RSpec.describe 'Long running command', :type => :aruba do
|
104
|
+
before(:each) { prepend_environment_variable 'REALLY_LONG_LONG_VARIABLE', 'b' }
|
105
|
+
before(:each) { run('env') }
|
106
|
+
|
107
|
+
it do
|
108
|
+
with_environment 'REALLY_LONG_LONG_VARIABLE' => 'a' do
|
109
|
+
expect(ENV['REALLY_LONG_LONG_VARIABLE']).to eq 'a'
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
# Has no effect here, is not in block and not a command `run`
|
114
|
+
it { expect(ENV['REALLY_LONG_LONG_VARIABLE']).to eq 'a' }
|
115
|
+
end
|
116
|
+
"""
|
117
|
+
When I run `rspec`
|
118
|
+
Then the specs should all pass
|
@@ -0,0 +1,252 @@
|
|
1
|
+
Feature: Set environment variable via API-method
|
2
|
+
|
3
|
+
It is quite handy to modify the environment of a process. To make this
|
4
|
+
possible, `aruba` provides several methods. One of these is
|
5
|
+
`#set_environment_variable`. Using this variable sets the value of a
|
6
|
+
non-existing variable and overwrites an existing value. Each variable name
|
7
|
+
and each value is converted to a string. Otherwise `ruby` would complain
|
8
|
+
about an invalid argument. To make use of a variable you can either use `#run`
|
9
|
+
and the like or `#with_environment`. Besides setting a variable globally, you
|
10
|
+
can set one for a block of code only using `#with_environment`.
|
11
|
+
|
12
|
+
Background:
|
13
|
+
Given I use the fixture "cli-app"
|
14
|
+
|
15
|
+
Scenario: Non-existing variable
|
16
|
+
Given a file named "spec/environment_spec.rb" with:
|
17
|
+
"""
|
18
|
+
require 'spec_helper'
|
19
|
+
|
20
|
+
RSpec.describe 'Long running command', :type => :aruba do
|
21
|
+
before(:each) { set_environment_variable 'LONG_LONG_VARIABLE', '1' }
|
22
|
+
before(:each) { run('env') }
|
23
|
+
|
24
|
+
it { expect(last_command.output).to include 'LONG_LONG_VARIABLE=1' }
|
25
|
+
end
|
26
|
+
"""
|
27
|
+
When I run `rspec`
|
28
|
+
Then the specs should all pass
|
29
|
+
|
30
|
+
Scenario: Existing variable set from within the test
|
31
|
+
Given a file named "spec/environment_spec.rb" with:
|
32
|
+
"""
|
33
|
+
require 'spec_helper'
|
34
|
+
|
35
|
+
RSpec.describe 'Long running command', :type => :aruba do
|
36
|
+
before(:each) { set_environment_variable 'LONG_LONG_VARIABLE', '1' }
|
37
|
+
before(:each) { set_environment_variable 'LONG_LONG_VARIABLE', '2' }
|
38
|
+
before(:each) { run('env') }
|
39
|
+
|
40
|
+
it { expect(last_command.output).to include 'LONG_LONG_VARIABLE=2' }
|
41
|
+
end
|
42
|
+
"""
|
43
|
+
When I run `rspec`
|
44
|
+
Then the specs should all pass
|
45
|
+
|
46
|
+
|
47
|
+
Scenario: Existing variable set by some outer parent process
|
48
|
+
|
49
|
+
Given a file named "spec/environment_spec.rb" with:
|
50
|
+
"""
|
51
|
+
require 'spec_helper'
|
52
|
+
|
53
|
+
ENV['REALLY_LONG_LONG_VARIABLE'] = '1'
|
54
|
+
|
55
|
+
RSpec.describe 'Long running command', :type => :aruba do
|
56
|
+
before(:each) { set_environment_variable 'REALLY_LONG_LONG_VARIABLE', '2' }
|
57
|
+
before(:each) { run('env') }
|
58
|
+
|
59
|
+
it { expect(last_command.output).to include 'REALLY_LONG_LONG_VARIABLE=2' }
|
60
|
+
it { expect(ENV['REALLY_LONG_LONG_VARIABLE']).to eq '1' }
|
61
|
+
end
|
62
|
+
"""
|
63
|
+
When I run `rspec`
|
64
|
+
Then the specs should all pass
|
65
|
+
|
66
|
+
Scenario: Run some ruby code in code with previously set environment
|
67
|
+
|
68
|
+
The `#with_environment`-block makes the change environment temporary
|
69
|
+
avaiable for the code run within the block.
|
70
|
+
|
71
|
+
Given a file named "spec/environment_spec.rb" with:
|
72
|
+
"""
|
73
|
+
require 'spec_helper'
|
74
|
+
|
75
|
+
ENV['REALLY_LONG_LONG_VARIABLE'] = '1'
|
76
|
+
|
77
|
+
RSpec.describe 'Long running command', :type => :aruba do
|
78
|
+
before(:each) { set_environment_variable 'REALLY_LONG_LONG_VARIABLE', '2' }
|
79
|
+
before(:each) { run('env') }
|
80
|
+
|
81
|
+
it do
|
82
|
+
with_environment do
|
83
|
+
expect(ENV['REALLY_LONG_LONG_VARIABLE']).to eq '2'
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
it { expect(ENV['REALLY_LONG_LONG_VARIABLE']).to eq '1' }
|
88
|
+
|
89
|
+
end
|
90
|
+
"""
|
91
|
+
When I run `rspec`
|
92
|
+
Then the specs should all pass
|
93
|
+
|
94
|
+
Scenario: Run some ruby code with local environment
|
95
|
+
|
96
|
+
If you need to set some environment variables only for the given block.
|
97
|
+
Pass it an `Hash` containing the environment variables.
|
98
|
+
|
99
|
+
Given a file named "spec/environment_spec.rb" with:
|
100
|
+
"""
|
101
|
+
require 'spec_helper'
|
102
|
+
|
103
|
+
ENV['REALLY_LONG_LONG_VARIABLE'] = '1'
|
104
|
+
|
105
|
+
RSpec.describe 'Long running command', :type => :aruba do
|
106
|
+
before(:each) { set_environment_variable 'REALLY_LONG_LONG_VARIABLE', '2' }
|
107
|
+
before(:each) { run('env') }
|
108
|
+
|
109
|
+
it do
|
110
|
+
with_environment 'REALLY_LONG_LONG_VARIABLE' => '3' do
|
111
|
+
expect(ENV['REALLY_LONG_LONG_VARIABLE']).to eq '3'
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
it { expect(ENV['REALLY_LONG_LONG_VARIABLE']).to eq '1' }
|
116
|
+
end
|
117
|
+
"""
|
118
|
+
When I run `rspec`
|
119
|
+
Then the specs should all pass
|
120
|
+
|
121
|
+
Scenario: Nested setup with rspec
|
122
|
+
|
123
|
+
It doesn't matter if you define an environment variable in some outer
|
124
|
+
scope, when you are using `RSpec`.
|
125
|
+
|
126
|
+
Given a file named "spec/environment_spec.rb" with:
|
127
|
+
"""
|
128
|
+
require 'spec_helper'
|
129
|
+
|
130
|
+
RSpec.describe 'Long running command', :type => :aruba do
|
131
|
+
before(:each) { set_environment_variable 'LONG_LONG_VARIABLE', '1' }
|
132
|
+
|
133
|
+
describe 'Method XX' do
|
134
|
+
before(:each) { run('env') }
|
135
|
+
|
136
|
+
it { expect(last_command.output).to include 'LONG_LONG_VARIABLE=1' }
|
137
|
+
end
|
138
|
+
|
139
|
+
describe 'Method YY' do
|
140
|
+
before(:each) { set_environment_variable 'LONG_LONG_VARIABLE', '2' }
|
141
|
+
before(:each) { run('env') }
|
142
|
+
|
143
|
+
it { expect(last_command.output).to include 'LONG_LONG_VARIABLE=2' }
|
144
|
+
end
|
145
|
+
end
|
146
|
+
"""
|
147
|
+
When I run `rspec`
|
148
|
+
Then the specs should all pass
|
149
|
+
|
150
|
+
Scenario: When an error occures the ENV is not polluted
|
151
|
+
Given a file named "spec/environment_spec.rb" with:
|
152
|
+
"""
|
153
|
+
require 'spec_helper'
|
154
|
+
|
155
|
+
ENV['REALLY_LONG_LONG_VARIABLE'] = '1'
|
156
|
+
|
157
|
+
RSpec.describe 'Long running command', :type => :aruba do
|
158
|
+
before(:each) { set_environment_variable 'REALLY_LONG_LONG_VARIABLE', '2' }
|
159
|
+
before(:each) { run('env') }
|
160
|
+
|
161
|
+
it do
|
162
|
+
begin
|
163
|
+
with_environment 'REALLY_LONG_LONG_VARIABLE' => '3' do
|
164
|
+
fail
|
165
|
+
end
|
166
|
+
rescue StandardError
|
167
|
+
end
|
168
|
+
|
169
|
+
expect(ENV['REALLY_LONG_LONG_VARIABLE']).to eq '1'
|
170
|
+
end
|
171
|
+
|
172
|
+
it { expect(ENV['REALLY_LONG_LONG_VARIABLE']).to eq '1' }
|
173
|
+
end
|
174
|
+
"""
|
175
|
+
When I run `rspec`
|
176
|
+
Then the specs should all pass
|
177
|
+
|
178
|
+
Scenario: Run some ruby code with nested environment blocks
|
179
|
+
|
180
|
+
It is possible to use a `#with_environment`-block with a
|
181
|
+
`#with_environment`-block. Each previously set variable is available with
|
182
|
+
the most inner block.
|
183
|
+
|
184
|
+
Given a file named "spec/environment_spec.rb" with:
|
185
|
+
"""
|
186
|
+
require 'spec_helper'
|
187
|
+
|
188
|
+
ENV['LONG_LONG_VARIABLE'] = '1'
|
189
|
+
ENV['REALLY_LONG_LONG_VARIABLE'] = '1'
|
190
|
+
|
191
|
+
RSpec.describe 'Long running command', :type => :aruba do
|
192
|
+
it do
|
193
|
+
with_environment 'REALLY_LONG_LONG_VARIABLE' => 2 do
|
194
|
+
with_environment 'LONG_LONG_VARIABLE' => 3 do
|
195
|
+
expect(ENV['LONG_LONG_VARIABLE']).to eq '3'
|
196
|
+
expect(ENV['REALLY_LONG_LONG_VARIABLE']).to eq '2'
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
it { expect(ENV['REALLY_LONG_LONG_VARIABLE']).to eq '1' }
|
202
|
+
end
|
203
|
+
"""
|
204
|
+
When I run `rspec`
|
205
|
+
Then the specs should all pass
|
206
|
+
|
207
|
+
Scenario: Re-use `#with_environment` for multiple `RSpec`-`it`-blocks
|
208
|
+
|
209
|
+
If you chose to run wrap examples via `RSpec`'s `around`-hook, make sure you
|
210
|
+
use `before(:context) {}` instead of `before(:each)` to set an environment
|
211
|
+
variable. Only then the `before`-hook is run before the `around`-hook is
|
212
|
+
run.
|
213
|
+
|
214
|
+
Given a file named "spec/environment_spec.rb" with:
|
215
|
+
"""
|
216
|
+
require 'spec_helper'
|
217
|
+
|
218
|
+
RSpec.describe 'Long running command', :type => :aruba do
|
219
|
+
# Please mind :context. This is run BEFORE the `around`-hook
|
220
|
+
before(:context) { set_environment_variable 'REALLY_LONG_LONG_VARIABLE', '1' }
|
221
|
+
|
222
|
+
context 'when no arguments are given' do
|
223
|
+
around(:each) do |example|
|
224
|
+
with_environment do
|
225
|
+
example.run
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
it { expect(ENV['REALLY_LONG_LONG_VARIABLE']).to eq '1' }
|
230
|
+
|
231
|
+
before(:each) { run('env') }
|
232
|
+
|
233
|
+
it { expect(last_command.output).to include 'REALLY_LONG_LONG_VARIABLE=1' }
|
234
|
+
end
|
235
|
+
|
236
|
+
context 'when arguments given' do
|
237
|
+
around(:each) do |example|
|
238
|
+
with_environment 'LONG_LONG_VARIABLE' => 2 do
|
239
|
+
example.run
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
it { expect(ENV['LONG_LONG_VARIABLE']).to eq '2' }
|
244
|
+
|
245
|
+
before(:each) { run('env') }
|
246
|
+
|
247
|
+
it { expect(last_command.output).to include 'REALLY_LONG_LONG_VARIABLE=1' }
|
248
|
+
end
|
249
|
+
end
|
250
|
+
"""
|
251
|
+
When I run `rspec`
|
252
|
+
Then the specs should all pass
|