代码之家  ›  专栏  ›  技术社区  ›  Trip

黄瓜找不到路线?这可能是一个新的大问题

  •  0
  • Trip  · 技术社区  · 15 年前

    黄瓜

    Given /^that a user is logged in$/ do
      current_user = User.first
      render new_user_post_path(current_user)
    end
    

    路由.rb

    map.resources :users do |users|
      users.resources :posts, :collection => {:view => :get}
    end
    

    describe PostsController do
      describe "#new" do
        it "should be successful" do
          get :new
          response.should be_success
        end
      end
    end
    

    我的第一次大失败

    (::) failed steps (::)
    
    No route matches {:controller=>"posts", :action=>"new"} (ActionController::RoutingError)
    ./features/step_definitions/tasklist_steps.rb:3:in `/^that a user is logged in$/'
    features/tasklist.feature:7:in `Given that a user is logged in'
    
    Failing Scenarios:
    cucumber features/tasklist.feature:6 # Scenario: List SubmitLink
    
    1 scenario (1 failed)
    3 steps (1 failed, 2 skipped)
    0m0.147s
    rake aborted!
    

    1 回复  |  直到 15 年前
        1
  •  3
  •   bobbywilson0    14 年前

    首先,在Rails3路由中不推荐使用FirstOffMap,您可能应该有这样的内容。

    resources :users do 
        resources :posts
    end
    

    Given /^I have one user "([^\"]*)" with email "([^\"]*)" and password "([^\"]*)"$/ do |username,email, password|
      @user = User.new(:email => email,
                       :username=>username,
                       :password => password,
                       :password_confirmation => password)
       @user.save!
    end
    
    Given /^I am an authenticated user$/ do
      name = 'exmample'
      email = 'example@example.com'
      password = 'secret!'
    
      Given %{I have one user "#{name}" with email "#{email}" and password "#{password}"}
      And %{I go to the user login page}
      And %{I fill in "user_username" with "#{name}"}
      And %{I fill in "user_password" with "#{password}"}
      And %{I press "Sign in"}
    end
    

    Feature: 
      In order to reboot my crappy/POS equipment without bothering the awesome Noc Monkeys
      I would like to login to a webpage and see the status of and control the outlets on my equipment
    
      Background: Valid and authenticated user with at least one outlet to control
        Given I am an authenticated user
    
      @ok
      Scenario: Viewing All outlets
        Given I am able to control an outlet with index "1"
        And I am on the home page
        Then I should see "server_1"
    

    另外,通常我不会在cucumber步骤中调用render。因为您使用的是模拟浏览器(假设是webrat/capybara),所以 visit path_to(page_name) .