Rspec JSON测试结果具有错误的日期格式

时间:2018-11-27 18:07:03

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

我尝试测试我正在研究的Api。我也得到了正确的答复,但dateformat似乎已更改

来自 <android.support.design.widget.BottomNavigationView . . . app:labelVisibilityMode="labeled" />

2018-11-27 18:03:44.000000000 +0000

2018-11-27T18:03:44.000Z

这是规格

expected: [{"created_at"=>2018-11-27 18:03:44.000000000 +0000, "email"=>"jennettesaway...UfR7oeVa5.ZaWXce2qtn6Em2oSQuH6Iljqhx61BI7cvE3CG", "updated_at"=>2018-11-27 18:03:44.000000000 +0000}]

got: [{"created_at"=>"2018-11-27T18:03:44.000Z", "email"=>"georgene@champlin.biz...4$JlzdvIUfR7oeVa5.ZaWXce2qtn6Em2oSQuH6Iljqhx61BI7cvE3CG", "updated_at"=>"2018-11-27T18:03:44.000Z"}]

那是我的控制人

RSpec.describe UsersController, type: :request do

   let!(:user) { Fabricate(:user) }
   let(:valid_attributes) { Fabricate.attributes_for :user }
   let(:invalid_attributes) { Fabricate.attributes_for :invalid_user }
    # set headers for authorization
   #let(:headers) { { 'Authorization' => token_generator(user.id) } }
   let(:headers) { valid_headers }

   describe "GET #index" do
    before(:each) do
      #allow(request).to receive(:headers).and_return(headers)
    end

    it "returns a success response" do
      get "/users", params: {}, headers: valid_headers
      expect(json).to eq [user.as_json]
    end
   end
end

class UsersController < ApplicationController skip_before_action :authorize_request, only: :create before_action :set_user, only: [:show, :update, :destroy] # GET /users # GET /users.json def index @users = User.all render json: @users end end 方法

json

我以前从未遇到过这个问题。我必须更改什么?

0 个答案:

没有答案