Skip to content
This repository

Add support for subject(:name) { ... } #619

Closed
dchelimsky opened this Issue May 15, 2012 · 13 comments

5 participants

David Chelimsky Avdi Grimm Bradley Schaefer Nick Sieger Justin Ko
David Chelimsky
Owner
describe Article do
  subject(:article) { Article.new }
  it { should support_one_liners }
  it "should be exposed with the name :article" do
    article.should support_intention_revealing_name
  end
end

See the following for background:

http://blog.davidchelimsky.net/2012/05/13/spec-smell-explicit-use-of-subject/
https://gist.github.com/2705101
https://gist.github.com/2705200

Avdi Grimm
avdi commented May 15, 2012

Heh, I was just about to suggest exactly that :-)

Bradley Schaefer
Collaborator

Good deal.

David Chelimsky dchelimsky closed this issue from a commit May 15, 2012
David Chelimsky Support a 'name' arg to subject declaration
Closes #619.

Example:

    describe Article do
      subject(:article) { Article.new }
      it { supports_one_liners }
      it "supports intention revealing name" do
        article.should do_something
      end
    end
2e20683
David Chelimsky dchelimsky closed this in 2e20683 May 15, 2012
Nick Sieger

Next step would be to deprecate Example#subject :)

David Chelimsky
Owner

@nicksieger I could deprecate it in the docs, but not programatically, because it's needed for one-liners.

Avdi Grimm
avdi commented May 15, 2012
Nick Sieger

Oh, of course. #subject is used internally in the framework.

David Chelimsky
Owner

@avdi I'd argue that in most cases you can do better than "subject", even in shared specs.

David Chelimsky
Owner

@avdi ... unless you're using the implicit subject built from the described_class, but then you could just reference described_class, which I think is a more descriptive name than subject. YMMV :)

Justin Ko

I'd argue that in most cases you can do better than "subject", even in shared specs.

All methods of sharing accept arguments (and soon to be blocks). :metal:

Avdi Grimm
avdi commented May 15, 2012
David Chelimsky
Owner

@avdi - but that protocol has a name. If the specs are for things that implement that protocol, then you can use that name or something similar. If you're spec'ing a consumer of the protocol, then "consumer" might be a good name. "subject" doesn't tell you anything about either, unless it's one of the subjects who bow to you in your kingdom.

Avdi Grimm
avdi commented May 15, 2012
David Chelimsky
Owner

@avdi if you were going to add shared specs from my fribble-protocol lib, you'd probably start with docs because you'd need to know the name to pass to it_behaves_like, and those same docs would tell you what to put in the block. But even if you failed to read that part, you'd get a NameError when the shared spec references fribble_drinker, or the shared spec could detect the presence of the method first and then, with a friendly tone, guide you to "awful awful" happiness.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.