Skip to content

Compiler/Line Number Metadata #57

Closed
@wied03

Description

@wied03

Add an optional compiler helper that will add_special call nodes for describe, context, it, etc.

The modified code will still call describe, call, etc. but it will add a caller metadata attribute in implicitly to the arguments list. Caller should be an array with 1 element containing the filename and line number of the spec.

Will need to handle cases where:

  • User has already supplied the caller
  • Existing metadata being passed as a hash variable
  • Existing metadata passed with { }
  • Existing metadata passed with an implicit hash
  • No metadata being passed
  • No arguments at all (not sure if describe;do;end is valid)

It should be bootstrap compatible and configurable as to when this runs, some ideas:

  • Only files ending in _spec.rb
  • Use a compiler setting (we do have access to the compiler object in the call node, we can add an additional setting)
  • Opt in (need to require the compiler patch, this one is not mutually exclusive)

Testing:

  • Unit test with MRI - see note below
  • Unit test with bootstrap/Opal compilation
  • Maybe include in RSpec's specs so they can find location? It might be too difficult to test this so it might be easier to just have a separate integration test

Compiler test, the compiled version with the patch on:

describe 'foo' do
end

should equal this with the patch off:

describe 'foo', caller: ['/some/file/path.rb:123'] do
end

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions