Skip to content

Conversation

@schneems
Copy link
Collaborator

@schneems schneems commented Jan 21, 2026

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 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:

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
@Earlopain
Copy link
Contributor

I don't have much expertise but

both if and do require their own end

In the rspec case, you can't insert end anywhere to make it valid. If you do, the string literal takes the block, which is also bad syntax. If I read that message, that's how I would try to fix it.

But I don't have an idea how to spell it differently.

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

3 participants