Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

procs inside of arrays in :with and :returns options of the expects-m…

…ethod are now evaluated.

This allows things like:
  expects :update_attribute, :on => user_proc, :with => [:name, proc{ current_user.name }]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
commit 37fb41206248f7e35fd16b49da91cc7d28bcc9f3 1 parent 580804d
@yolk yolk authored josevalim committed
View
2  remarkable_rails/lib/remarkable_rails/action_controller/macro_stubs.rb
@@ -560,6 +560,8 @@ def run_action!(use_expectations=true, verb=nil, action=nil, params=nil, mime=ni
def evaluate_value(duck) #:nodoc:
if duck.is_a?(Proc)
self.instance_eval(&duck)
+ elsif duck.is_a?(Array)
+ duck.map{|child_duck| evaluate_value(child_duck) }
else
duck
end
View
26 remarkable_rails/spec/action_controller/macro_stubs_spec.rb
@@ -122,6 +122,32 @@ def current_id; '37'; end
teardown_mocks_for_rspec
end
end
+
+ describe 'with array in options' do
+ expects :find, :on => Task, :with => [proc{ current_id }, 1], :returns => [proc{ current_id }, 2]
+
+ it 'should evaluate all procs in :with option' do
+ run_expectations!
+
+ lambda {
+ Task.find(1)
+ }.should raise_error(Spec::Mocks::MockExpectationError, /expected :find with \("37"\, 1\) but received it with \(1\)/)
+
+ lambda {
+ Task.find("37", 1)
+ }.should_not raise_error
+ end
+
+ it 'should evaluate all procs in :returns option' do
+ run_expectations!
+
+ Task.find("37", 1).should eql(["37", 2])
+ end
+
+ after(:each) do
+ teardown_mocks_for_rspec
+ end
+ end
describe 'when extending describe group behavior' do
expects :find, :on => Task, :with => proc{ current_id }, :returns => task_proc
Please sign in to comment.
Something went wrong with that request. Please try again.