Skip to content

Commit

Permalink
Merge pull request #3 from monkbroc/namespace-block-form
Browse files Browse the repository at this point in the history
Add block form to Nenv() helper method
  • Loading branch information
e2 committed Jan 16, 2015
2 parents 58ce856 + f47d908 commit e5dd87c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ puts git.pager
puts git.editor
```

Or in block form

```ruby
Nenv :git do |git|
puts git.browser
puts git.pager
puts git.editor
end
```

### Custom type handling

```ruby
Expand Down
4 changes: 3 additions & 1 deletion lib/nenv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
require 'nenv/builder'

def Nenv(namespace = nil)
Nenv::AutoEnvironment.new(namespace)
Nenv::AutoEnvironment.new(namespace).tap do |env|
yield env if block_given?
end
end

module Nenv
Expand Down
18 changes: 18 additions & 0 deletions spec/lib/nenv_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@
end
end

describe 'Nenv() helper method with block' do
it 'reads from env' do
expect(ENV).to receive(:[]).with('GIT_BROWSER').and_return('chrome')
Nenv('git') do |git|
git.browser
end
end

it 'return the value from env' do
allow(ENV).to receive(:[]).with('GIT_BROWSER').and_return('firefox')
result = nil
Nenv('git') do |git|
result = git.browser
end
expect(result).to eq('firefox')
end
end

describe 'Nenv module' do
it 'reads from env' do
expect(ENV).to receive(:[]).with('CI').and_return('true')
Expand Down

0 comments on commit e5dd87c

Please sign in to comment.