Skip to content

Commit

Permalink
Improve handling of environment
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmeyer committed Jul 6, 2015
1 parent 3b52099 commit 663991e
Show file tree
Hide file tree
Showing 29 changed files with 767 additions and 99 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Metrics/LineLength:
Exclude:
- lib/aruba/api.rb
- lib/aruba/api/deprecated.rb
- aruba.gemspec

# Configuration parameters: CountComments.
Metrics/MethodLength:
Expand Down
19 changes: 12 additions & 7 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@ gemspec
group :debug do
gem 'pry', '~> 0.10.1'

platform :mri_20, :mri_21, :mri_22 do
platform :ruby_20, :ruby_21, :ruby_22 do
gem 'byebug', '~> 4.0.5'
gem 'pry-byebug', '~> 3.1.0'
end

platform :mri_19, :mri_20, :mri_21, :mri_22 do
platform :ruby_19 do
gem 'debugger', '~> 1.6.8'
gem 'pry-debugger', '~> 0.2.3'
end

platform :ruby_19, :ruby_20, :ruby_21, :ruby_22 do
gem 'pry-stack_explorer', '~> 0.4.9'
end

Expand All @@ -23,7 +28,7 @@ group :development, :test do
# Run development tasks
gem 'rake', '~> 10.4.2'

platform :mri_19, :mri_20, :mri_21, :mri_22 do
platform :ruby_19, :ruby_20, :ruby_21, :ruby_22 do
# Reporting
gem 'bcat', '~> 0.6.2'
gem 'kramdown', '~> 1.7.0'
Expand All @@ -37,20 +42,20 @@ group :development, :test do
gem 'fuubar', '~> 2.0.0'

# Make aruba compliant to ruby community guide
platform :mri_19, :mri_20, :mri_21, :mri_22 do
platform :ruby_19, :ruby_20, :ruby_21, :ruby_22 do
gem 'rubocop', '~> 0.32.0'
end

platform :mri_19, :mri_20, :mri_21, :mri_22 do
platform :ruby_19, :ruby_20, :ruby_21, :ruby_22 do
gem 'cucumber-pro', '~> 0.0'
end

platform :mri_19, :mri_20, :mri_21, :mri_22 do
platform :ruby_19, :ruby_20, :ruby_21, :ruby_22 do
# License compliance
gem 'license_finder', '~> 2.0.4'
end

platform :mri_19, :mri_20, :mri_21, :mri_22 do
platform :ruby_19, :ruby_20, :ruby_21, :ruby_22 do
# Upload documentation
gem 'relish', '~> 0.7.1'
end
Expand Down
15 changes: 15 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## [v0.8.0](https://github.com/cucumber/aruba/compare/v0.7.4...v0.8.0)
* Make aruba compatible with "ruby 1.8.7" and "ruby 1.9.3" again (fixes #279)
* Move more and more documentation to cucumber steps (partly fixes #268)
* Refactoring of test suits, now rspec tests run randomly
* Move Aruba constants to configuration class (fixes #271)
* Added runtime configuration via `aruba.config` which is reset for each test run
* Refactored hooks: now there are `after()` and `before()`-hooks, old
before_cmd-hook is still working, but is deprecated, added new
`after(:command)`-hook.
* Refactored jruby-startup helper
* Cleanup API by moving deprecated methods to separte class
* Cleanup Core API - reduced to `cd`, `expand_path`, `setup_aruba` and use expand_path wherever possible (fixes #253)
* Better isolation for environment variable manipulation - really helpful from 1.0.0 on

## [v0.7.4](https://github.com/cucumber/aruba/compare/v0.7.2...v0.7.4)
* Really Fixed post install message

Expand All @@ -21,6 +35,7 @@
* Improve development environment (issue #240)
* Cleanup process management (issue #257)
* Make path content available through matchers and api metchods (issue #250)
* Refactor announcer to support user defined announce channels (fixes #267)

## [v0.6.2](https://github.com/cucumber/aruba/compare/v0.6.1...v0.6.2)
* Fixed minor issue #223)
Expand Down
3 changes: 3 additions & 0 deletions aruba.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ With aruba >= 1.0
* "ruby 1.8.7"-support is discontinued
* aruba requires "cucumber 2" for the feature steps. The rest of aruba should be usable by whatever testing framework you are using
* "aruba/reporting" will be removed. Please use `@debug`-tag + `byebug`, `debugger`, `pry` to troubleshoot your feature tests
* Set environment variables will have only effect on `#run` and the like + `#with_environment { }`
* The process environment will be fully resetted between tests. Sharing state via ENV['VAR'] = 'shared state' between tests will not be possible anymore. Please make that obvious by using explicit steps or use the aruba API for that.
* There will be a major cleanup for command execution. There will be only `run` and `run_simple` left. `run_interactive` is replaced by `run`.
EOS

s.files = `git ls-files`.split("\n")
Expand Down
118 changes: 118 additions & 0 deletions features/api/environment/append_environment_variable.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
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:
"""
require 'spec_helper'
RSpec.describe 'Long running command', :type => :aruba do
before(:each) { append_environment_variable 'LONG_LONG_VARIABLE', 'a' }
before(:each) { run('env') }
it { expect(last_command.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:
"""
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') }
it { expect(last_command.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:
"""
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') }
it { expect(last_command.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:
"""
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') }
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:
"""
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') }
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
118 changes: 118 additions & 0 deletions features/api/environment/prepend_environment_variable.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
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` 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:
"""
require 'spec_helper'
RSpec.describe 'Long running command', :type => :aruba do
before(:each) { prepend_environment_variable 'LONG_LONG_VARIABLE', 'a' }
before(:each) { run('env') }
it { expect(last_command.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:
"""
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('env') }
it { expect(last_command.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:
"""
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('env') }
it { expect(last_command.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:
"""
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('env') }
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:
"""
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('env') }
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
Loading

0 comments on commit 663991e

Please sign in to comment.