its with arguments #553

Closed
dnagir opened this Issue Jan 13, 2012 · 7 comments

Comments

Projects
None yet
4 participants
@dnagir

dnagir commented Jan 13, 2012

It is very common to write specs for testing on multiple arguments:

it "should be 1" do
  subject.check(1).should == 1
end

it "should be 22" do
  subject.check(2).should == 2
end

# etc

It would be way MUCH easier to write:

its(:check, 1) { should == 1 }
its(:check, 2) { should == 22 }

It makes it absolutely clear what's happening with 2 lines of code instead of 6.

@justinko

This comment has been minimized.

Show comment Hide comment
@justinko

justinko Jan 13, 2012

Contributor

its is going to be extracted into its (pardon the pun) own gem in RSpec 3. We feel it is not "core" to the framework. Once it is extracted, I'm sure this argument enhancement will be added.

However, nothing is stopping anyone from making an its gem right now and overriding the its in RSpec :)

Contributor

justinko commented Jan 13, 2012

its is going to be extracted into its (pardon the pun) own gem in RSpec 3. We feel it is not "core" to the framework. Once it is extracted, I'm sure this argument enhancement will be added.

However, nothing is stopping anyone from making an its gem right now and overriding the its in RSpec :)

@justinko justinko closed this Jan 13, 2012

@dnagir

This comment has been minimized.

Show comment Hide comment
@dnagir

dnagir Jan 13, 2012

Could be please give a pointer on how to override its? Money-patching or there's some API for that?
Should define_example_method be used for that?

dnagir commented Jan 13, 2012

Could be please give a pointer on how to override its? Money-patching or there's some API for that?
Should define_example_method be used for that?

@myronmarston

This comment has been minimized.

Show comment Hide comment
@myronmarston

myronmarston Jan 13, 2012

Member

Could be please give a pointer on how to override its?

module ItsOverride
  def its(*args)
    puts "I override its in rspec!"
  end

  RSpec.configure { |c| c.extend self }
end
Member

myronmarston commented Jan 13, 2012

Could be please give a pointer on how to override its?

module ItsOverride
  def its(*args)
    puts "I override its in rspec!"
  end

  RSpec.configure { |c| c.extend self }
end
@dnagir

This comment has been minimized.

Show comment Hide comment
@dnagir

dnagir Jan 13, 2012

Well, here's the `its' gem :)
I took the impl and spec from RSpec Core.

So it's pretty much self contained and doesn't really need its of the RSpec Core.

Feel free to get rid of it :)

dnagir commented Jan 13, 2012

Well, here's the `its' gem :)
I took the impl and spec from RSpec Core.

So it's pretty much self contained and doesn't really need its of the RSpec Core.

Feel free to get rid of it :)

@justinko

This comment has been minimized.

Show comment Hide comment
@justinko

justinko Jan 13, 2012

Contributor

That was fast! Thanks for giving RSpec "a way out" with the its method. Cheers!

Contributor

justinko commented Jan 13, 2012

That was fast! Thanks for giving RSpec "a way out" with the its method. Cheers!

@dnagir

This comment has been minimized.

Show comment Hide comment
@dnagir

dnagir Jan 13, 2012

I hope I won't end up as a single contributor to that little, useful thing :)

dnagir commented Jan 13, 2012

I hope I won't end up as a single contributor to that little, useful thing :)

@dchersey

This comment has been minimized.

Show comment Hide comment
@dchersey

dchersey Sep 14, 2012

Thanks much! Really loving the conciseness of its, now with args & much more useful. Glad it won't be going away when we upgrade.

Thanks much! Really loving the conciseness of its, now with args & much more useful. Glad it won't be going away when we upgrade.

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