Skip to content

Commit

Permalink
Merge pull request #144 from doc75/return_regexp
Browse files Browse the repository at this point in the history
add capability to check return code of function using regexp
  • Loading branch information
timtim123456 committed Jan 25, 2014
2 parents dd635cd + ac08115 commit a3161d3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/rspec-puppet/matchers/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ def matches?(func_obj)
else
unless @expected_return.nil?
@actual_return = @func.call
@actual_return == @expected_return
case @expected_return
when Regexp
@actual_return =~ @expected_return
else
@actual_return == @expected_return
end
else
begin
@func.call
Expand Down
9 changes: 9 additions & 0 deletions spec/functions/regsubst_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'spec_helper'

describe 'regsubst' do
# used to test the fact that expected result can be a regexp
it { should run.with_params('thisisatest', '^192', '254').and_return(/sat/) }
it { should run.with_params('thisisatest', 'sat', 'xyz').and_return(/ixyze/) }
it { should run.with_params('thisisatest', 'sat', 'xyz').and_return('thisixyzest') }
it { should run.with_params('thisisatest', 'sat', 'xyz').and_return(/^thisixyzest$/) }
end

0 comments on commit a3161d3

Please sign in to comment.