开发者

ROR 3.1 + Cucumber => Routes issue

It would be greatly appreciated if you could assist with the following issue/act of inexperience. I have searched the usual suspects (google, stackoverflow, groups, etc) to no avail and if I have missed something blatantly obvious my apologies.

I am starting to learn ROR3.1 plus cucumber through the following online tutorial at http://ridingrails.net/rails-3-cucumber-started-outside-in-testing/ which seems great except for my lack of success.

All good and well except that for some reason the one step is beyond my reach, if you could assist it would be greatly appreciated.

The Feature:

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"

The Error:

Feature: User manages agents

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

The guilty parts according to me => paths.rb:

def path_to(page_name)
  case page_name

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

The web_steps.rb file is the standard one generated as described by the tutorial. Here is the function just in case:

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

Additional details that might assist:

ruby -v => ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux]

rails -v => Rails 3.1.0.rc5

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

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

If there are any other details required please let me know as I am stumped.

Thanking you in advance for any assistance.

EDIT rake routes output below:

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=开发者_Go百科>"destroy", :controller=>"agents"}

controller:

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

routes:

Outsidein::Application.routes.draw do

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

end


In your create action, when you successfully save the model, it redirects to the root_path - not the agents_path ... so you will need to change that path in the action, or your expectation in the features.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜