我正在设置一个黄瓜方案来设置一个有效的用户,我的最后一步是:
“然后我应该被带到节目用户页面”
我定义为:
Then /I should be taken to the show user page/ do
@user = User.last
if current_path.respond_to? :should
current_path.should == path_to(user_path(@user))
else
assert_equal path_to(user_path(@user)), current_path
end
visit(user_path(@user))
end
收到错误后“无法找到从”/ users / 49“到路径的映射。”我试图将路径定义为:
when /^users\/(.+)$/ do |user|
user_path(user.to_i)
end
但这会产生错误:
语法错误,意外的keyword_do,期待keyword_then或','或';'或'\ n' 当/^landlords/(.+)$/做|房东|
我对rails和web开发相对较新,对黄瓜和TDD来说是全新的。也是正则表达式的新手。任何帮助将不胜感激!
谢谢,
约翰
答案 0 :(得分:3)
看起来user_path(@user)
正在为您提供所需的路径,因此将其包含在path_to
中会导致错误,因为它会尝试执行相同的操作。
我认为摆脱path_to
电话可能有所帮助:
current_path.should == user_path(@user)
答案 1 :(得分:0)
出现“意外的keyword_do”错误的原因是因为您 而不是何时,即Ruby将其解释为 case 式的陈述。但正如Jon M指出的那样,无论如何你都不需要。