为什么我无法测试我的版本主义路线

时间:2012-11-03 05:14:36

标签: ruby-on-rails rspec

我有像这样的版本路线

api_version(:module => "api/v1", :path => "api/v1") do
  match '/files' => 'files#index', :via => :get
end

我的控制器app / controllers / api / v1 / files_controller.rb

class Api::V1::FilesController < ApplicationController

  def index
  end

end
root / spec / controllers / api / v1 / files_controller_spec.rb中的

spec

require 'spec_helper'

describe Api::V1::FilesController do

  describe "routing" do

    it "should routes to version-1 api" do
      expect(:get => "/api/v1/files").to route_to("api/v1/files#index")
    end

  end

end

命令rake routes给我一个我这样的路由列表

devise/registrations#edit
                          PUT    /users(.:format)  devise/registrations#update
                          DELETE /users(.:format)  devise/registrations#destroy
             api_v1_files GET    /api/v1/files(.:format)      api/v1/files#index

当我运行rake规范:控制器时,规格会下降。

F

Failures:

1) Api::V1::FilesController routing should routes to version-1 api
 Failure/Error: Unable to find matching line from backtrace
 NoMethodError:
   undefined method `[]' for nil:NilClass
 # /home/dilshod/.rvm/gems/ruby-1.9.2-p290/gems/moped-1.2.7/lib/moped/node.rb:74:in `block in command'
 # /home/dilshod/.rvm/gems/ruby-1.9.2-p290/gems/moped-1.2.7/lib/moped/n

我做错了什么?

1 个答案:

答案 0 :(得分:0)

解决更新RUBY到1.9.3的问题