File: database_spec.rb

package info (click to toggle)
python-hypothesis 6.138.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 15,272 kB
  • sloc: python: 62,853; ruby: 1,107; sh: 253; makefile: 41; javascript: 6
file content (67 lines) | stat: -rw-r--r-- 1,896 bytes parent folder | download | duplicates (4)
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
# frozen_string_literal: true

RSpec.describe 'database usage' do
  it 'saves a minimal failing example' do
    expect do
      hypothesis do
        n = any integer
        expect(n).to be < 10
      end
    end.to raise_exception(RSpec::Expectations::ExpectationNotMetError)

    saved = Dir.glob("#{Hypothesis::DEFAULT_DATABASE_PATH}/*/*")
    expect(saved.length).to be == 1
  end

  it 'can be disabled' do
    expect do
      hypothesis(database: false) do
        n = any integer
        expect(n).to be < 10
      end
    end.to raise_exception(RSpec::Expectations::ExpectationNotMetError)
    expect(File.exist?(Hypothesis::DEFAULT_DATABASE_PATH)).to be false
  end

  it 'replays a previously failing example' do
    # This is a very unlikely value to be hit on by random. The first
    # time we run the test we fail for any value larger than it.
    # This then shrinks to exactly equal to magic. The second time we
    # run the test we only fail in this exact magic value. This
    # demonstrates replay from the previous test is working.
    magic = 17_658

    expect do
      hypothesis do
        n = any integer
        expect(n).to be < magic
      end
    end.to raise_exception(RSpec::Expectations::ExpectationNotMetError)

    expect do
      hypothesis do
        n = any integer
        expect(n).not_to be == magic
      end
    end.to raise_exception(RSpec::Expectations::ExpectationNotMetError)
  end

  it 'cleans out passing examples' do
    expect do
      hypothesis do
        n = any integer
        expect(n).to be < 10
      end
    end.to raise_exception(RSpec::Expectations::ExpectationNotMetError)

    saved = Dir.glob("#{Hypothesis::DEFAULT_DATABASE_PATH}/*/*")
    expect(saved.length).to be == 1

    hypothesis do
      any integer
    end

    saved = Dir.glob("#{Hypothesis::DEFAULT_DATABASE_PATH}/*/*")
    expect(saved.length).to be == 0
  end
end