我正在使用Rails 4.1,我有一个API json,但不适用于Rspec-Rails。
rspec-rails - 版本使用3.2.1
$ rake routes
GET /cities/:code(.:format) cities#show
cities_controller.rb
class CitiesController < ApplicationController
respond_to :json
def show
code = params[:code]
respond_with City.find_by_code(code)
end
end
cities_controller_spec.rb
require 'rails_helper'
RSpec.describe CitiesController, :type => :controller do
describe "GET city" do
it "should be ok" do
get '/cities', :code => 'DUB', :format => :json
expect(response).to be_success
expect(response).to have_http_status(200)
end
end
end
当我执行rspec时,我收到了这个
Failure/Error: data = get '/cities', :code => 'DUB', :format => :json
ActionController::UrlGenerationError:
No route matches {:action=>"/cities", :controller=>"cities", :code=>"DUB", :format=>:json}
有什么想法吗?
谢谢!
答案 0 :(得分:2)