Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Rerun failed spec with example groups in different files does not work. #243

Closed
slowjack2k opened this Issue Jan 8, 2014 · 13 comments

Comments

Projects
None yet
3 participants
Contributor

slowjack2k commented Jan 8, 2014

The core issue is a rspec issue listed here rspec/rspec-core#793.

For example:

I have a shared_examples in lib/my_shared_example.rb.
I use this shared example in spec/lib/my_other_spec.rb.
And an expectation of this shared example groups fails,
then guard-rspec tries to execute the file lib/my_shared_example.rb
insteed of spec/lib/my_other_spec.rb.

I found 2 workarounds for this:

1st workaround:

Guardfile

 guard :rspec, failed_mode: :none do

2nd workaround:

spec_helper.rb

require 'guard/rspec'

# issue https://github.com/rspec/rspec-core/issues/793

module Guard
  class RSpec
    class Formatter
      def self.extract_spec_location(metadata)

        while !(metadata[:location] =~ /_spec.rb:\d+$/) do

          metadata = metadata[:example_group]
          raise 'No spec file could be found in meta data!' unless metadata

        end

        metadata[:location]
      end

      def _failed_paths
        failed = examples.select { |e| e.execution_result[:status] == 'failed' }
        failed.map { |e| extract_spec_location(e.metadata[:location]) }
      end
    end
  end
end

Is there a better way to fix this issue?

Owner

thibaudgg commented Jan 8, 2014

Looking to the metadata location could be a nice way of fixing that, @907th what are you thinking?

Member

907th commented Jan 8, 2014

Don't know really. Workaround seems good to me.

@slowjack2k:
Should the extract_spec_location(e.metadata[:location]) line be extract_spec_location(e.metadata)?
And I think it's better to define private _extract_spec_location helper.

Owner

thibaudgg commented Jan 8, 2014

Yep right, @slowjack2k could you submit a PR please?

Member

907th commented Jan 8, 2014

I'm not sure that it's good idea to raise in case of no *_spec file. May be just skip?

Owner

thibaudgg commented Jan 8, 2014

Yeah I wouldn't raise 'No spec file could be found in meta data!' unless metadata as well, just skipping it is good enough.

Contributor

slowjack2k commented Jan 8, 2014

I'll try to create a pull request.

Contributor

slowjack2k commented Jan 8, 2014

I can create a pr if the changes are sufficient.

Contributor

slowjack2k commented Jan 8, 2014

Is it possible to use rspec -l 4 switch insteed of _spec.rb:4? With shared examples I have an strange rspec behavior that the shared examples are not executed when I use _spec.rb:4, but when I use -I 4 _spec.rb it is executed.

Owner

thibaudgg commented Jan 8, 2014

Which rspec version are you using, with 2.14.7 I got:

-l, --line-number LINE           Specify line number of an example or group (may be
                                       used more than once).
Contributor

slowjack2k commented Jan 8, 2014

I have also 2.14.7 . The -l switch works fine but spec_filename:line_number does not play well with shared example groups. guard-rspec uses

rspec spec_filename:line_number 

insteed of

rspec -l line_number spec_filename

, right?

Owner

thibaudgg commented Jan 8, 2014

Yep, if changing to the later fix it and works everywhere no problem for me.

Member

907th commented Jan 8, 2014

guard-rspec may come running several specs at the same time... so using -l switch may break things. Am I right?

Contributor

slowjack2k commented Jan 8, 2014

An example what not works https://gist.github.com/slowjack2k/8319290 (rspec issue). It's special when you use a shared example in a shared example. @907th yeah, I think your right, the switch would break things :(

@thibaudgg thibaudgg closed this in 250a568 Jan 9, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment