Skip to content

Conversation

@seikichi
Copy link

Consider the following test:

context do
  let(:blk) { [1, 2, 3] }
  it_is_asserted_by { blk == %w(a b c) }
end

The above test outputs the following report (blk is wrong!):

Failure/Error: Unable to find matching line from backtrace
          it_is_asserted_by { blk == %w(a b c) }
                              |   |
                              |   false
                              #<Proc:0x...>

This is because RSpec::PowerAssert.evaluate_example sends
wrong assertion proc pr to PowerAssert::Context.
The PowerAssert::Context calls
@assertion_proc.binding.eval('local_variables')
and uses the local variables to create reports.
Thus, PowerAssert::Context uses wrong local variables to create report.

This commit fixes the above problem by wrapping
the assertion proc pr in blk binding context.

Consider the following test:
```ruby
context do
  let(:blk) { [1, 2, 3] }
  it_is_asserted_by { blk == %w(a b c) }
end
```

The above test outputs the following report (`blk` is wrong!):
```
Failure/Error: Unable to find matching line from backtrace
          it_is_asserted_by { blk == %w(a b c) }
                              |   |
                              |   false
                              #<Proc:0x...>
```

This is because `RSpec::PowerAssert.evaluate_example` sends
wrong assertion proc `pr` to PowerAssert::Context.
The `PowerAssert::Context` calls
`@assertion_proc.binding.eval('local_variables')`
and uses the local variables to create reports.
Thus, `PowerAssert::Context` uses wrong local variables to create report.

This commit fixes the above problem by wrapping
the assertion proc `pr` in `blk` binding context.
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.

1 participant