Top Level Namespace

Defined Under Namespace

Modules: ApplicationFixtureHelper, PackageProtections, RuboCop

Instance Method Summary collapse

Instance Method Details

#get_resulting_rubocopObject



8
9
10
11
12
13
# File 'lib/package_protections/rspec/support.rb', line 8

def get_resulting_rubocop
  write_file('config/default.yml', <<~YML.strip)
    <%= PackageProtections.rubocop_yml(root_pathname: Pathname.pwd) %>
  YML
  YAML.safe_load(ERB.new(File.read('config/default.yml')).result(binding))
end

#offense(package_name, message, file, violation_type) ⇒ Object



1
2
3
4
5
6
7
8
9
10
11
12
# File 'lib/package_protections/rspec/matchers.rb', line 1

def offense(
  package_name, message, file, violation_type
)

  package = ParsePackwerk.all.find { |p| p.name == package_name }
  PackageProtections::Offense.new(
    package: package,
    message: message,
    file: file,
    violation_type: violation_type
  )
end

#serialize_offenses(actual_offenses) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/package_protections/rspec/matchers.rb', line 28

def serialize_offenses(actual_offenses)
  actual_offenses.map do |offense|
    <<~SERIALIZED_OFFENSE
      File: #{offense.file}
      Message: #{offense.message}
      Violation Type: #{offense.violation_type}
      Package: #{offense.package.name}
    SERIALIZED_OFFENSE
  end
end

#serialize_offenses_diff(actual_offenses, expected_offense) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/package_protections/rspec/matchers.rb', line 14

def serialize_offenses_diff(actual_offenses, expected_offense)
  color_by_match = ->(actual, expected) { actual == expected ? Rainbow(actual).green : "#{Rainbow(actual).red} (expected: #{expected})" }

  actual_offenses.map do |offense|
    # We color each field red or green depending on if the attributes match our expected
    <<~SERIALIZED_OFFENSE
      File: #{color_by_match.call(offense.file, expected_offense.file)}
      Message: #{color_by_match.call(offense.message, expected_offense.message)}
      Violation Type: #{color_by_match.call(offense.violation_type, expected_offense.violation_type)}
      Package: #{color_by_match.call(offense.package.name, expected_offense.package.name)}
    SERIALIZED_OFFENSE
  end
end