저는 레일즈 4에 rspec_api_documentation을 사용하여 API를 만들고 있습니다. 정말 인상 깊었습니다. DoorKeeper를 사용하여 엔드 포인트를 보호하기로 결정한이 콘솔에서이 모든 것을 성공적으로 테스트 할 수있었습니다.rspec_api_documentation을 사용하여 Doorkeep 토큰 스텁하기
나는 이제 어떻게 문제를 풀어 내는지 명시하고 토큰을 스텁한다.
문지기의 문서는 다음과 같은 사용 제안 :
describe Api::V1::ProfilesController do
describe 'GET #index' do
let(:token) { stub :accessible? => true }
before do
controller.stub(:doorkeeper_token) { token }
end
it 'responds with 200' do
get :index, :format => :json
response.status.should eq(200)
end
end
end
을 그러나, 나는 rspec_api_documentation에 맞춰 수용 테스트를 작성했습니다. 내가 말했듯이
undefined local variable or method `controller' for #<RSpec::Core
나는 그것이 명시 적으로 컨트롤러 사양 아니기 때문에이 용의자 :하지만, 내가 테스트를 실행하면
require 'spec_helper'
require 'rspec_api_documentation/dsl'
resource "Projects" do
header "Accept", "application/json"
header "Content-Type", "application/json"
let(:token) { stub :accessible? => true }
before do
controller.stub(:doorkeeper_token) { token }
end
get "/api/v1/group_runs" do
parameter :page, "Current page of projects"
example_request "Getting a list of projects" do
status.should == 200
end
end
end
내가 다음 얻을 : 이것은 내가 쓴 그 projects_spec.rb
입니다 , 내 API를 테스트하는이 rspec_api_documentation 방법을 고집합니다.
확실히 누군가가해야만합니까? 토큰을 스터 빙할 수있는 다른 방법이 있습니까?
미리 감사드립니다.
여기를 보셨습니까? https://relishapp.com/rspec/rspec-rails/v/2-14/docs/controller-specs. 아마'rspec-rails' 보석이 포함되어 있는지 확인하고 예제에': type => : controller' 태그를 붙이시겠습니까? – zetetic