Everyone wants their code was reliable, cleaner and just great! We collected the most reliable Rails testing tools that you can certainly be sure about. We use most of them in Syndicode, but of course, RSpec is the most honorable one.
Let’s start with the Rails testing tools you’ve probably come across more often:
- RSpec is a testing tool that allows you to write and run your tests. It has an analog – MiniTest.
- Capybara is another tool that uses helper methods like
fill_into fill in a form field and many other. It’s not used in conjunction with Cucumber and sometimes it’s possible to write integration tests in Rails and use only Capybara.
- Cucumber is a tool that helps to write a test using code similar to English-like syntax. But it can be more complicated than the previous two.
- MiniTest is a tool that supports TDD, BDD, mocking, benchmarking. It’s small, fast and easy in use.
- Test-unit is a unit testing tool for Ruby, that is based on xUnit. You can write tests, check your results and automate testing in Ruby.
- Timecop – a gem with “time travel” function, helping in making test time-dependent code. It uses a method to mock Time.now, Date.today, and DateTime.now in one call.
- Factory_bot is a tool and DSL that provides using factories.
- Fabrication has an object-generation function and can be used for ActiveRecord, Mongoid, DataMapper, Sequel, and other Ruby object.
- WebMock is a tool that helps in stubbing HTTP requests and sets new expectations.
- VCR provides you with the record of suite’s HTTP interactions during the test, so you can replay them again for the next tests.
- Selenium WebDriver helps you to write automated tests of websites. It mimics the behavior of users.
- Faker is used for mixing random data in one application. You can call Faker to generate a name, mobile number, some name and use it.
- Database Cleaner is responsible for checking if our database clearer after running automated tests suite.
Using tests is great when you remember some of the basic but important principles:
- Don’t test Rails validations, associations and simple scopes.
- Test custom validations, regular expressions, complicated scopes, custom methods, and custom attribute writers.
To find more tips about programming in Rails, please check our video tutorials.
p.s. Every month we publish a regular Rails digest with the most interesting and popular Ruby/Rails open source repositories. Some of the testing tools mentioned above were explored first thanks to our digests.
We have Telegram!