黄瓜奇怪的路线问题

时间:2010-12-16 01:22:22

标签: rspec cucumber bdd ruby-on-rails-3 webrat

我在铁轨中做一个简单的应用而不使用黄瓜

我有这个用户故事:

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

2 个答案:

答案 0 :(得分:1)

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

这是this的同样问题,并且有解决方案,webrat宝石的简单补丁

答案 1 :(得分:0)

我认为paths.rb已正确配置,但您的create操作会重定向回expenses_path

相关问题