Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Closed
dchelimsky opened this Issue · 13 comments

5 participants

@dchelimsky
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

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

@soulcutter
Collaborator

Good deal.

@dchelimsky dchelimsky closed this issue from a commit
@dchelimsky dchelimsky 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
@nicksieger

Next step would be to deprecate Example#subject :)

@dchelimsky
Owner

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

@avdi
@nicksieger

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

@dchelimsky
Owner

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

@dchelimsky
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 :)

@justinko

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
@dchelimsky
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
@dchelimsky
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.