File: spec_helper.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 (120 lines) | stat: -rw-r--r-- 3,034 bytes parent folder | download | duplicates (3)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# frozen_string_literal: true

require 'simplecov'
SimpleCov.minimum_coverage 100

class PrintingFormatter
  # Takes a SimpleCov::Result and generates a string out of it
  def format(result)
    bad = []
    result.files.each do |file|
      bad.push file if file.covered_percent < 100.0
    end

    unless bad.empty?
      puts 'Files with missing coverage!'
      bad.each do |file|
        lines = file.source_lines.select { |l| l.coverage == 0 }
                    .map(&:line_number).sort
        s = lines[0]
        groups = [[s, s]]
        lines.each do |i|
          if i <= groups[-1][-1] + 1
            groups[-1][-1] = i
          else
            groups.push([i, i])
          end
        end
        markers = []
        groups.each do |g|
          if g[0] == g[1]
            markers.push(g[0].to_s)
          else
            markers.push(g.join('-'))
          end
        end
        puts "#{file.filename}: #{markers.join(', ')}"
      end
    end
  end
end

SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new(
  [SimpleCov::Formatter::HTMLFormatter, PrintingFormatter]
)

SimpleCov.start do
  add_filter do |source_file|
    name = source_file.filename
    !(name.include?('/hypothesis-ruby/lib/') || name.end_with?('hypothesis.rb'))
  end
end

require 'hypothesis'

module Hypothesis
  module Debug
    class NoSuchExample < HypothesisError
    end

    def find(options = {}, &block)
      unless Hypothesis::World.current_engine.nil?
        raise UsageError, 'Cannot nest hypothesis calls'
      end
      begin
        Hypothesis::World.current_engine = Hypothesis::Engine.new(
          'find',
          max_examples: options.fetch(:max_examples, 1000),
          phases: options.fetch(:phases, Phase.all)
        )
        Hypothesis::World.current_engine.is_find = true
        Hypothesis::World.current_engine.run(&block)
        source = Hypothesis::World.current_engine.current_source
        raise NoSuchExample if source.nil?
        source.draws
      ensure
        Hypothesis::World.current_engine = nil
      end
    end

    def find_any(options = {}, &block)
      # Currently the same as find, but once we have config
      # options for shrinking it will turn that off.
      find(options, &block)
    end
  end
end

RSpec.configure do |config|
  config.expect_with :rspec do |expectations|
    expectations.include_chain_clauses_in_custom_matcher_descriptions = true
  end

  config.alias_example_to :they

  config.mock_with :rspec do |mocks|
    mocks.verify_partial_doubles = true
  end

  config.shared_context_metadata_behavior = :apply_to_host_groups

  config.example_status_persistence_file_path = 'spec/examples.txt'
  config.disable_monkey_patching!

  config.warnings = true

  config.default_formatter = 'doc'

  config.profile_examples = 10

  config.order = :random

  Kernel.srand config.seed

  config.include(Hypothesis)
  config.include(Hypothesis::Possibilities)

  config.before(:each) do
    FileUtils.rm_rf Hypothesis::DEFAULT_DATABASE_PATH
  end
end