# Spec and calling other examples

**URL:** <https://www.ruby-forum.com/t/spec-and-calling-other-examples/171707>\
**Category:** IronRuby\
**Created:** [July 8, 2009, 12:00am UTC](https://www.ruby-forum.com/t/spec-and-calling-other-examples/171707 "2009-07-08T00:00:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![metanoize](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9fc29f/32.png) [@metanoize](https://www.ruby-forum.com/u/metanoize)\
**Post date:** [July 8, 2009, 12:00am UTC](https://www.ruby-forum.com/t/spec-and-calling-other-examples/171707/1 "2009-07-08T00:00:24Z")

</div>

Hi,

When performing BDD there are few occasions when a certain example (BDD  
test) depends on other context/example.

Here is one example:

describe Person do

before do

@person = Person.new  
@person.Age = 19

end

it “should be able to vote” do

@person.CanVote().should == true

end

describe “19 years old” do

it “should be able to vote” # does not work

end

end

The context of “19 years old” fails since it requires to put the  
“voting” context as a shared example which I don’t want to do. If we can  
just call other contexts within the parent context then it would be  
great. I think it would be great if the above example just works.

---

<div class="post-metadata">

**Author:** ![metanoize](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9fc29f/32.png) [@metanoize](https://www.ruby-forum.com/u/metanoize)\
**Post date:** [July 9, 2009, 3:56am UTC](https://www.ruby-forum.com/t/spec-and-calling-other-examples/171707/2 "2009-07-09T03:56:29Z")

</div>

Mohammad A. wrote:

> The context of “19 years old” fails since it requires to put the  
> “voting” context as a shared example which I don’t want to do. If we can  
> just call other contexts within the parent context then it would be  
> great. I think it would be great if the above example just works.

I’m not quite sure what you’re expecting in this case.  
I can understand if you are expecting the parent context to be passed  
down to the child, but the code:

it “should be able to vote” # does not work

Is only saying “here is a description about what I want to test… I’m  
getting ready to test something… and … nothing”

I’d imagine based on a conversation we had that you “might” be expecting  
the implicit method calling/subject setup mentioned in the post here:

[http://blog.davidchelimsky.net/2009/01/13/rspec-1-1-12-is-released/](http://blog.davidchelimsky.net/2009/01/13/rspec-1-1-12-is-released/)

However, for that, you’d actually need the following syntax (which is  
probably using some magic shortcuts behind the scenes):

it { should be\_able\_to\_vote }

You’d also need to add (perhaps monkey-patch if you’re dealing with an  
existing C# dll) the method that RSpec will be looking for (namely:  
able\_to\_vote? )

Since you already have CanVote, you could actually just alias it like  
this:

class Person  
alias\_method :able\_to\_vote?, :CanVote  
end

Let us/me know if this helps, and how far you get from here  
If you’d like to discuss further personally, please email or direct  
message me.  
Thanks
