print spec file path

19 views
Skip to first unread message

Joao Miguel Ferreira

unread,
Jun 11, 2021, 11:30:21 AM6/11/21
to rspec
Hello all,

Is there a way to ask rspec to print the path of the file from which tests are being run?

Thank you
Joao

Mohit Sindhwani

unread,
Jun 21, 2021, 8:09:20 AM6/21/21
to rs...@googlegroups.com, Joao Miguel Ferreira
Hi Joao,

Did you find an answer?

On 2021-6-11 11:30 pm, Joao Miguel Ferreira wrote:
> Hello all,
>
> Is there a way to ask rspec to print the path of the file from which
> tests are being run?

Today, while reading the 'Effective Testing with RSpec 3' book, I found
that you can access metadata in the context level:

RSpec.describe 'My Exciting Class' do
  puts metadata

  context 'when condition' do
    it 'succeeds' do
    end
  end
end

The metadata outputs a bunch of stuff, including :file_path and
:absolute_file_path

Hope this helps.

Best Regards,
Mohit.
2021-6-21 | 8:07 pm.

Joao Miguel Ferreira

unread,
Jun 21, 2021, 12:00:18 PM6/21/21
to mo_...@onghu.com, rs...@googlegroups.com
Hello Mohit,

I did not find an answer specifically for the case I mentioned

But the approach you suggest seems to be ok for me. I will try that

thank you
Joao

Reply all
Reply to author
Forward
0 new messages