4

I'm learning Rails after a long time manually testing my own .NET code,

I'm loving what ive seen but i am SO confused about how it all fits together!

So my questions are

1 - Where would i use:

Rspec

Cucumber

Test Unit

Shoulda

Selenium (not really a ruby thing but more of a web thing ive heard)

I've sort-of been testing my code with some very basic RSpec on my models and using factory girl..

2 - Do i need all of these tools?

For example could i choose cucumber and factory girl and never have to learn rspec or is cucumber a pretty dsl wrapper for rspec and test unit...

3 - Are any of them usable / have a port on .NET as well?

Thanks!

Daniel

Daniel Upton
  • 5,561
  • 8
  • 41
  • 64
  • The pb with this kind of question is there is no truth, well that's an assertion :) – apneadiving Jan 10 '11 at 00:13
  • You sound like you're in about the same place I am. Try http://railstutorial.org/book/ He has a great, thorough, and well-written tutorial that at least shows you where Rspec and Factory Girl fit into the picture. – JnBrymn Jan 28 '11 at 01:43

2 Answers2

3

My current stack of Testing tools is:

  • Steak, instead of Cucumber.
  • Capybara with driver Akephalos, instead of Selenium.
  • RSpec
  • Machinist2, instead of factory girl.

https://github.com/cavalle/steak

https://github.com/jnicklas/capybara

http://rspec.info/

https://github.com/notahat/machinist

I learned a lot about testing with the book: The Rspec Book, by the Pragmatic Programmers.

http://pragprog.com/

You have more detailed information in this other question:

Rails: Good Rspec2 example usage? (Also: Cucumber, Pickle, Capybara)

Community
  • 1
  • 1
Nerian
  • 15,901
  • 13
  • 66
  • 96
  • What do you use for Ajax testing? – apneadiving Jan 09 '11 at 23:58
  • @apneadiving: Here https://github.com/jnicklas/capybara you can read the Readme. 'Asynchronous JavaScript (AJAX and friends)' that's how you test Ajax with Capybara. – Nerian Jan 10 '11 at 00:00
  • I do know that, the pb is the setting of Capybara.default_wait_time, this is really DIY... some alternative solutions exist (https://gist.github.com/424127) but it's not yet integrated. – apneadiving Jan 10 '11 at 00:05
  • @apneadiving: I just found this testing tool and looks quite good. http://pivotal.github.com/jasmine/ It for testing Javascript, but can be integrated with Selenium ( And I guess others drivers too) – Nerian Jan 10 '11 at 12:46
  • I'll second the pitch for The Rspec Book. It was a great resource for me. – raidfive Jan 17 '11 at 08:39
2

For 1)

I do use Rspec for unit and Functional testing.

I do use Cucumber for integration testing. Cucumber uses Capybara or Selenium. I like Cucumber because it enables me to write tests with the customers. They feel implicated and thus give sometimes more details about their expectations.

Selenium could be used as a stand alone app to test your web app directly in your browser.

Many other tools exist, it's really a matter of choice. As you said, fixtures are not used anymore, Factory Girl is one of the best way to create testing data sets.

For 2)

You don't need all these tools, of course. You could even write your tests with the native Rails helpers.

But they provide convenient helpers you can take benefit from. So get the one you prefer. Some, like Cucumber, have extensions (like Pickle), to provide even more helpers.

For 3)

The strength of Rspec, Cucumber, Selenium (those I know) is they can be used to test any app.

I'm curious to listen to other's point of view concerning Ajax testing.

apneadiving
  • 114,565
  • 26
  • 219
  • 213
  • I'd say Webrat is the old Capybara. It's still much used to realize integration tests. You have many functions to browse your app, click links, fill in forms etc... – apneadiving Jan 09 '11 at 23:10
  • Ah ok... this is gonna take some getting used to! So correct me if im wrong... i write all my actual behaviour in cucumber, write the ruby code which matches the English text using a regular expression and work with RSpec directly for the specific stuff the test needs to do, then i also write some of the stuff to work with selenium?? – Daniel Upton Jan 09 '11 at 23:17
  • Also what does Capybara actually do? does it just work with the DOM? and if so then what does Selenium do.. just javascript? – Daniel Upton Jan 09 '11 at 23:18
  • Cucumber uses either Capybara or Selenium to browse your app. Both can handle javascript. The real pb is ajax testing, there is much DIY in this field. Capybara & Selenium could be used as standalone testing tools. – apneadiving Jan 09 '11 at 23:29
  • Ah ok thanks for clearing it up.. So to sum up, If I use cucumber, rspec, factory girl and capybara I'll have a full test stack, and won't need any other tools? (or would I be better off swapping capybara for selenium? Or would I be better with both) – Daniel Upton Jan 09 '11 at 23:45
  • My testing set is: Rspec + Cucucumber (using Capybara and Envjs) + Factory Girl :) it responds to my current needs! – apneadiving Jan 09 '11 at 23:56