module Ameba::Spec::ExpectIssue

Overview

This mixin makes it easier to specify strict issue expectations in a declarative and visual fashion. Just type out the code that should generate an issue, annotate code by writing '^'s underneath each character that should be highlighted, and follow the carets with a string (separated by a space) that is the message of the issue. You can include multiple issues in one code snippet.

Usage:

expect_issue subject, %(
  def foo
    a do
      b
    end.c
  # ^^^^^ error: Avoid chaining a method call on a do...end block.
  end
)

Equivalent assertion without #expect_issue:

source = Source.new %(
  def foo
    a do
      b
    end.c
  end
), "source.cr"
subject.catch(source).should_not be_valid
source.issues.size.should be(1)

issue = source.issues.first
issue.location.to_s.should eq "source.cr:4:3"
issue.end_location.to_s.should eq "source.cr:4:7"
issue.message.should eq(
  "Avoid chaining a method call on a do...end block."
)

If you do not want to specify an issue then use the companion method #expect_no_issues. This method is a much simpler assertion since it just inspects the code and checks that there were no issues. The #expect_issue method has to do more work by parsing out lines that contain carets.

Included Modules

Defined in:

ameba/spec/expect_issue.cr

Instance Method Summary

Instance methods inherited from module Ameba::Spec::Util

normalize_code(code, separator = '\n') normalize_code

Instance Method Detail

def expect_issue(rules : Rule::Base | Enumerable(Rule::Base), annotated_code : String, path = "", normalize = true, *, file = __FILE__, line = __LINE__, **replacements) #

[View source]
def expect_no_issues(rules : Rule::Base | Enumerable(Rule::Base), code : String, path = "", normalize = true, *, file = __FILE__, line = __LINE__) #

[View source]