黄瓜奇怪的路线问题
我正在 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:我的创建方法
respond_to :html
def create
@expense = Expense.new(params[:expense])
if @expense.save
flash[:notice] = "The expense was successfully created"
end
respond_with @expense
end
I'm doing a simple app in rails without using cucumber
I have this user story:
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"
In development mode I followed the same steps and I got the expected results, but running this with cucumber I get this error message
(::) 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'
I already set the correct path in the path.rb
when /the "(.+)" expense page/
"/expenses/#{Expense.find_by_title($1).id}"
because of that, the expected path corresponding to the result of the previous code, it's right, but the got result don't.
When I added the "Then show me the page" after submitting the button I get a simple page with this message:
You are being redirected.
But as I said before this doesn't happen in development mode and also I've checked that the record is successfully stored into the database, so I don't know where could be the problem, Does anyone can help me please?
Greetings
PS: my create method
respond_to :html
def create
@expense = Expense.new(params[:expense])
if @expense.save
flash[:notice] = "The expense was successfully created"
end
respond_with @expense
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是 webrat 与 Rails 3 的兼容性问题,
与 this,并且有解决方案,一个简单的 webrat gem 补丁
The problem was a webrat compatibility issue with rails 3,
It was the same problem of this, and there is the solution, a simple patch to the webrat gem
在我看来,您的
paths.rb
配置正确,但您的create
操作却重定向回expenses_path
。It looks to me like your
paths.rb
is configured correctly, but it's yourcreate
action that's redirecting back toexpenses_path
instead.