[rspec-users] before(:each) <- need some clarification

Srushti Ambekallu
2011-04-27T20:58:01Z

On 28/04/11 1:25 AM, Sergio Ruiz wrote:
> i am setting up a few objects that are interrelated for use in an rspec
> test..
>
> something like:
>
> describe Dimension do
>
> before(:each) do
>   text = "string here"
> end
>
> it "should puts string" do
>   puts text
> end
>
> end
>
> when i run this, i get an error: undefined local variable or method
> `text''
>
> am doing something wrong?
>
> thanks!
>

Sergio,

You''ll want to create text as an instance variable
(''@text'').

The other option is to use ''let'' as in:

    let (:text) { "string here" }

Either option will get you what you want.


Thanks,

Srushti

-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://rubyforge.org/pipermail/rspec-users/attachments/20110428/616a7a70/attachment.html>