我在不使用黄瓜的情况下在 Rails 中做一个简单的应用程序
我有这个用户故事:
Scenario: add new expense
Given I am on the expenses page
When I follow "new expense"
Then I am on new expense page
Then I fill in "expense_title" with "french fries"
Then I fill in "expense_category" with "Lunch"
Then I fill in "expense_amount" with "2300"
And I press "expense_submit"
And I should be on the "french fries" expense page
Then I should see "The expense was successfully created"
在开发模式下,我遵循了相同的步骤,得到了预期的结果,但是用黄瓜运行它,我得到了这个错误消息
(::) failed steps (::)
expected: "/expenses/2",
got: "/expenses" (using ==) (RSpec::Expectations::ExpectationNotMetError)
./features/step_definitions/web_steps.rb:260:in `/^(?:|I )should be on (.+)$/'
features/expenses.feature:14:in `And I should be on the "french fries" expense page'
我已经在 path.rb 中设置了正确的路径
when /the "(.+)" expense page/
"/expenses/#{Expense.find_by_title($1).id}"
正因为如此,与前面代码的结果对应的预期路径是正确的,但得到的结果却不是。
当我在提交按钮后添加“然后显示页面”时,我得到一个带有此消息的简单页面:
You are being redirected.
但正如我之前所说,这在开发模式下不会发生,而且我已经检查过记录是否已成功存储到数据库中,所以我不知道问题出在哪里,有人可以帮助我吗?
问候
PS:我的创建方法
响应:html
def create
@expense = Expense.new(params[:expense])
if @expense.save
flash[:notice] = "The expense was successfully created"
end
respond_with @expense
end