# I don't get rspec

**URL:** <https://www.ruby-forum.com/t/i-dont-get-rspec/82714>\
**Category:** Ruby\
**Created:** [January 19, 2007, 10:41pm UTC](https://www.ruby-forum.com/t/i-dont-get-rspec/82714 "2007-01-19T22:41:11Z")\
**Posts on this page:** 10\
**Page:** 3

<div class="post-metadata">

**Author:** ![nicknameoptional](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/48db29/32.png) [@nicknameoptional](https://www.ruby-forum.com/u/nicknameoptional)\
**Post date:** [January 24, 2007, 4:26pm UTC](https://www.ruby-forum.com/t/i-dont-get-rspec/82714/41 "2007-01-24T16:26:20Z")

</div>

On 1/24/07, Luke I. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > >
> 
> I know I’m not the person that this was targeted at, but I would absolutely  
> love to see nested contexts included in rspec… I was just wishing I could  
> do that yesterday.

Google this:

pipermail rspec nested contexts

and you’ll see what’s been said about it before. Feel free to  
resurrect the discussion on the rspec-devel or rspec-users list if you  
have some new insights to add to the discussion.

Cheers,  
David

---

<div class="post-metadata">

**Author:** ![nicknameoptional](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/48db29/32.png) [@nicknameoptional](https://www.ruby-forum.com/u/nicknameoptional)\
**Post date:** [January 24, 2007, 8:34pm UTC](https://www.ruby-forum.com/t/i-dont-get-rspec/82714/42 "2007-01-24T20:34:27Z")

</div>

“David C.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> user = User.new  
> setup do  
> kind of interesting.  
> I’m not sure how I could implement that (and I wont ;-)). But maybe  
> includable setups would be useful.

module UserSetup  
setup do # ???  
@user = User.new  
end  
end

context “Users” do  
context “with a valid email address” do  
include UserSetup  
setup { @user.email … }  
end  
context “with a valid email address” do  
include UserSetup  
setup { @user.email … }  
end  
end

That shouldn’t be too hard to do…

---

<div class="post-metadata">

**Author:** ![nicknameoptional](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/48db29/32.png) [@nicknameoptional](https://www.ruby-forum.com/u/nicknameoptional)\
**Post date:** [January 24, 2007, 10:10pm UTC](https://www.ruby-forum.com/t/i-dont-get-rspec/82714/43 "2007-01-24T22:10:45Z")

</div>

On 1/24/07, Christian N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> @user = User.new
> 
> ```
> 
> end  
> end

It’s actually pretty easy if you don’t mind using the Module#included  
hook.

module UserSetup  
def self.included(context)  
context.setup do  
@user = User.new  
end  
end  
end

But I’m sure you would have figured that out eventually… 🙂

context “Users” do

> context “with a valid email address” do  
> include UserSetup  
> setup { @user.email … }  
> end  
> context “with a valid email address” do  
> include UserSetup  
> setup { @user.email … }  
> end  
> end

Cheers,  
/Nick

---

<div class="post-metadata">

**Author:** ![nicknameoptional](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/48db29/32.png) [@nicknameoptional](https://www.ruby-forum.com/u/nicknameoptional)\
**Post date:** [June 25, 2007, 4:14pm UTC](https://www.ruby-forum.com/t/i-dont-get-rspec/82714/44 "2007-06-25T16:14:17Z")

</div>

M. Edward (Ed) Borasky wrote:

> I do have a bone to pick with the tutorial (or maybe I don’t understand  
> TDD/BDD yet). In the stack example, I cringe with horror when I see them  
> setting a method that just returns “true” simply to get a test to pass.  
> That grates on me, because I _know_ I’m actually going to have to write  
> the real code eventually. It seems like a waste of time to do the  
> nitty-gritty “add a test to the spec/add a trivial fix to the code” cycle.

The idea behind doing small steps is that you know exactly what went  
wrong  
when you run the tests. If you roll several steps into one  
test/development  
cycle then you have many possibilities to investigate what went wrong if  
they fail.

Sometimes, it is easier to skip the most trivial steps though!

---

<div class="post-metadata">

**Author:** ![nicknameoptional](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/48db29/32.png) [@nicknameoptional](https://www.ruby-forum.com/u/nicknameoptional)\
**Post date:** [June 25, 2007, 10:30pm UTC](https://www.ruby-forum.com/t/i-dont-get-rspec/82714/45 "2007-06-25T22:30:43Z")

</div>

> they fail.
> 
> Sometimes, it is easier to skip the most trivial steps though!

Also keep in mind that is just a tutorial example. The goal is just to  
communicate the process - spec first, make the spec pass, next step.  
It’s all about a single point of failure, and a clear mapping between  
specs and functionality.

–  
Giles B.

Blog: [http://gilesbowkett.blogspot.com](http://gilesbowkett.blogspot.com)  
Portfolio: [http://www.gilesgoatboy.org](http://www.gilesgoatboy.org)

---

<div class="post-metadata">

**Author:** ![nicknameoptional](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/48db29/32.png) [@nicknameoptional](https://www.ruby-forum.com/u/nicknameoptional)\
**Post date:** [January 25, 2007, 5:27pm UTC](https://www.ruby-forum.com/t/i-dont-get-rspec/82714/46 "2007-01-25T17:27:54Z")

</div>

“Nick S.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> > setup do # ???  
> > @user = User.new  
> > end  
> > end  
> > end
> 
> But I’m sure you would have figured that out eventually… 🙂

Nifty, thanks!

---

<div class="post-metadata">

**Author:** ![nicknameoptional](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/48db29/32.png) [@nicknameoptional](https://www.ruby-forum.com/u/nicknameoptional)\
**Post date:** [June 27, 2007, 8:28pm UTC](https://www.ruby-forum.com/t/i-dont-get-rspec/82714/47 "2007-06-27T20:28:40Z")

</div>

On 6/25/07, Giles B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Also keep in mind that is just a tutorial example. The goal is just to  
> communicate the process - spec first, make the spec pass, next step.  
> It’s all about a single point of failure, and a clear mapping between  
> specs and functionality.

Actually I believe that the pure process of  
test-driven/behavior-driven development is:

1. Write the test/spec
2. Ensure that it FAILS
3. Write the code to make it pass
4. Goto step 1

Step 2 is to debug the spec.

–  
Rick DeNatale

My blog on Ruby  
[http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)

---

<div class="post-metadata">

**Author:** ![nicknameoptional](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/48db29/32.png) [@nicknameoptional](https://www.ruby-forum.com/u/nicknameoptional)\
**Post date:** [June 27, 2007, 8:44pm UTC](https://www.ruby-forum.com/t/i-dont-get-rspec/82714/48 "2007-06-27T20:44:43Z")

</div>

On 6/27/07, Rick DeNatale [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 1. Write the test/spec
> 2. Ensure that it FAILS
> 3. Write the code to make it pass
> 4. Goto step 1
> 
> Step 2 is to debug the spec.

The reason that we want to see the test fail is so that we can  
confident that when it passes that it’s passing because of the code we  
wrote in step 3. Otherwise, we could write code that the test doesn’t  
interact with in any way resulting in a useless test and dead code.

Is that what you mean by “debug the spec?” If not, can you please  
explain?

Thx,  
David

---

<div class="post-metadata">

**Author:** ![nicknameoptional](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/48db29/32.png) [@nicknameoptional](https://www.ruby-forum.com/u/nicknameoptional)\
**Post date:** [July 19, 2007, 5:31am UTC](https://www.ruby-forum.com/t/i-dont-get-rspec/82714/49 "2007-07-19T05:31:22Z")

</div>

On 6/27/07, David C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > 
> 
> interact with in any way resulting in a useless test and dead code.
> 
> Is that what you mean by “debug the spec?” If not, can you please explain?

Better late than never. Yes

–  
Rick DeNatale

My blog on Ruby  
[http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)

---

<div class="post-metadata">

**Author:** ![nicknameoptional](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/48db29/32.png) [@nicknameoptional](https://www.ruby-forum.com/u/nicknameoptional)\
**Post date:** [July 19, 2007, 5:37am UTC](https://www.ruby-forum.com/t/i-dont-get-rspec/82714/50 "2007-07-19T05:37:24Z")

</div>

On 7/18/07, Rick DeNatale [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > test-driven/behavior-driven development is:  
> > > wrote in step 3. Otherwise, we could write code that the test doesn’t  
> > > interact with in any way resulting in a useless test and dead code.
> > 
> > Is that what you mean by “debug the spec?” If not, can you please explain?
> 
> Better late than never. Yes

🙂

Thanks

[Previous page](https://www.ruby-forum.com/t/i-dont-get-rspec/82714.md?page=2)
