鉴于以下辅助方法,我将如何正确地使用rspec
?
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