Skip to content

Conversation

@schneems
Copy link
Collaborator

A typo in RSpec is typing if instead of it. Depending on the font, they can be hard to distinguish at a glance:

if "does something" do  # Should be `it "does something" do`
  # ...
end

This results in a confusing "Unmatched keyword, missing end'?" error because both ifanddorequire their ownend. And some keywords like whileandlooptakedo, so it's not always obvious that iforunless` don't.

The message needs to accommodate a scenario where it's unknown if the value inside accepts a block like:

if method_call do
end

This might be perfectly valid ruby code, so you wouldn't want to assert "if does not take a do" (since that's not the problem...the problem is that both if and do require an end to close, but the code doesn't provide that.

Before:

Unmatched keyword, missing `end' ?

  2  describe "something" do
> 3    if "does something" do
> 5    end
  6  end

After:

Unmatched keyword, missing `end' ?
Both `if` and `do` require an `end`.

  2  describe "something" do
> 3    if "does something" do
> 5    end
  6  end

Close #206

A typo in RSpec is typing `if` instead of `it`. Depending on the font, they can be hard to distinguish at a glance:

```ruby
if "does something" do  # Should be `it "does something" do`
  # ...
end
```

This results in a confusing "Unmatched keyword, missing `end'?" error because both `if` and `do` require their own `end`. And some keywords like `while` and `loop` take `do`, so it's not always obvious that `if` or `unless` don't.

The message needs to accommodate a scenario where it's unknown if the value inside accepts a block like:

```ruby
if method_call do
   end
```

This might be perfectly valid ruby code, so you wouldn't want to assert "if does not take a do" (since that's not the problem...the problem is that both if and do require an `end` to close, but the code doesn't provide that).


Before:

```
Unmatched keyword, missing `end' ?

  2  describe "something" do
> 3    if "does something" do
> 5    end
  6  end
```

After:

```
Unmatched keyword, missing `end' ?
Both `if` and `do` require an `end`.

  2  describe "something" do
> 3    if "does something" do
> 5    end
  6  end
```

Close #206
@schneems schneems marked this pull request as ready for review January 21, 2026 03:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Accidental if instead of a block

2 participants