【发布时间】:2010-12-16 01:22:22
【问题描述】:
我在 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"
在开发模式下,我按照相同的步骤操作,得到了预期的结果,但是用 cucumber 运行它会收到此错误消息
(::) 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
【问题讨论】:
标签: rspec cucumber bdd ruby-on-rails-3 webrat