Skip to content

Commit

Permalink
Delete :env keys from ENV
Browse files Browse the repository at this point in the history
  • Loading branch information
jc00ke committed Jan 10, 2012
1 parent 5aff4a4 commit 621e9c3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
4 changes: 4 additions & 0 deletions lib/mspec/helpers/ruby_exe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ def ruby_exe(code, opts = {})
`#{cmd.compact.join(' ')}`
ensure
saved_env.each { |key, value| ENV[key] = value }
env.keys.each do |key|
key = key.to_s
ENV.delete key if ENV.key? key
end
end
end
end
Expand Down
31 changes: 18 additions & 13 deletions spec/helpers/ruby_exe_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,6 @@ class RubyExeSpecs
@script.stub!(:`)
end

after :each do
ENV.delete "ABC"
end

it "preserves the values of existing ENV keys" do
ENV["ABC"] = "123"
ENV.should_receive(:[]).with("RUBY_FLAGS")
Expand All @@ -198,15 +194,24 @@ class RubyExeSpecs
@script.ruby_exe nil, :env => { :ABC => "xyz" }
end

it "resets the values of existing ENV keys when an exception is raised" do
ENV["ABC"] = "123"
ENV.should_receive(:[]=).with("ABC", "xyz")
ENV.should_receive(:[]=).with("ABC", "123")

@script.should_receive(:`).and_raise(Exception)
lambda do
@script.ruby_exe nil, :env => { :ABC => "xyz" }
end.should raise_error(Exception)
context "when an exception is raised" do
it "deletes the :env entries in ENV" do
ENV.should_receive(:key?).with("XYZ").twice.and_return(true)
ENV.should_receive(:delete).with("XYZ")
@script.ruby_exe nil, :env => { :XYZ => "xyz" }
end

it "resets the values of existing ENV keys" do
ENV["ABC"] = "123"
ENV.should_receive(:[]=).with("ABC", "xyz")
ENV.should_receive(:[]=).with("ABC", "123")

@script.should_receive(:`).and_raise(Exception)
lambda do
@script.ruby_exe nil, :env => { :ABC => "xyz" }
end.should raise_error(Exception)
end
end

end
end

0 comments on commit 621e9c3

Please sign in to comment.