JSON :: ParserError:757:意外令牌

时间:2015-02-08 09:31:00

标签: ruby ruby-on-rails-4 testing rspec

我正在使用rspec测试控制器,我收到此错误 测试: quizes_controller_spec.rb:

 require 'rails_helper'
    require 'spec_helper'

RSpec.describe Api::QuizzesController, :type => :controller do
    before (:each) do
        @instructor = create(:instructor)
    end
describe "instructor_index method" do
        it "returns all quizzes of the current instructor" do
            sign_in @instructor
            @quiz = create(:quiz)
            @instructor.quizzes << @quiz
            get :instructor_index
            quiz_response = json(response.body)
            expect(response.status).to eq(200)
            expect(quiz_response[:success]).to eql(true)
            expect((quiz_response[:data][:quizzes]).first[:name]).to eql(@quiz.name)
        end
    end
end

在索引方法中,它正在渲染教师的测验: quizzes_controller.rb:

def instructor_index
            quizzes = current_instructor.quizzes
            render json: { success:true, data:{:quizzes => quizzes},info:{} }, status: 200
        end

aftur runnig rspec出现此错误:

  

Api :: QuizzesController instructor_index方法返回当前教师的所有测验        失败/错误:quiz_response = json(response.body)        JSON :: ParserError:          757:意外令牌在&#39;你正在redirected。&#39;        #./spec/rails_helper.rb:9:in json' # ./spec/controllers/quizzes_controller_spec.rb:60:in阻止(3级)&#39;

rails_helper.rb:

def json(body)  
  JSON.parse(body, symbolize_names: true) 
end

0 个答案:

没有答案