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

There should be a way to run single specs in a shared group in isolation #82

Closed
carllerche opened this issue Jul 20, 2010 · 10 comments
Closed

Comments

@carllerche
Copy link

Here is an example backtrace gotten from running an entire spec suite that uses shared spec groups

8)
RuntimeError in 'Arel Join#each iterates over the rows in any order'

/Users/apatterson/git/arel/spec/../lib/arel/algebra/relations/operations/join.rb:14:in `hash'
/Users/apatterson/git/arel/spec/../lib/arel/session.rb:38:in `[]'
/Users/apatterson/git/arel/spec/../lib/arel/session.rb:38:in `read'
/Users/apatterson/git/arel/spec/../lib/arel/algebra/relations/relation.rb:21:in `each'
/Users/apatterson/git/arel/spec/support/matchers/have_rows.rb:5:in `have_rows'
/Library/Ruby/Gems/1.8/gems/rspec-1.3.0/lib/spec/matchers/simple_matcher.rb:16:in `call'
/Library/Ruby/Gems/1.8/gems/rspec-1.3.0/lib/spec/matchers/simple_matcher.rb:16:in `matches?'
/Library/Ruby/Gems/1.8/gems/rspec-1.3.0/lib/spec/expectations/handler.rb:11:in `handle_matcher'
/Library/Ruby/Gems/1.8/gems/rspec-1.3.0/lib/spec/expectations/extensions/kernel.rb:27:in `should'
/Users/apatterson/git/arel/spec/shared/relation_spec.rb:23:
/Library/Ruby/Gems/1.8/gems/rspec-1.3.0/lib/spec/example/example_methods.rb:40:in `instance_eval'
/Library/Ruby/Gems/1.8/gems/rspec-1.3.0/lib/spec/example/example_methods.rb:40:in `execute'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/timeout.rb:53:in `timeout'
/Library/Ruby/Gems/1.8/gems/rspec-1.3.0/lib/spec/example/example_methods.rb:37:in `execute'
/Library/Ruby/Gems/1.8/gems/rspec-1.3.0/lib/spec/example/example_group_methods.rb:214:in `run_examples'
/Library/Ruby/Gems/1.8/gems/rspec-1.3.0/lib/spec/example/example_group_methods.rb:212:in `each'
/Library/Ruby/Gems/1.8/gems/rspec-1.3.0/lib/spec/example/example_group_methods.rb:212:in `run_examples'
/Library/Ruby/Gems/1.8/gems/rspec-1.3.0/lib/spec/example/example_group_methods.rb:103:in `run'
/Library/Ruby/Gems/1.8/gems/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:23:in `run'
/Library/Ruby/Gems/1.8/gems/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:22:in `each'
/Library/Ruby/Gems/1.8/gems/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:22:in `run'
/Library/Ruby/Gems/1.8/gems/rspec-1.3.0/lib/spec/runner/options.rb:152:in `run_examples'
/Library/Ruby/Gems/1.8/gems/rspec-1.3.0/lib/spec/runner/command_line.rb:9:in `run'
/Library/Ruby/Gems/1.8/gems/rspec-1.3.0/bin/spec:5

There are a few problems here.

  1. given the backtrace, I have no idea what the context of the shared spec is. Aka, where was it included, what file was it included in, etc... There is the description 'Arel Join#each iterates over the rows in any order', but in a project with a lot of specs, that's basically useless to me.

  2. I would like a way to run that single spec in isolation in the context that caused it to fail. I'm not sure of how to do that right now.

@justinko
Copy link
Contributor

David, I think I might have a solution for this:

When "it_should_behave_like" (or the alias) is called, it sets the following metadata on the ExampleGroup:

Name of the shared example group.
File path and line number of "it_should_behave_like" method call.

When an example fails, RSpec will check to see if that example exists in the shared example group. If it does, it will append to the output the file path and line number (stored in the ExampleGroup metadata).

What do you think?

@justinko
Copy link
Contributor

Oh nice I see that metadata is already there :-)

@justinko
Copy link
Contributor

justinko commented Aug 2, 2010

@dchelimsky
Copy link
Contributor

I merged @justinko's patch (3906559), which displays the line that calls the shared group, so we now know the context in which it was run. That still leaves open the issue of running a single shared example - but this should help at least to understand when a shared example fails.

@justinko
Copy link
Contributor

You can run a single example in a shared group via rspec spec/my_spec_that_contains_the_shared_group.rb --example "hello world"

@dchelimsky
Copy link
Contributor

Yep - that's true. That's good enough for me. I'm going to close this. @carllerche if you think this is not sufficient, comment here and I'll reopen this.

@justinko
Copy link
Contributor

Crap, found a bug with this:

share_as :MySpecs do
  let(:foo) { described_class # returns nil }

Investigating.

@dchelimsky
Copy link
Contributor

I want to deprecate share_as. It generates a module, which you then use include to include, which has very different implications from creating a nested group, as we do now with shared_examples_for. WDYT?

@justinko
Copy link
Contributor

I completely agree with deprecating it. When I first started learning RSpec, I was confused why there was shared_examples_for and share_as.

I tend to use share_as for the top level group:

describe Model do
  include MySharedSpecs

  context 'it works' do
    it_should_behave_like 'a working model'

I switched to shared_examples_for and all is well. Thanks.

timcharper pushed a commit to timcharper/rspec-core that referenced this issue Aug 19, 2011
@axelson
Copy link

axelson commented Mar 30, 2017

For anyone skipping to the bottom I want to point out that justinko provided a completely satisfactory answer to this above.

You can run a single example in a shared group via rspec spec/my_spec_that_contains_the_shared_group.rb --example "hello world"

This issue was closed.
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

4 participants