鑑於以下輔助方法,我將如何使用rspec
正確地測試該方法?測試rails helper呈現部分
def datatable(rows = [], headers = [])
render 'shared/datatable', { :rows => rows, :headers => headers }
end
def table(headers = [], data = [])
render 'shared/table', headers: headers, data: data
end
我試過以下,但我得到的錯誤:can't convert nil into String
describe 'datatable' do
it 'renders the datatable partial' do
rows = []
headers = []
helper.should_receive('render').with(any_args)
datatable(rows, headers)
end
end
Rspec的輸出
Failures:
1) ApplicationHelper datatable renders the datatable partial
Failure/Error: datatable(rows, headers)
TypeError:
can't convert nil into String
# ./app/helpers/application_helper.rb:26:in `datatable'
# ./spec/helpers/application_helper_spec.rb:45:in `block (3 levels) in <top (required)>'
./app/helpers/application_helper.rb:26
render 'shared/datatable', { :rows => rows, :headers => headers }
視圖/共享/ _datatable.html.haml
= table headers, rows
視圖/共享/ _table.html.haml
%table.table.dataTable
%thead
%tr
- headers.each do |header|
%th= header
%tbody
- data.each do |columns|
%tr
- columns.each do |column|
%td= column
哪一行產生此錯誤? – samuil
我已經更新了這個問題w /一些額外的細節 –