File: defaults_spec.rb

package info (click to toggle)
ruby-simplecov 0.22.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,500 kB
  • sloc: ruby: 5,550; makefile: 10
file content (41 lines) | stat: -rw-r--r-- 1,202 bytes parent folder | download | duplicates (2)
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
# frozen_string_literal: true

require "helper"

describe SimpleCov do
  skip "requires the default configuration" if ENV["SIMPLECOV_NO_DEFAULTS"]

  context "profiles" do
    let(:config_class) do
      Class.new do
        include SimpleCov::Configuration

        def load_profile(name)
          configure(&SimpleCov.profiles[name.to_sym])
        end
      end
    end

    let(:config) { config_class.new }

    def filtered?(config, filename)
      path = File.join(SimpleCov.root, filename)
      file = SimpleCov::SourceFile.new(path, [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil])
      config.filters.any? { |filter| filter.matches?(file) }
    end

    it "provides a sensible test_frameworks profile" do
      config.load_profile(:test_frameworks)
      expect(filtered?(config, "foo.rb")).not_to be
      expect(filtered?(config, "test/foo.rb")).to be
      expect(filtered?(config, "spec/bar.rb")).to be
    end

    it "provides a sensible rails profile" do
      config.load_profile(:rails)
      expect(filtered?(config, "app/models/user.rb")).not_to be
      expect(filtered?(config, "db/schema.rb")).to be
      expect(filtered?(config, "config/environment.rb")).to be
    end
  end
end