Skip to content

Commit

Permalink
Make MockEnv#[]= more compatible with ENV.
Browse files Browse the repository at this point in the history
  • Loading branch information
marshall-lee committed Feb 7, 2016
1 parent 60afe58 commit ecdf57a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions spec/lib/nenv/environment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
RSpec.describe Nenv::Environment do
class MockEnv < Hash # a hash is close enough
def []=(k, v)
super(k.to_s, v.to_s)
fail TypeError, "no implicit conversion of #{k.class} into String" unless k.respond_to? :to_str
fail TypeError, "no implicit conversion of #{v.class} into String" unless v.respond_to? :to_str
super(k.to_str, v.to_str)
end
end

Expand Down Expand Up @@ -73,7 +75,7 @@ def []=(k, v)

context 'with no block' do
before { instance.create_method(:foo) }
let(:value) { 123 }
let(:value) { '123' }

it 'returns marshalled stored value' do
expect(subject.foo).to eq '123'
Expand Down Expand Up @@ -150,7 +152,7 @@ def []=(k, v)
before { instance.create_method(:foo_baz) }

it 'reads the correct variable' do
ENV['BAR_FOO_BAZ'] = 123
ENV['BAR_FOO_BAZ'] = '123'
expect(subject.foo_baz).to eq '123'
end
end
Expand Down

0 comments on commit ecdf57a

Please sign in to comment.