yusemoose
yusemoose

Reputation: 17

Testing with Capybara: Can it be used to test data models?

Just started using rails and still in the midst of putting things together, hence sorry if my question is simple but can Capybara be used for testing databases(data models) because all the examples that i have seen have it testing views and sometimes controllers? And I know that rspec works great for TDD in data models via failing tests but can Capybara do this as well?

Upvotes: 0

Views: 76

Answers (2)

auralbee
auralbee

Reputation: 8841

Capybara is for integration testing, meaning it simulates requests from a real browser usage, clicking and typing and so on.

If you want to test your models use Test::Unit, Rspec, Shoulda.

Upvotes: 0

Jesse Wolgamott
Jesse Wolgamott

Reputation: 40277

Capybara is an Acceptance framework for web applications. That means it tests the full stack, through a browser (or browser-like) interface.

So it wouldn't make sense to use a browser to test a data-model or business-logic class. They don't have an interface for a browser to talk to them. It's web -> framework -> classes. Capybara becomes the "web"

That's where Test::Unit, RSpec, and/or Minitest come in. They are designed to be code -> classes.

Upvotes: 1

Related Questions