erikedin / Behavior.jl

Tool for Behavior Driven Development in Julia
Other
25 stars 3 forks source link

Display file name on error in step file #107

Closed m-charlton closed 2 years ago

m-charlton commented 2 years ago

Enhancement

File name not displayed when error caught in step file

How to reproduce

In a 'steps' file(s), for a step used in an existing scenario, introduce an intentional error:

# features/steps/ExperimentSteps.jl

@given("a machine filled with coffee beans") do context
    # Should be 'Machine(coffee=5.0)' not 'machine(coffee=5.0)'
    context[:machine] = machine(coffee=5.0)
end

Run the tests

(MPackage) pkg> test
     Testing MPackage
     ...
     Testing Running tests...

Feature: Making Coffee
  Scenario: Making a regular coffee
    Given a machine filled with coffee beans

        Exception: UndefVarError(:machine)
          (::var"#3#6")(context::Behavior.StepDefinitionContext) at string:18

Instead of the name of the file, we get 'string:18'

Solution

The built-in include_string (base/loading.jl) can take an optional filename argument, the default value being 'string'.

With the file name being passed:

        Exception: UndefVarError(:machine)
          (::var"#3#6")(context::Behavior.StepDefinitionContext) at ExperimentSteps.jl:18
          #2 at stepdefinitions.jl:140 [inlined]
erikedin commented 2 years ago

Hi! Sorry, I've been focused on other things recently, and completely missed that I had this PR waiting. Thanks for the improvement! I'll make a patch release that includes this.