# Learning TDD Rspec

**URL:** <https://rubytalk.org/t/learning-tdd-rspec/73207>\
**Category:** ruby-talk\
**Created:** [2 September 2015 00:37 UTC](https://rubytalk.org/t/learning-tdd-rspec/73207 "2015-09-02T00:37:51Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robert\_Freiberger](https://avatars.discourse-cdn.com/v4/letter/r/b4bc9f/32.png) [@Robert\_Freiberger](https://rubytalk.org/u/Robert_Freiberger)\
**Post date:** [2 September 2015 00:37 UTC](https://rubytalk.org/t/learning-tdd-rspec/73207/1 "2015-09-02T00:37:51Z")

</div>

Hello Ruby-lang,

I'm learning Rspec and Ruby which I heard is a good step since it's  
developing TDD practice for real world use. While I understand the high  
level point of view about using TDD with Rspec, I'm struggling to know how  
to test certain conditions.

Below is my repo which I wrote a test for the first function but don't  
believe this is covering the changes.

[https://github.com/rfreiberger/Ruby-Rspec-Example](https://github.com/rfreiberger/Ruby-Rspec-Example)

Is there suggestions on getting a proper start with Rspec or should I just  
focus on Ruby before I learn unit testing?

Thanks,  
Robert

---

<div class="post-metadata">

**Author:** ![Raj\_Sahae](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/raj_sahae/32/1840_2.png) [@Raj\_Sahae](https://rubytalk.org/u/Raj_Sahae)\
**Post date:** [2 September 2015 01:09 UTC](https://rubytalk.org/t/learning-tdd-rspec/73207/2 "2015-09-02T01:09:04Z")

</div>

Hi Robert,  
There are different perspectives on your second question and I wouldn't presume to have all the answers there. In my opinion, knowing how to write some basic tests is good because you give yourself the ability to make changes in your code and check for regressions easily. Writing in-depth tests is a different sort of problem and you should feel free to research that area.

For your code specifically, I have the following comments:  
&nbsp;&nbsp;1) You instantiate your Report object in your library file. This is generally bad practice. Your library should simply declare/define the object and you should allow the user that requires your library to instantiate the object on their own, when they want to.  
&nbsp;&nbsp;&nbsp;&nbsp;2) The same concept goes for your validation. You call your validation method in the object initializer but you should simply initialize your state variables and then allow the user to instantiate the object on their own and then call validation when they are ready.

&nbsp;&nbsp;3) Once you fix the above points, you can then instantiate a single object in your spec test and test the 3 methods (check/restart/validate) separately, which is the main strength of unit tests (think divide and conquer).

&nbsp;&nbsp;4) Additionally, you are testing something that uses system calls to achieve results and this can be tricky for a beginner to test (but it is possible). You are trying to inject an initial condition to cause failure, but you are not taking the scoping of the object into account so therefore you don't get the desired result. You might want to consider abstracting out the system interaction so you can test the  
&nbsp;&nbsp;method logic separately.

> **···**
>
> On 09/02/2015 00:37:51, Robert Freiberger wrote:
> 
> > Hello Ruby-lang,
> > 
> > I'm learning Rspec and Ruby which I heard is a good step since it's  
> > developing TDD practice for real world use. While I understand the high  
> > level point of view about using TDD with Rspec, I'm struggling to know how  
> > to test certain conditions.
> > 
> > Below is my repo which I wrote a test for the first function but don't  
> > believe this is covering the changes.
> > 
> > [https://github.com/rfreiberger/Ruby-Rspec-Example](https://github.com/rfreiberger/Ruby-Rspec-Example)
> > 
> > Is there suggestions on getting a proper start with Rspec or should I just  
> > focus on Ruby before I learn unit testing?
> > 
> > Thanks,  
> > Robert
> 
> --  
> Raj Sahae  
> 408.230.8531

---

<div class="post-metadata">

**Author:** ![Phuong\_Phan](https://avatars.discourse-cdn.com/v4/letter/p/f6c823/32.png) [@Phuong\_Phan](https://rubytalk.org/u/Phuong_Phan)\
**Post date:** [2 September 2015 04:48 UTC](https://rubytalk.org/t/learning-tdd-rspec/73207/3 "2015-09-02T04:48:02Z")

</div>

Hi Rubyists,

I am new to Ruby. Appreciate very much if you could introduce to me a good  
textbook for beginner.  
Thanks,  
Phuong

> **···**
>
> On Wed, Sep 2, 2015 at 10:09 AM Raj Sahae \<rajsahae@gmail.com\> wrote:
> 
> > Hi Robert,  
> > There are different perspectives on your second question and I wouldn't  
> > presume to have all the answers there. In my opinion, knowing how to  
> > write some basic tests is good because you give yourself the ability to  
> > make changes in your code and check for regressions easily. Writing  
> > in-depth tests is a different sort of problem and you should feel free  
> > to research that area.
> > 
> > For your code specifically, I have the following comments:  
> > &nbsp;&nbsp;1) You instantiate your Report object in your library file. This is  
> > &nbsp;&nbsp;generally bad practice. Your library should simply declare/define the  
> > &nbsp;&nbsp;object and you should allow the user that requires your library to  
> > &nbsp;&nbsp;instantiate the object on their own, when they want to.
> > 
> > &nbsp;&nbsp;2) The same concept goes for your validation. You call your validation  
> > &nbsp;&nbsp;method in the object initializer but you should simply initialize your  
> > &nbsp;&nbsp;state variables and then allow the user to instantiate the object on  
> > &nbsp;&nbsp;their own and then call validation when they are ready.
> > 
> > &nbsp;&nbsp;3) Once you fix the above points, you can then instantiate a single  
> > &nbsp;&nbsp;object in your spec test and test the 3 methods  
> > &nbsp;&nbsp;(check/restart/validate) separately, which is the main strength of  
> > &nbsp;&nbsp;unit tests (think divide and conquer).
> > 
> > &nbsp;&nbsp;4) Additionally, you are testing something that uses system calls to  
> > &nbsp;&nbsp;achieve results and this can be tricky for a beginner to test (but it  
> > &nbsp;&nbsp;is possible). You are trying to inject an initial condition to cause  
> > &nbsp;&nbsp;failure, but you are not taking the scoping of the object into account  
> > &nbsp;&nbsp;so therefore you don't get the desired result. You might want to  
> > &nbsp;&nbsp;consider abstracting out the system interaction so you can test the  
> > &nbsp;&nbsp;method logic separately.
> > 
> > On 09/02/2015 00:37:51, Robert Freiberger wrote:  
> > \>Hello Ruby-lang,  
> > \>  
> > \>I'm learning Rspec and Ruby which I heard is a good step since it's  
> > \>developing TDD practice for real world use. While I understand the high  
> > \>level point of view about using TDD with Rspec, I'm struggling to know how  
> > \>to test certain conditions.  
> > \>  
> > \>Below is my repo which I wrote a test for the first function but don't  
> > \>believe this is covering the changes.  
> > \>  
> > \>[https://github.com/rfreiberger/Ruby-Rspec-Example](https://github.com/rfreiberger/Ruby-Rspec-Example)  
> > \>  
> > \>Is there suggestions on getting a proper start with Rspec or should I just  
> > \>focus on Ruby before I learn unit testing?  
> > \>  
> > \>Thanks,  
> > \>Robert
> > 
> > --  
> > Raj Sahae  
> > 408.230.8531

---

<div class="post-metadata">

**Author:** ![Joe\_Gain](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/joe_gain/32/1847_2.png) [@Joe\_Gain](https://rubytalk.org/u/Joe_Gain)\
**Post date:** [2 September 2015 07:54 UTC](https://rubytalk.org/t/learning-tdd-rspec/73207/4 "2015-09-02T07:54:23Z")

</div>

Hello,

Just to add to Raj's excellent advice, I feel a bit ambivalent about a lot  
of the things written about so called agile development but with Ruby and  
RSpec refactoring your way to a design is really possible. Be prepared to  
massage your code to a good api-- that's why it's good to use git as you go.

Here are a couple of interesting links which helped me get started:

> **[Design Is Refactoring](https://www.designisrefactoring.com/)**
>
> Writing is Rewriting, Desiging is Refactoring

Jim Weirich - Roman Numerals Kata

[![]( " - YouTube") ](https://www.youtube.com/watch?v=983zk0eqYLY)

There are two important things:  
1. Write the test first ! (And get it to pass, refactor etc.)  
2. Try and write at the method level -- pragmatic advice if you get stuck.  
I find it useful to start with a constructor like:

RSpec.describe SomeModule::AClass do  
&nbsp;&nbsp;describe '#initialize' do  
&nbsp;&nbsp;&nbsp;&nbsp;it 'constructs a class' do  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SomeModule::AClass.new(some, params)  
&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;end  
end

And then you've already got some state, which you can think about. This is  
cheating a bit because you can be wrong about the attributes a class needs,  
but you have to be prepared to rewrite and change your code a lot and for  
me this often works because I have some idea about what I want the class to  
do (ie. not strictly test driven.)

In your program you might want to think about using exceptions and also  
logging (ie. add a logger and error classes) to remove some of those error  
messages from methods which are really doing other things, like checking  
for the existence of a file.

Sometimes you don't need a class either. I'm not sure what you've got  
planned here, but a module method might do for a configuration task?  
Classes usually are nouns like WebServerManager, or something. This isn't  
just convention it's a way to help think about object design. So, you might  
have:

module ApacheServer  
&nbsp;&nbsp;def self.daemon\_exist?  
&nbsp;&nbsp;&nbsp;&nbsp;File.exist? '/etc/init.d/httpd'  
&nbsp;&nbsp;end  
end

And then you might end up using this in the constructor?

module ApacheServer  
&nbsp;&nbsp;class Manager  
&nbsp;&nbsp;&nbsp;&nbsp;def initialize  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# start\_logging  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;raise DaemonNotFound.new("some important info") unless daemon.exist?  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# init manager state? uptime, load\_statiscs, etc..  
&nbsp;&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;&nbsp;. . .

&nbsp;&nbsp;end  
end

There are some good bash scripts which do the task(s) you are programming.  
It might be a good exercise to see how they work and see how you can do  
that in ruby?

> **···**
>
> On Wed, Sep 2, 2015 at 2:37 AM, Robert Freiberger \<rfreiberger@gmail.com\> wrote:
> 
> > Hello Ruby-lang,
> > 
> > I'm learning Rspec and Ruby which I heard is a good step since it's  
> > developing TDD practice for real world use. While I understand the high  
> > level point of view about using TDD with Rspec, I'm struggling to know how  
> > to test certain conditions.
> > 
> > Below is my repo which I wrote a test for the first function but don't  
> > believe this is covering the changes.
> > 
> > [https://github.com/rfreiberger/Ruby-Rspec-Example](https://github.com/rfreiberger/Ruby-Rspec-Example)
> > 
> > Is there suggestions on getting a proper start with Rspec or should I just  
> > focus on Ruby before I learn unit testing?
> > 
> > Thanks,  
> > Robert
> 
> --  
> joe gain
> 
> jacob-burckhardt-str. 16  
> 78464 konstanz  
> germany
> 
> +49 (0)7531 60389
> 
> (...otherwise in ???)

---

<div class="post-metadata">

**Author:** ![Leonardo](https://avatars.discourse-cdn.com/v4/letter/l/e56c9b/32.png) [@Leonardo](https://rubytalk.org/u/Leonardo)\
**Post date:** [2 September 2015 11:38 UTC](https://rubytalk.org/t/learning-tdd-rspec/73207/5 "2015-09-02T11:38:24Z")

</div>

Hi, I'm learning rspec with rails and found this book... I think it  
could be useful [https://leanpub.com/everydayrailsrspec](https://leanpub.com/everydayrailsrspec)

hava a nice day 🙂

> **···**
>
> On 02/09/15 02:54, Joe Gain wrote:
> 
> > On Wed, Sep 2, 2015 at 2:37 AM, Robert Freiberger \> \<rfreiberger@gmail.com \<mailto:rfreiberger@gmail.com\>\> wrote:
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;Hello Ruby-lang,
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;I'm learning Rspec and Ruby which I heard is a good step since  
> > &nbsp;&nbsp;&nbsp;&nbsp;it's developing TDD practice for real world use. While I  
> > &nbsp;&nbsp;&nbsp;&nbsp;understand the high level point of view about using TDD with  
> > &nbsp;&nbsp;&nbsp;&nbsp;Rspec, I'm struggling to know how to test certain conditions.
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;Below is my repo which I wrote a test for the first function but  
> > &nbsp;&nbsp;&nbsp;&nbsp;don't believe this is covering the changes.
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;[https://github.com/rfreiberger/Ruby-Rspec-Example](https://github.com/rfreiberger/Ruby-Rspec-Example)
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;Is there suggestions on getting a proper start with Rspec or  
> > &nbsp;&nbsp;&nbsp;&nbsp;should I just focus on Ruby before I learn unit testing?
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;Thanks,  
> > &nbsp;&nbsp;&nbsp;&nbsp;Robert
> > 
> > Hello,
> > 
> > Just to add to Raj's excellent advice, I feel a bit ambivalent about a  
> > lot of the things written about so called agile development but with  
> > Ruby and RSpec refactoring your way to a design is really possible. Be  
> > prepared to massage your code to a good api-- that's why it's good to  
> > use git as you go.
> > 
> > Here are a couple of interesting links which helped me get started:  
> > [http://designisrefactoring.com/](http://designisrefactoring.com/)
> > 
> > Jim Weirich - Roman Numerals Kata  
> > [https://www.youtube.com/watch?v=983zk0eqYLY](https://www.youtube.com/watch?v=983zk0eqYLY)
> > 
> > There are two important things:  
> > 1. Write the test first ! (And get it to pass, refactor etc.)  
> > 2. Try and write at the method level -- pragmatic advice if you get  
> > stuck. I find it useful to start with a constructor like:
> > 
> > RSpec.describe SomeModule::AClass do  
> > &nbsp;&nbsp;describe '#initialize' do  
> > &nbsp;&nbsp;&nbsp;&nbsp;it 'constructs a class' do  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SomeModule::AClass.new(some, params)  
> > &nbsp;&nbsp;&nbsp;&nbsp;end  
> > &nbsp;&nbsp;&nbsp;end  
> > end
> > 
> > And then you've already got some state, which you can think about.  
> > This is cheating a bit because you can be wrong about the attributes a  
> > class needs, but you have to be prepared to rewrite and change your  
> > code a lot and for me this often works because I have some idea about  
> > what I want the class to do (ie. not strictly test driven.)
> > 
> > In your program you might want to think about using exceptions and  
> > also logging (ie. add a logger and error classes) to remove some of  
> > those error messages from methods which are really doing other things,  
> > like checking for the existence of a file.
> > 
> > Sometimes you don't need a class either. I'm not sure what you've got  
> > planned here, but a module method might do for a configuration task?  
> > Classes usually are nouns like WebServerManager, or something. This  
> > isn't just convention it's a way to help think about object design.  
> > So, you might have:
> > 
> > module ApacheServer  
> > &nbsp;&nbsp;def self.daemon\_exist?  
> > &nbsp;&nbsp;&nbsp;&nbsp;File.exist? '/etc/init.d/httpd'  
> > &nbsp;&nbsp;end  
> > end
> > 
> > And then you might end up using this in the constructor?
> > 
> > module ApacheServer  
> > &nbsp;&nbsp;class Manager  
> > &nbsp;&nbsp;&nbsp;&nbsp;def initialize  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# start\_logging  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;raise DaemonNotFound.new("some important info") unless daemon.exist?  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# init manager state? uptime, load\_statiscs, etc..  
> > &nbsp;&nbsp;&nbsp;&nbsp;end
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;. . .
> > 
> > &nbsp;&nbsp;end  
> > end
> > 
> > There are some good bash scripts which do the task(s) you are  
> > programming. It might be a good exercise to see how they work and see  
> > how you can do that in ruby?  
> > --  
> > joe gain
> > 
> > jacob-burckhardt-str. 16  
> > 78464 konstanz  
> > germany
> > 
> > +49 (0)7531 60389
> > 
> > (...otherwise in ???)

---

<div class="post-metadata">

**Author:** ![Daniel\_Llinas](https://avatars.discourse-cdn.com/v4/letter/d/3e96dc/32.png) [@Daniel\_Llinas](https://rubytalk.org/u/Daniel_Llinas)\
**Post date:** [2 September 2015 12:24 UTC](https://rubytalk.org/t/learning-tdd-rspec/73207/6 "2015-09-02T12:24:52Z")

</div>

I'd suggest a few free online resources first. Learn Ruby The Hard way is good. Ruby Monk as well.

As for an actual book, the Well Grounded Rubyist has been pretty good. I'm Still working through it, but it's highly regarded, and one of the few that covers Ruby 2.0.

Best,

Danny

> **[Facebook's New Spam-Killer Hints at the Future of Coding](https://www.wired.com/2015/09/facebooks-new-anti-spam-system-hints-future-coding/)**
>
> Haskell is a 25-year-old programming language that isn't all that popular. But Facebook uses it, and that's a sign of things to come.

> **···**
>
> > On Sep 2, 2015, at 12:48 AM, Phuong Phan \<p.h.phan2006@gmail.com\> wrote:
> > 
> > Hi Rubyists,
> > 
> > I am new to Ruby. Appreciate very much if you could introduce to me a good textbook for beginner.  
> > Thanks,  
> > Phuong
> > 
> > > On Wed, Sep 2, 2015 at 10:09 AM Raj Sahae \<rajsahae@gmail.com\> wrote:  
> > > Hi Robert,  
> > > There are different perspectives on your second question and I wouldn't  
> > > presume to have all the answers there. In my opinion, knowing how to  
> > > write some basic tests is good because you give yourself the ability to  
> > > make changes in your code and check for regressions easily. Writing  
> > > in-depth tests is a different sort of problem and you should feel free  
> > > to research that area.
> > > 
> > > For your code specifically, I have the following comments:  
> > > &nbsp;&nbsp;1) You instantiate your Report object in your library file. This is  
> > > &nbsp;&nbsp;generally bad practice. Your library should simply declare/define the  
> > > &nbsp;&nbsp;object and you should allow the user that requires your library to  
> > > &nbsp;&nbsp;instantiate the object on their own, when they want to.
> > > 
> > > &nbsp;&nbsp;2) The same concept goes for your validation. You call your validation  
> > > &nbsp;&nbsp;method in the object initializer but you should simply initialize your  
> > > &nbsp;&nbsp;state variables and then allow the user to instantiate the object on  
> > > &nbsp;&nbsp;their own and then call validation when they are ready.
> > > 
> > > &nbsp;&nbsp;3) Once you fix the above points, you can then instantiate a single  
> > > &nbsp;&nbsp;object in your spec test and test the 3 methods  
> > > &nbsp;&nbsp;(check/restart/validate) separately, which is the main strength of  
> > > &nbsp;&nbsp;unit tests (think divide and conquer).
> > > 
> > > &nbsp;&nbsp;4) Additionally, you are testing something that uses system calls to  
> > > &nbsp;&nbsp;achieve results and this can be tricky for a beginner to test (but it  
> > > &nbsp;&nbsp;is possible). You are trying to inject an initial condition to cause  
> > > &nbsp;&nbsp;failure, but you are not taking the scoping of the object into account  
> > > &nbsp;&nbsp;so therefore you don't get the desired result. You might want to  
> > > &nbsp;&nbsp;consider abstracting out the system interaction so you can test the  
> > > &nbsp;&nbsp;method logic separately.
> > > 
> > > On 09/02/2015 00:37:51, Robert Freiberger wrote:  
> > > \>Hello Ruby-lang,  
> > > \>  
> > > \>I'm learning Rspec and Ruby which I heard is a good step since it's  
> > > \>developing TDD practice for real world use. While I understand the high  
> > > \>level point of view about using TDD with Rspec, I'm struggling to know how  
> > > \>to test certain conditions.  
> > > \>  
> > > \>Below is my repo which I wrote a test for the first function but don't  
> > > \>believe this is covering the changes.  
> > > \>  
> > > \>[https://github.com/rfreiberger/Ruby-Rspec-Example](https://github.com/rfreiberger/Ruby-Rspec-Example)  
> > > \>  
> > > \>Is there suggestions on getting a proper start with Rspec or should I just  
> > > \>focus on Ruby before I learn unit testing?  
> > > \>  
> > > \>Thanks,  
> > > \>Robert
> > > 
> > > --  
> > > Raj Sahae  
> > > 408.230.8531

---

<div class="post-metadata">

**Author:** ![Robert\_Freiberger](https://avatars.discourse-cdn.com/v4/letter/r/b4bc9f/32.png) [@Robert\_Freiberger](https://rubytalk.org/u/Robert_Freiberger)\
**Post date:** [2 September 2015 22:46 UTC](https://rubytalk.org/t/learning-tdd-rspec/73207/7 "2015-09-02T22:46:47Z")

</div>

Thanks everyone,

I'm taking the feedback and working on improving my core Ruby skills. Also  
reading up on the testing. I have a copy of Well Grounded Rubyist, which I  
haven't completed yet.

Again thank you,  
Robert

> **···**
>
> On Wed, Sep 2, 2015 at 5:25 AM Daniel Llinas \<danllinas@gmail.com\> wrote:
> 
> > I'd suggest a few free online resources first. Learn Ruby The Hard way is  
> > good. Ruby Monk as well.
> > 
> > As for an actual book, the Well Grounded Rubyist has been pretty good. I'm  
> > Still working through it, but it's highly regarded, and one of the few that  
> > covers Ruby 2.0.
> > 
> > Best,
> > 
> > Danny
> > 
> > [http://www.wired.com/2015/09/facebooks-new-anti-spam-system-hints-future-coding/](http://www.wired.com/2015/09/facebooks-new-anti-spam-system-hints-future-coding/)
> > 
> > On Sep 2, 2015, at 12:48 AM, Phuong Phan \<p.h.phan2006@gmail.com\> wrote:
> > 
> > Hi Rubyists,
> > 
> > I am new to Ruby. Appreciate very much if you could introduce to me a good  
> > textbook for beginner.  
> > Thanks,  
> > Phuong
> > 
> > On Wed, Sep 2, 2015 at 10:09 AM Raj Sahae \<rajsahae@gmail.com\> wrote:
> > 
> > > Hi Robert,  
> > > There are different perspectives on your second question and I wouldn't  
> > > presume to have all the answers there. In my opinion, knowing how to  
> > > write some basic tests is good because you give yourself the ability to  
> > > make changes in your code and check for regressions easily. Writing  
> > > in-depth tests is a different sort of problem and you should feel free  
> > > to research that area.
> > > 
> > > For your code specifically, I have the following comments:  
> > > &nbsp;&nbsp;1) You instantiate your Report object in your library file. This is  
> > > &nbsp;&nbsp;generally bad practice. Your library should simply declare/define the  
> > > &nbsp;&nbsp;object and you should allow the user that requires your library to  
> > > &nbsp;&nbsp;instantiate the object on their own, when they want to.
> > > 
> > > &nbsp;&nbsp;2) The same concept goes for your validation. You call your validation  
> > > &nbsp;&nbsp;method in the object initializer but you should simply initialize your  
> > > &nbsp;&nbsp;state variables and then allow the user to instantiate the object on  
> > > &nbsp;&nbsp;their own and then call validation when they are ready.
> > > 
> > > &nbsp;&nbsp;3) Once you fix the above points, you can then instantiate a single  
> > > &nbsp;&nbsp;object in your spec test and test the 3 methods  
> > > &nbsp;&nbsp;(check/restart/validate) separately, which is the main strength of  
> > > &nbsp;&nbsp;unit tests (think divide and conquer).
> > > 
> > > &nbsp;&nbsp;4) Additionally, you are testing something that uses system calls to  
> > > &nbsp;&nbsp;achieve results and this can be tricky for a beginner to test (but it  
> > > &nbsp;&nbsp;is possible). You are trying to inject an initial condition to cause  
> > > &nbsp;&nbsp;failure, but you are not taking the scoping of the object into account  
> > > &nbsp;&nbsp;so therefore you don't get the desired result. You might want to  
> > > &nbsp;&nbsp;consider abstracting out the system interaction so you can test the  
> > > &nbsp;&nbsp;method logic separately.
> > > 
> > > On 09/02/2015 00:37:51, Robert Freiberger wrote:  
> > > \>Hello Ruby-lang,  
> > > \>  
> > > \>I'm learning Rspec and Ruby which I heard is a good step since it's  
> > > \>developing TDD practice for real world use. While I understand the high  
> > > \>level point of view about using TDD with Rspec, I'm struggling to know  
> > > how  
> > > \>to test certain conditions.  
> > > \>  
> > > \>Below is my repo which I wrote a test for the first function but don't  
> > > \>believe this is covering the changes.  
> > > \>  
> > > \>[https://github.com/rfreiberger/Ruby-Rspec-Example](https://github.com/rfreiberger/Ruby-Rspec-Example)  
> > > \>  
> > > \>Is there suggestions on getting a proper start with Rspec or should I  
> > > just  
> > > \>focus on Ruby before I learn unit testing?  
> > > \>  
> > > \>Thanks,  
> > > \>Robert
> > > 
> > > --  
> > > Raj Sahae  
> > > 408.230.8531
