Comprehensive guide on testing rails app - ruby-on-rails

Is there any comprehensive guides on testing rails apps. Im searching for guide that will tell me what should I test and how should I test it especially with Rspec. Lots of examples will be appreciated.

The RSpec Book
Testing the rails app is part of development so I'd sugest to read Ruby on Rails Tutorial, Learn Rails by Example by Michael Hartl, it has good explained testing process.

The Rails Guide A Guide to Testing Rails Applications is a good place to start.
It covers the default test/unit style of testing.
As suggested by #megas, the RSpec book is another place to look.
Agile Web Development with Rails is a great first book for any rails developer, covering the full process of building an application, testing it as you go.

Also take a look at Railscast as well.
Some episodes that talks about testing:
Episode 275: How I Test
Episode 257: Request Specs and Capybara
Episode 158: Factories not Fixtures revised or Older Episode
Episode 261: Testing JavaScript with Jasmine

Check out Everyday Rails Testing with RSpec. Sumner does a great job of walking you through writing tests for an entire app. The Hartl book is also a great resource.

Related

How to write cucumber test cases?

Can anyone tell me how to write cucumber testcases as am new to this.Suggest me best tutorial togo through for this.
Thanks in Advance.
Rails cast is nice
Nice book for basic setup: The Cucumber Book: Behaviour-Driven Development for Developers and Testers
Also, the Nettuts+ tutorial: Ruby for Newbies: Testing Web Apps with Capybara and Cucumber
This screencast is the best out there. Do checkout part 2 as well! BTW, in cucumber parlance, they are called 'features' where you describe scenarios.
I can personally recommend "The RSpec Book: Behaviour-Driven Development with RSpec, Cucumber, and Friends" if you want to know more about BDD with Cucumber although I am in no way related to the authour(s) and/or the publisher.
Assuming that you have setup cucumber, I would recommend to use https://github.com/cucumber/cucumber/wiki/Scenario-Outlines

writing test for rubyonrails

I am new to writing test for rubyonrails app like rspect, steak, cucumber etc. How do I start or learn so that it will help me to write beautiful codes?
You can give some simple example or some url where I can understand from zero.
Thanks
http://railscasts.com/episodes/155-beginning-with-cucumber - a good podcast for beginner
The RSpec Book - also very useful
It's a good point to start and then Google help you
1) Start by reading the rails testing guide just to get a feel for testing.
2) Become familiar with the various testing frameworks (Cucumber, rspec, testunit, steak, minitest), watch screencasts (railscasts, TeachMeToCode) and then try and choose one that appeals to you.
3) Write tests!! and get help as you need it from StackOverflow. If you like RSpec then the RSpec book is very helpful, but not essential.
My personal opinion on frameworks:
I started out really liking cucumber but I eventually found it very verbose and I didn't like using it for my integration tests and then RSpec for my unit and functional tests. I now like using just RSpec with Capybara and Shoulda matchers. TestUnit can be even less verbose than RSpec but personally I find RSpec to be the happy medium between writing self documenting code and not being overly verbose.
I've just started with RSpec a few days ago and it was pretty hard (it still is actually). You could start from railstutorial.org. The author follows the TDD principle. More info available at RSpec and Cucumber github page. Be sure to check out the wiki.

How to create Rails App using cucumber

I am new for cucumber. I want to create on sample application using cucumber.
I am working on Windows 7 OS. Can any one guide me?
Thanks.
I think these are two separate problems:
Building a Rails application on Windows
Building a Rails application with Cucumber (using principles promoted by Cucumber like BDD, Specification by Example and an outside-in workflow)
Building a Rails application on Windows
There are a lot of tutorials, best starting point is probably: Getting Started with Rails on Rails Guides.
However the official advice there is using a virtual machine with Linux :-)
Here is a good thread with advice for running Rails under Windows.
Building a Rails application with Cucumber
An extraordinary example for this is the Book Rails 3 in Action by Manning.
This book really excels at showing how to create an application outside-in with Specification by Example using Cucumber.
In each chapter of the book a new feature is implemented. There are almost no screenshots explaining those features. Instead the authors are using Cucumber scenarios at the beginning of each chapter to exactly specify the desired new behavior that is the topic of given chapter. Then they are showing and explaining the necessary steps and the code that is needed to implement the functionality.
This is the best example I have found for using Cucumber with Rails so far.
This is also a really great example how Specfication by Example can be used for building a shared understanding - since teaching is all about sharing understanding.
However the scenarios in the book are quite focusing of specifying behavior on the UI level ... which is not commonly agreed on being best practice. But for teaching Rails it is great.
Rails 3 in Action is still in the early access program. I don't know where the official sources are.
But when you search on GitHub you already find different implementations of the example application (Tiketee):
https://github.com/rubykr/ticketee
https://github.com/oMartell/ticketee-rails-3-in-action
https://github.com/rails3book/ticketee
Here is the guide how to do it.
I found an interesting webcast video that does just this.
The basic procedure is define a couple features in cucumber. (actually the gherkin language)
Run cucumber
Fix errors
Repeat the
2 steps until you have a
working app.
It makes use of a few RoR gems like webrat and rspec.
http://railscasts.com/episodes/155-beginning-with-cucumber

Cucumber and Rspec

Can anyone suggest me good source (Easy examples) for cucumber and rspec tutorials (rails 3)???
Edit:
Actually I am looking for free online resources with good examples..
I think the RSpec Book is an excellent resource on Cucumber, RSpec and BDD.
Agree - the RSpec Book provides a wealth of information. I found getting the flow was a big problem in the learning. The book gives you the quick intro, then dives into details and by the time you surface your head will be swimming. It takes a couple of goes of reading the book to get the finer points.
Another great read is a blog post by Sarah Mei called Outside-In BDD. This dialog really help to make things gel since it's demonstrating the application of Cucumber/Rspec in the context of the flow a developer would go through.
Then there is the classics such as the Railscast from Ryan Bates. There are a couple of episodes on Cucumber and other tools and the snippets give you a nice overview after you've soaked up the RSpec book.
For Rspec you can read the Michael Hartl book "Rails 3 tutorial" there is a lot of testing examples : Here the online book
For cucumber, you can watch teachmetocode screencasts (website) . There are good examples using cucumber when building an application from scratch.
Hope it could help!
Screencast walk-throughs can be good sources to grok them
Peepcode has a few, like this one on Cucumber, which has been updated this year - so I'm assuming it's good for rails 3

What is the Path to Learn BDD on Ruby On Rails?

I want to start BDD on Ruby On Rails what should I learn?
I don't know anything about BDD, RSpec or Cucumber. What is the best way to learn? Tutorials? Something that cover things like 'What behavior I should test?' etc.
thanks!
RSpec specific; I keep these links for reference (might be advance for beginners). But just wanna share it with you. (Some of it probably already outdated but I think still worth a read)
Rspec Link Fest - links to other references
RSpec in Controllers:
Testing your Application Controller with rSpec
Testing Controllers with rspec
Using Rspec on Controllers
RSpec in Models:
stub_model by Dave Chelimsky
Do we really need Controller and View tests? - some discussion
RSpec in Views:
RSpec testing views for escaped HTML
Rspec Stories (now Cucumber):
Understanding RSpec Stories - a Tutorial
Rspec on Windows:
RSpec, autotest and Snarl on Windows - dunno if this still relevant
p/s: Some are from 2007, I'm not sure if the stuffs are outdated or not, but these are the some of my references used to learn RSpec. Hope it helps
Start with two articles by Dan North: Introducing BDD, followed closely What's in a Story?
Start at the top, RSpec home page:
http://rspec.info/

Resources