Class: EagerEye::RSpec::Matchers::PassEagerEyeMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/eager_eye/rspec/matchers.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ PassEagerEyeMatcher

Returns a new instance of PassEagerEyeMatcher.



11
12
13
14
15
16
17
# File 'lib/eager_eye/rspec/matchers.rb', line 11

def initialize(options = {})
  @only = options[:only]
  @exclude = options[:exclude] || []
  @max_issues = options[:max_issues] || 0
  @issues = []
  @path = nil
end

Instance Method Details

#descriptionObject



47
48
49
50
51
52
# File 'lib/eager_eye/rspec/matchers.rb', line 47

def description
  desc = "pass EagerEye analysis"
  desc += " for #{@only.join(", ")}" if @only
  desc += " (max #{@max_issues} issues)" if @max_issues.positive?
  desc
end

#failure_messageObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/eager_eye/rspec/matchers.rb', line 27

def failure_message
  message = "expected #{@path} to pass EagerEye analysis"
  message += " (max #{@max_issues} issues)" if @max_issues.positive?
  message += ", but found #{@issues.count} issue(s):\n\n"

  @issues.group_by(&:file_path).each do |file, file_issues|
    message += "#{file}:\n"
    file_issues.each do |issue|
      message += "  Line #{issue.line_number}: [#{issue.detector}] #{issue.message}\n"
    end
    message += "\n"
  end

  message
end

#failure_message_when_negatedObject



43
44
45
# File 'lib/eager_eye/rspec/matchers.rb', line 43

def failure_message_when_negated
  "expected #{@path} to have EagerEye issues, but it passed"
end

#matches?(path) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
25
# File 'lib/eager_eye/rspec/matchers.rb', line 19

def matches?(path)
  @path = path
  configure_eager_eye
  analyzer = build_analyzer
  @issues = analyzer.run
  @issues.count <= @max_issues
end