我想用rspec测试API控制器。下面是简单的代码:
require 'rails_helper'
describe "GET /api/config" do
it 'routes GET to /api/config to Api::V1::ConfigsController#show' do
get '/api/config.json'
expect(response).to be_success
end
end
但我有个错误:
1) Configs API GET /api/config ro
我试图在Rails中的API控制器上运行一个单元测试。但它的行为并不像我想的那样。
这条线适用于:
post '/api/sessions', params
然而,这一行
post :create, params
将抛出错误
Failure/Error: post :create
URI::InvalidURIError:
bad URI(is not URI?): http://www.example.com:80create
我可以使用第一个语法,但最好知道为什么第二个语法不起作用?因为我记得在以前的项目中使用过这个语法,而且它可以工作。我不记得在我的RSpec配置
我有很多Azure函数,现在我想把Azure管理放在前面。
我已经从我帐户中的2或3个其他功能应用程序中导入了所有功能,没有任何问题,但我对其中一个功能应用程序有问题。这个函数应用程序有6个功能,其中3个我可以导入罚款,如果我选择的具体。其他三个函数中的一些内容是抛出一个错误:
All template parameters used in the UriTemplate must be defined in the Operation, and vice-versa.
这里是由Azure函数本身创建的Swagger文档的相关部分:
paths:
'/api/api-keys/
我似乎无法解决以下问题。
Spec:(spec/api/power_ups_spec.rb)
describe Api::PowerUpsController, :type => :controller do
describe "GET power_ups" do
it "returns all power-ups" do
FactoryGirl.create :power_up, name: "Increase rate of take", description: "You gain points mor
它工作得很好。返回了正确的市场数据。
import requests
import urllib
class Robinhood(object):
# All known endpoints as of September 5th, 2015
endpoints = {
"quotes": "https://api.robinhood.com/quotes/",
"user": "https://api.robinhood.com/user/",
"user/additional_info
Springfox不能正确生成像这样的简单情况下的swagger文档:
GET /api/departments - Gets all department
GET /api/departments?name=IT - Gets a department with name passed as query parameter
这是Spring控制器:
@ApiOperation(value = "Gets all departments", notes = "", tags = {"departments"})
@RequestMapping(v
我正在我的应用程序上实现一个API,并使用Rspec进行测试。
我的项控制器没有new或edit操作,而且routes.rb没有它们的路由:
namespace :api, defaults: {format: 'json'} do
namespace :v1 do
resources :items, except: [:new, :edit]
end
end
我对他们的rspec测试看起来如下:
it "raises error on #new" do
expect(:get => "/api/v1/items/n
在我的葡萄/Rails应用程序中,我已经在ApplicationController中实现了维护模式,所以当该模式处于活动状态时,它将从应用程序中的任何位置重定向到maintenance_mode_path。如何迫使rspec在一段时间内处于不同的端点。api/v1/new_endpoint,而整个测试是在MaintenanceModeController中进行的?
maintenance_mode_controller_spec
context 'when maintenance mode is active' do
context 'when current
我有一个控制器规范,如下所示:
# config_controller_spec.rb
require "spec_helper"
describe Api::V4::ConfigController, type: :controller do
let(:parsed_response) { response.body.to_json }
describe 'GET app_config' do
it "renders successfully" do
get :app_config
expect(r
lib/modules/api.rb
module Api
require 'net/http'
require 'json'
def send_get_request(url, body)
# some logic
end
end
控制员:
class DashboardController < ApplicationController
include Api
def index
response = send_get_request(_some_, _params_)[:json]
@somethi
我正试图按照Yehuda的书“”第13章中提供的示例为我的Ruby项目创建一个JSON。下面是第353页中描述的适合我的环境的RSpec测试。
# /spec/api/v1/farms_spec.rb # Reduced to the minimum code.
require "spec_helper"
include ApiHelper # not sure if I need this
describe "/api/v1/farms", type: :api do
context "farms viewable by this user&