Sha256: b12270dbac6f058875605f6f797834b09a9da87fe3d72fe94f7524be7fcf1d93

Contents?: true

Size: 1.71 KB

Versions: 3

Compression:

Stored size: 1.71 KB

Contents

require 'digest'

RSpec.describe Percy::Client::Resources, :vcr do
  let(:content) { 'hello world!' }
  let(:sha) { Digest::SHA256.hexdigest(content) }

  describe 'Percy::Client::Resource' do
    it 'can be initialized with minimal data' do
      resource = Percy::Client::Resource.new('/foo.html', sha: sha)
      expect(resource.serialize).to eq({
        'type' => 'resources',
        'id' => sha,
        'attributes' => {
          'resource-url' => '/foo.html',
          'mimetype' => nil,
          'is-root' => nil,
        },
      })
    end
    it 'can be initialized with all data' do
      resource = Percy::Client::Resource.new(
        '/foo.html',
        sha: sha,
        is_root: true,
        mimetype: 'text/html',
        content: content,
      )
      expect(resource.serialize).to eq({
        'type' => 'resources',
        'id' => sha,
        'attributes' => {
          'resource-url' => '/foo.html',
          'mimetype' => 'text/html',
          'is-root' => true,
        },
      })
    end
    it 'errors if not given sha or content' do
      expect { Percy::Client::Resource.new('/foo.html') }.to raise_error(ArgumentError)
    end
  end
  describe '#upload_resource' do
    it 'returns true with success' do
      build = Percy.create_build('fotinakis/percy-examples')
      resources = [Percy::Client::Resource.new('/foo/test.html', sha: sha, is_root: true)]
      Percy.create_snapshot(build['data']['id'], resources, name: 'homepage')

      # Verify that upload_resource hides conflict errors, though they are output to stderr.
      expect(Percy.upload_resource(build['data']['id'], content)).to be_truthy
      expect(Percy.upload_resource(build['data']['id'], content)).to be_truthy
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
percy-client-0.2.2 spec/lib/percy/client/resources_spec.rb
percy-client-0.2.1 spec/lib/percy/client/resources_spec.rb
percy-client-0.2.0 spec/lib/percy/client/resources_spec.rb