sconover / wrong

Wrong provides a general assert method that takes a predicate block. Assertion failure messages are rich in detail.
MIT License
434 stars 31 forks source link

NameError on otherwise un-referenced block arg in failing example #34

Open dchelimsky opened 11 years ago

dchelimsky commented 11 years ago

Given the following failing example in failing_example.rb

require 'wrong/adapters/rspec'

describe "a block arg in a failing assertion" do
  it "raises a NameError :(" do
    assert { [].each {|v|} != [] }
  end
end

When I run rspec failing_example.rb

Then I get this error:

F

Failures:

  1) a block arg in a failing assertion raises a NameError :(
     Failure/Error: assert { [].each {|v|} != [] }
       Expected [].each { |v| }.!=([]), but
           (v) raises NameError: undefined local variable or method `v' for #<RSpec::Core::ExampleGroup::Nested_1:0x007f938a0d1ef0>
     # ./failing_example.rb:5:in `block (2 levels) in <top (required)>'

The example should fail, that's not the problem. The problem is the failure message should indicate that the values were not equal, not a NameError on v

alexch commented 11 years ago

That's funny. My guess is that the parser doesn't distinguish between "v" in a block parameter list and "v" as a standalone statement. Should be fixable; thanks for pointing it out.