黄瓜奇怪的路线问题

发布于 2024-10-08 04:41:03 字数 1478 浏览 0 评论 0原文

我正在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

_蜘蛛 2024-10-15 04:41:03

问题是 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

伪装你 2024-10-15 04:41:03

在我看来,您的 paths.rb 配置正确,但您的 create 操作却重定向回 expenses_path

It looks to me like your paths.rb is configured correctly, but it's your create action that's redirecting back to expenses_path instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文