Keith Bennett
Keith Bennett

Reputation: 4970

In RSpec, Is there a way to get information about the example to be tested for use in before(:each)?

I would like to keep track at runtime of the RSpec test currently being executed, preferably including its file name and line number, so that if a test hangs I can know where to find it. I'm thinking of simply writing the file name and line number to a file in a before(:each).

I realize I can see in the output the most recently executed test, but I would like to know the currently executing test.

Upvotes: 0

Views: 111

Answers (1)

pat
pat

Reputation: 16226

before(:each) yields an RSpec::Core::Example instance representing the current test/example, which should contain the information you're after.

before(:each) do |example|
  puts example.description
  puts example.location
  puts example.metadata
end

Upvotes: 4

Related Questions