Dom Lizarraga

dominiclizarraga@hotmail.com

How I learned rpsec

Rspec learning resources

The best way to get a grasp of testing in general and rspec is to start from scratch a project and start writing down each test, that way you’ll be able to see what happens if you forget to close either a context block or an it block or even more intricate subjects like what’s the difference between describe and context.

While developing a freelance project I wanted to add testing as a way to push myself to learn more about testing and also give rspec a try and by doing it I learned how to use gems like: faker, shoulda-matchers, factory_bot and finally rspec. 🎲

You’ll additionally acquire:

– how to read the output of the test suite in the console.

– difference between create and build more details.;

# build doesn't persist 
user = build(:user, name: "John")
expect(user.name).to eq("John")

# create does persist 
user = create(:user, name: "Jane")
expect(user.persisted?).to be true

– How to include Devise’s test helpers

class PostsControllerTest < ActionController::TestCase
  config.include Devise::Test::ControllerHelpers, type: :requests
end

blog;

– difference between fixtures and factories;

– and finally learn how to integrate FactoryBot with RSpec link.

class Test::Unit::TestCase
  include FactoryBot::Syntax::Methods
end

Here are also another resources that I followed in order to cement more my knowledge.

Learn by doing is the best way to learn rspec DSL, development stack, learn what to test and why it’s important to test and avoid technical debt.

So give it a try, it wont be difficult at all.

June 14, 2023   @domlizarraga_