【发布时间】:2019-05-29 10:44:18
【问题描述】:
我有一个通过的规范,如下所示:
scenario "Brand likes a comment", js: true do
visit post_path(question, as: brand)
within("#comment_#{comment.id}") do
click_on "Like"
end
expect(page).to have_text "Like •1"
end
我最近添加了一个带有 chart.js 图表的页面,我正在使用一个看起来像这样的 ajax 请求加载该图表的数据:
$.ajax({
url: "/admin/reporting/weekly_new_users",
type: "get",
dataType: "json",
cache: false,
success: function(response){
var ctx = document.getElementById("weeklyUsers");
new Chart(ctx, {
type: 'line',
data: {
labels: response.weekly_users.map(arr => arr[0]),
datasets: [{
label: '# of New Users',
data: response.weekly_users.map(arr => arr[1]),
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
],
borderColor: [
'rgba(255,99,132,1)',
],
borderWidth: 1
}]
},
});
}
})
};
此 ajax 请求导致我的 js:true 规范失败,并显示以下错误消息:
Failure/Error: raise ActionController::RoutingError, "No route matches [#{env['REQUEST_METHOD']}] #{env['PATH_INFO'].inspect}"
ActionController::RoutingError:
No route matches [GET] "/likes/1"
当我注释掉规范通过的 ajax 请求时。不知道是什么原因造成的,有什么想法吗?
【问题讨论】:
标签: ruby-on-rails ajax rspec capybara capybara-webkit