LoginSignup
1
1

More than 5 years have passed since last update.

Aruba gem - Environment

Posted at

Aruba の Environment 周りについてまとめます。

サンプル

append_environment_variable

require 'spec_helper'

RSpec.describe 'Environment', :type => :aruba do
  context 'append_environment_variable' do
    before(:each) { append_environment_variable 'HOGE_VARIABLE', 'a' }
    before(:each) { run('env') }
    before(:each) { stop_all_commands }

    it { expect(last_command_started.output).to include 'HOGE_VARIABLE=a' }
  end
end
  • 実行結果
$ rspec -fd -c ./spec/environment/append_environment_variable_spec.rb

Environment
  append_environment_variable
    should include "HOGE_VARIABLE=a"

Finished in 0.11345 seconds (files took 0.22137 seconds to load)
1 example, 0 failures

with_environment

require 'spec_helper'

RSpec.describe 'Environment', :type => :aruba do
  context 'with_environment' do
    it do
      with_environment 'HOGE_VARIABLE' => 'd' do
        expect(ENV['HOGE_VARIABLE']).to eq 'd'
      end
    end
  end
end
  • 実行結果
$ rspec -fd -c ./spec/environment/with_environment_spec.rb

Environment
  with_environment
    should eq "d"

Finished in 0.00567 seconds (files took 0.23039 seconds to load)
1 example, 0 failures

prepend_environment_variable

require 'spec_helper'

RSpec.describe 'Environment', :type => :aruba do
  context 'prepend_environment_variable' do
    before(:each) { prepend_environment_variable 'HOGE_VARIABLE', 'a' }

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

    it { expect(last_command_started.output).to include 'HOGE_VARIABLE=a' }
  end
end
  • 実行結果
$ rspec -fd -c ./spec/environment/prepend_environment_variable_spec.rb

Environment
  prepend_environment_variable
    should include "HOGE_VARIABLE=a"

Finished in 0.11504 seconds (files took 0.21995 seconds to load)
1 example, 0 failures

delete_environment_variable

require 'spec_helper'

ENV['HOGE_VARIABLE'] = 'a'
RSpec.describe 'Environment', :type => :aruba do
  context 'delete_environment_variable' do
    before(:each) { delete_environment_variable 'HOGE_VARIABLE' }
    before(:each) { run('env') }
    before(:each) { stop_all_commands }

    it { expect(last_command_started.output).not_to include 'HOGE_VARIABLE=a' }
  end
end
  • 実行結果
$ rspec -fd -c ./spec/environment/delete_environment_variable_spec.rb

Environment
  delete_environment_variable
    should not include "HOGE_VARIABLE=a"

Finished in 0.11695 seconds (files took 0.22419 seconds to load)
1 example, 0 failures

外部資料

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1