2014-02-26 35 views
2
块参数

可以说我有这个应用程序控制器:在另一个控制器的Rails如何测试方法接收使用RSpec

class ApplicationController < ActionController::Base 

    def example(&block) 
     ...code here 
    end 
end 

这:

class OtherController < ApplicationController 

    def index 
     example { some_text("irrelevant_text") } 
    end 

    private 

    def some_text var 
     "#{var}_string" 
    end 
end 

我想测试时调用索引操作example方法被调用与irrelevant_text_string说法。

喜欢的东西:

describe 'index' do 
    it 'should call example' do 
     controller.should_receive(:example).with("irrelevant_text_string") 
     get :index 
    end 
end 

但是,这是行不通的。我一直收到

received :example with unexpected arguments 
expected: ("irrelevant_text_string") 
      got: (no args) 

为什么说没有参数?
任何帮助将不胜感激

回答

0

因为你传递一个块,而不是一个参数。

+0

确定,以及如何我测试方法接收正确的块? – spiria