Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I be using RSpec or Cucumber

I'm new to unit/func testing in Rails 3. So I'm starting now, better late than never.

I have a method in /lib/mailingjob.rb called find_reply(body)

Right now I'm using cucumber to test this but given that this is all backend, no web interface to this, should I not be using cucumber?

I'm finding when to use RPSEC vs cucumber confusing.

Thanks

like image 395
AnApprentice Avatar asked Mar 15 '11 17:03

AnApprentice


People also ask

What is the difference between RSpec and Cucumber?

The main difference between RSpec and Cucumber are the business readability factor. Cucumber's main draw is that the specification (features) are separate from the test code, so your product owners can provide or review the specification without having to dig through code.

Is RSpec TDD or BDD?

RSpec is a Behavior-Driven Development tool for Ruby programmers. BDD is an approach to software development that combines Test-Driven Development, Domain Driven Design and Acceptance Test-Driven Planning. RSpec helps you do the TDD part of that equation, focusing on the documentation and design aspects of TDD.

Why do we use RSpec?

RSpec is a testing tool for Ruby, created for behavior-driven development (BDD). It is the most frequently used testing library for Ruby in production applications. Even though it has a very rich and powerful DSL (domain-specific language), at its core it is a simple tool which you can start using rather quickly.

Does RSpec clean database?

I use the database_cleaner gem to scrub my test database before each test runs, ensuring a clean slate and stable baseline every time. By default, RSpec will actually do this for you, running every test with a database transaction and then rolling back that transaction after it finishes.


2 Answers

In my opinion, you need to use both. Rspec is very good for unit testing, that is testing models, controllers, views. On the other hand, cucumber is a very nice tool to check full scenarios like a user logs in, clicks a link and he is supposed to view this.

I highly advise that you take a look at the cucumber railscast from railscasts.com. Also, make sure that you use webrat and maybe something to auto load your specs like watchr(which i prefer).

like image 166
Spyros Avatar answered Nov 14 '22 13:11

Spyros


I'd advise you to never use Cucumber unless you are specifically employed as a business analyst. That makes your life much easier: all your tests will be in Rspec.

Cucumber takes a toll on your productivity, and your sanity. Running parallel test environments, adding layers of abstraction and breaking your editor with its odd syntax make for lost time. I've written about this extensively on my blog: Why Bother With Cucumber Testing?

like image 40
Jack Kinsella Avatar answered Nov 14 '22 13:11

Jack Kinsella