BigW Consortium Gitlab

example_spec.rb 2.48 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
require 'spec_helper'

describe RspecFlaky::Example do
  let(:example_attrs) do
    {
      id: 'spec/foo/bar_spec.rb:2',
      metadata: {
        file_path: 'spec/foo/bar_spec.rb',
        line_number: 2,
        full_description: 'hello world'
      },
      execution_result: double(status: 'passed', exception: 'BOOM!'),
      attempts: 1
    }
  end
  let(:rspec_example) { double(example_attrs) }

  describe '#initialize' do
    shared_examples 'a valid Example instance' do
      it 'returns valid attributes' do
        example = described_class.new(args)

        expect(example.example_id).to eq(example_attrs[:id])
      end
    end

    context 'when given an Rspec::Core::Example that responds to #example' do
      let(:args) { double(example: rspec_example) }

      it_behaves_like 'a valid Example instance'
    end

    context 'when given an Rspec::Core::Example that does not respond to #example' do
      let(:args) { rspec_example }

      it_behaves_like 'a valid Example instance'
    end
  end

  subject { described_class.new(rspec_example) }

  describe '#uid' do
    it 'returns a hash of the full description' do
      expect(subject.uid).to eq(Digest::MD5.hexdigest("#{subject.description}-#{subject.file}"))
    end
  end

  describe '#example_id' do
    it 'returns the ID of the RSpec::Core::Example' do
      expect(subject.example_id).to eq(rspec_example.id)
    end
  end

  describe '#attempts' do
    it 'returns the attempts of the RSpec::Core::Example' do
      expect(subject.attempts).to eq(rspec_example.attempts)
    end
  end

  describe '#file' do
    it 'returns the metadata[:file_path] of the RSpec::Core::Example' do
      expect(subject.file).to eq(rspec_example.metadata[:file_path])
    end
  end

  describe '#line' do
    it 'returns the metadata[:line_number] of the RSpec::Core::Example' do
      expect(subject.line).to eq(rspec_example.metadata[:line_number])
    end
  end

  describe '#description' do
    it 'returns the metadata[:full_description] of the RSpec::Core::Example' do
      expect(subject.description).to eq(rspec_example.metadata[:full_description])
    end
  end

  describe '#status' do
    it 'returns the execution_result.status of the RSpec::Core::Example' do
      expect(subject.status).to eq(rspec_example.execution_result.status)
    end
  end

  describe '#exception' do
    it 'returns the execution_result.exception of the RSpec::Core::Example' do
      expect(subject.exception).to eq(rspec_example.execution_result.exception)
    end
  end
end