Please help me learn how to use rspec!

Hi,

So-- I am very very new to BDD… and I am trying to go over and write
some tests for existing code that has been problematic… I am
struggling with knowing exactly how to write the proper specs. So I
wrote out a list of things this controller action should do, but as
far as how to really hook in and test the individual components, I am
a bit hazy, so I am hoping some people here can chime in and school
me.

To give some background on what is going on in this code-- I have a
form that lists contacts which is used in two different contexts–
One for newsletter mailings lists, and the other for shipping labels
(pdf list). So I have a controller action called ‘result_list’ that
is part of my contacts_controller (in my routes, it’s a :collection
=> :put). This action looks if there is a newsletter_id param, and if
so, it knows to look up a newsletter, otherwise it looks up a pdf
list.

If this newsletter/pdf list is not currently being modified / sent /
etc, then a rake task is launched which adds or removes additional
contacts to the list.

After that is complete, if javascript is disabled, it redirects back
to the contacts path, and if it’s an ajax request (which it most
likely will be, it renders nothing-- there is unobtrusive js that
handles updating the page).

… So, if someone could please point me in the right direction as
far as what my test code SHOULD look like, I’d greatly appreciate it.
I have no idea how to test if a rake task fails or not… I have no
idea how to hook into the controller code and determine whether the
result_lis variable is a PdfList class or a Newsletter class… And I
have no idea how to test whether a http request redirects to
contacts_path, or if an ajax request renders nothing!

I feel like, I know what I want to test, but I just have no idea how
to test it…

Thank you for any guidance.

-patrick

patrick99e99 wrote:

Hi,

So-- I am very very new to BDD… and I am trying to go over and write

The best place to start is the RSpec Book.

http://www.pragprog.com/titles/achbd/the-rspec-book

Peace,
Phillip

Yeah, I have the book… have read it… also have watched peepcode’s
three screencasts on rspec, also have watched the first 7 episodes of
BDDCasts.

I just am still fuzzy on lots of things, and am hoping someone will be
kind enough to go through my spec file and show me what kind of code
they would write to get it to accomplish what it needs to.

-patrick


rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users


rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs