Skip to content

Commit

Permalink
Fix docs and specs for calling functions directly
Browse files Browse the repository at this point in the history
When using subject.call() to test functions, the arguments need to be passed
as a single Array.

Closes #27
  • Loading branch information
rodjek committed Feb 24, 2013
1 parent 3f3efcb commit b73e6d4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
12 changes: 6 additions & 6 deletions README.md
Expand Up @@ -258,7 +258,7 @@ Puppet functions.

```ruby
it 'should be able to do something' do
subject.call('foo') == 'bar'
subject.call(['foo']) == 'bar'
end
```

Expand Down Expand Up @@ -302,7 +302,7 @@ Or by using the `call` method on the subject directly

```ruby
it 'something' do
subject.call('foo', 'bar', ['baz'])
subject.call(['foo', 'bar', ['baz']])
end
```

Expand All @@ -319,8 +319,8 @@ Or by using any of the existing RSpec matchers on the subject directly

```ruby
it 'something' do
subject.call('foo') == 'bar'
subject.call('baz').should be_an Array
subject.call(['foo']) == 'bar'
subject.call(['baz']).should be_an Array
end
```

Expand All @@ -338,7 +338,7 @@ Or by using the existing `raises_error` RSpec matcher

```ruby
it 'something' do
expect { subject.call('a', 'b') }.should raise_error(Puppet::ParseError)
expect { subject.call('a') }.should_not raise_error(Puppet::ParseError)
expect { subject.call(['a', 'b']) }.should raise_error(Puppet::ParseError)
expect { subject.call(['a']) }.should_not raise_error(Puppet::ParseError)
end
```
11 changes: 3 additions & 8 deletions spec/functions/split_spec.rb
Expand Up @@ -2,16 +2,11 @@

describe 'split' do
it { should run.with_params('aoeu', 'o').and_return(['a', 'eu']) }
it { should run.with_params('foo').and_raise_error(Puppet::ParseError) }
it { should_not run.with_params('foo').and_raise_error(Puppet::DevError) }

it 'something' do
if Integer(Puppet.version.split('.').first) >= 3
expected_error = ArgumentError
else
expected_error = Puppet::ParseError
end
it { should run.with_params('foo').and_raise_error(Puppet::ParseError) }

expect { subject.call('foo') }.to raise_error(expected_error)
it 'should fail with one argument' do
expect { subject.call(['foo']) }.to raise_error(Puppet::ParseError)
end
end

0 comments on commit b73e6d4

Please sign in to comment.