ROR 3.1 + Cucumber =>路线问题

时间:2011-08-01 19:22:09

标签: ruby-on-rails cucumber ruby-on-rails-3.1

如果您可以协助解决以下问题/缺乏经验,我们将不胜感激。我搜索了通常的嫌疑人(google,stackoverflow,群组等)无济于事,如果我错过了一些明显的道歉我的道歉。

我开始通过http://ridingrails.net/rails-3-cucumber-started-outside-in-testing/的以下在线教程学习ROR3.1 plus黄瓜,除了我的成功之外,这似乎很棒。

一切都很好,除了由于某种原因,一步超出了我的范围,如果你能提供帮助,我将不胜感激。

功能:

Feature: User manages agents
  Scenario: User adds a new agent
    Given I go to the new agent page
    And I fill in "Name" with "Alex"
    When I press "Create"
    Then I should be on the agent list page
    And I should see "Alex"

错误:

功能:用户管理座席

Scenario: User adds a new agent              # features/agent_management.feature:2
Given I go to the new agent page             # features/step_definitions/web_steps.rb:48
And I fill in "Name" with "Alex"             # features/step_definitions/web_steps.rb:60
When I press "Create"                        # features/step_definitions/web_steps.rb:52
Then I should be on the agent list page      # features/step_definitions/web_steps.rb:187
  expected: "/agents"
       got: "/" (using ==) (RSpec::Expectations::ExpectationNotMetError)
  ./features/step_definitions/web_steps.rb:190:in `/^(?:|I )should be on (.+)$/'
  features/agent_management.feature:6:in `Then I should be on the agent list page'
And I should see "Alex"          # features/step_definitions/web_steps.rb:105

Failing Scenarios:
cucumber features/agent_management.feature:2 # Scenario: User adds a new agent

根据我的有罪部分=> paths.rb:

def path_to(page_name)
  case page_name

  when /^the home\s?page$/
    '/'
  when /the agent list page/
    agents_path
  ...

web_steps.rb文件是本教程所描述的标准文件。以下是函数:

Then /^(?:|I )should be on (.+)$/ do |page_name|
  current_path = URI.parse(current_url).path
  if current_path.respond_to? :should
    current_path.should == path_to(page_name)
  else
    assert_equal path_to(page_name), current_path
  end
end

可能会有所帮助的其他详细信息

  

ruby​​ -v => ruby 1.9.2p180(2011-02-18修订版30909)[i686-linux]

     

rails -v => Rails 3.1.0.rc5

     

cat / proc / version / => Linux版本2.6.38-10-通用   (buildd @ vernadsky)(gcc版本4.5.2(Ubuntu / Linaro 4.5.2-8ubuntu4))

     

cat / etc / issue => Ubuntu 11.04 \ n \ l

如果还有其他详细信息,请告诉我,因为我很难过。

提前感谢您的任何帮助。

修改 rake路线输出如下:

root        /                                 {:controller=>"home", :action=>"index"}
agents GET    /agents(.:format)               {:action=>"index", :controller=>"agents"}
POST   /agents(.:format)                      {:action=>"create", :controller=>"agents"}
new_agent GET    /agents/new(.:format)        {:action=>"new", :controller=>"agents"}
edit_agent GET    /agents/:id/edit(.:format)  {:action=>"edit", :controller=>"agents"}
agent GET    /agents/:id(.:format)            {:action=>"show", :controller=>"agents"}
PUT    /agents/:id(.:format)                  {:action=>"update", :controller=>"agents"}
DELETE /agents/:id(.:format)                  {:action=>"destroy", :controller=>"agents"}

控制器:

class AgentsController < ApplicationController

  def index
    @agents = Agent.all
  end

  def new
    @agent = Agent.new
  end

  def create
    @agent = Agent.new(params[:agent])
    if @agent.save
      redirect_to root_path
    end
  end

end

路线:

Outsidein::Application.routes.draw do

  root :to => "home#index"
  resources :agents

end

1 个答案:

答案 0 :(得分:1)

在您的创建操作中,当您成功保存模型时,它会重定向到root_path - 而不是agents_path ...因此您需要更改操作中的路径或您对功能的期望。