Skip to content

Commit

Permalink
Add edge case specs
Browse files Browse the repository at this point in the history
These are unlikely, but we should handle them without errors.
  • Loading branch information
sambostock committed Oct 16, 2023
1 parent e74f994 commit fd1e1e0
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion spec/rubocop/cop/sorbet/signatures/empty_line_after_sig_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ def foo; end
bar!
RUBY
end

it("does not register an offense or fail if the sig and definition are on the same line") do
expect_no_offenses(<<~RUBY)
sig { void }; def foo; end
RUBY
end
end

context("with an empty line between sig and method definition") do
Expand Down Expand Up @@ -147,20 +153,49 @@ def initialize(
expect_offense(<<~RUBY)
sig { params(session: String).void }
# Session: string
^ Extra empty line or comment detected
# More stuff
# on more lines
^{} Extra empty line or comment detected
def initialize(session:)
@session = session
end
RUBY

expect_correction(<<~RUBY)
# Session: string
# More stuff
# on more lines
sig { params(session: String).void }
def initialize(session:)
@session = session
end
RUBY
end

it("registers an offense and does not fail if the sig is not the first expression on its line") do
expect_offense(<<~RUBY)
true; sig { void }
# Comment
^ Extra empty line or comment detected
def m; end
RUBY

expect_correction(<<~RUBY)
# Comment
true; sig { void }
def m; end
RUBY
end
end

it "registers no offense when there is only a method definition" do
expect_no_offenses(<<~RUBY)
def foo; end
RUBY
end
end

0 comments on commit fd1e1e0

Please sign in to comment.