Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

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
Closed

Comments

@slowjack2k
Copy link
Contributor

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?

@thibaudgg
Copy link
Member

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

@907th
Copy link
Contributor

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.

@thibaudgg
Copy link
Member

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

@907th
Copy link
Contributor

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?

@thibaudgg
Copy link
Member

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

@slowjack2k
Copy link
Contributor Author

I'll try to create a pull request.

@slowjack2k
Copy link
Contributor Author

I can create a pr if the changes are sufficient.

@slowjack2k
Copy link
Contributor Author

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.

@thibaudgg
Copy link
Member

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).

@slowjack2k
Copy link
Contributor Author

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?

@thibaudgg
Copy link
Member

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

@907th
Copy link
Contributor

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?

@slowjack2k
Copy link
Contributor Author

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 :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants