Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RSpec: Most accurate type for a service test

What is the most accurate test type for testing a normal ruby class (PORO) with rspec – in my case a service. Normally I would have used a :model test.

But just for the sake of idiomatic testing: Is there a way of having an rspec test which is thinner than the :model type?

like image 471
schmijos Avatar asked Aug 10 '15 13:08

schmijos


People also ask

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.

What type of testing is 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.

Is RSpec used for unit testing?

RSpec is a unit test framework for the Ruby programming language. RSpec is different than traditional xUnit frameworks like JUnit because RSpec is a Behavior driven development tool. What this means is that, tests written in RSpec focus on the "behavior" of an application being tested.


1 Answers

There is no type to apply. Just treat it as a PORO and write a spec for it. If you really wanted to add a type, you could add type: :service but it won't do anything by default.

RSpec.describe MyServiceObject do
  # specs
end
like image 130
Aaron K Avatar answered Nov 15 '22 07:11

Aaron K