【问题标题】:Cucumber weird routes problem黄瓜奇怪的路线问题
【发布时间】: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


    【解决方案1】:

    问题是 webrat 与 rails 3 的兼容性问题,

    和this一样的问题,有解决办法,给webrat gem打个简单的补丁

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • 不,不是,在开发模式下一切正常,因为它应该是,但不是黄瓜,这是我的问题
      • @forellana:您在 Cucumber 功能中使用的费用有效吗?
      • 是的,这是一个 webrat 路由问题,我用我对这个问题的回答解决了这个问题,谢谢
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多