title: RSpec and Factory Girl - Error with datetime field
body: <p>I'm with the following problem:</p>
  
  <p>Environment: Ruby: 2.3.1 and Rails 5.0.0.1</p>
  
  <p>I'm trying to validate a datetime field with RSpec and Factory Girl.</p>
  
  <p>I got this error:</p>
  
  <pre><code>expected: "2016-11-11 13:30:31 UTC"  (From Factory Girl)
       got: "2016-11-11T13:30:31.218Z" (From database)
  </code></pre>
  
  <p>My code:</p>
  
  <pre><code>klass_object = FactoryGirl.create(:character)
  klass = Character
  
  
  RSpec.shared_examples 'API GET #index' do |klass|
    before { get :index, params: params, accept: Mime[:json] }
  
  
    it "returns a list of #{klass.to_s.underscore.pluralize}" do
      object_array = json(response.body)
  
      klass_attributes = klass.attribute_names.without("id", "created_at", "updated_at").map(&amp;:to_sym)
  
      klass_attributes.each do |attribute|
        object_array.each do |object|
          expect(object[attribute].to_s).to eq(klass_object[attribute].to_s)
        end
      end
    end
    ...
  end
  </code></pre>
  
  <p>Factory:</p>
  
  <pre><code>FactoryGirl.define do
    factory :character do
      marvel_id { Faker::Number.number(6).to_i }
      name { Faker::Superhero.name }
      description { Faker::Hipster.paragraphs(1) }
      modified { Faker::Date.between(DateTime.now - 1, DateTime.now) }
  
      factory :invalid_character do
        id ''
        name ''
        marvel_id ''
        modified ''
      end
    end
  </code></pre>
  
  <p>end</p>
  
  <p>How can I correct this problem?</p>
  
  <p>I did that, it works but I think it is not so good. There is a better way to do it?</p>
  
  <pre><code>    object_array.each do |object|
        if ActiveSupport::TimeWithZone == klass_object[attribute].class
          expect(object[attribute].to_datetime.strftime("%Y-%m-%d %H:%M:%S")).to eq(klass_object[attribute].to_datetime.strftime("%Y-%m-%d %H:%M:%S"))
        else
          expect(object[attribute].to_s).to eq(klass_object[attribute].to_s)
        end
      end
  </code></pre>
  
  <p>Thanks for your help.</p>