Hi List,
Being pretty lazy here, but I figure you can help very quickly and
others
might benefit from the results. I write old crumbly rspec (see gist
old crumbly rspec · GitHub), and I would like to improve, can you
take my
crumbly spec and make it shiny?
Also if you can post any links to recent relevant blog articles that
would
be much appreciated
Best one I can find at the moment is:
http://eggsonbread.com/2010/03/28/my-rspec-best-practices-and-tips/
TIA
Andrew
Cursory look at that blog post seems like it’s covered most of what’s in
this talk, but worth mentioning anyway, it’s good:
http://pure-rspec-rubynation.heroku.com/
http://video2010.scottishrubyconference.com/show_video/3/1
What is the functional difference between “it” and “specify”
Thanks!
Tim
As David said, there is no difference between “it” and “specify”. One
of them is alias of other one. However semantically you can use them
differently.
The two examples given below are same. However second one reads
better. I like to use specify when I have explicitly created a
subject. Implicit subjects read better with it.
describe User do
context “create a user” do
subject { User.create(:email => ‘[email protected]’) }
it { subject.id.should_not be_nil}
end
end
describe User do
context “create a user” do
subject { User.create(:email => ‘[email protected]’) }
specify { subject.id.should_not be_nil}
end
end
On May 26, 2010, at 3:23 PM, Tim W. wrote:
What is the functional difference between “it” and “specify”
None.
On May 26, 2010, at 4:05 PM, Nadal wrote:
subject { User.create(:email => ‘[email protected]’) }
In this case you can also use “its”:
describe User do
context “create a user” do
subject { User.create(:email => ‘[email protected]’) }
its(:id) { should_not be_nil}
end
end
That doesn’t always work out well, depending on how deep you need to dig
into the subject, but it can work well in some cases.
Cheers,
David
I knew its existed but did not know any use case.
Thanks for an excellent example. As you said in some cases its might
make sentence more readable.
good stuff.