DEV Community

Aliya Lewis
Aliya Lewis

Posted on

2

Are you "mocking" me?

Hi, everyone! I was hoping this blog would be about how to make a mock call to an API but unfortunately, I didn't have enough time to get to that. So today's short blog will be about what mocking is in RSpec. Let's begin!

What is mocking?

"Mocking is a technique in test-driven development (TDD) that involves using fake dependent objects or methods in order to write a test." (1)

One handy thing to note about mocking, if you have the rspec gem as a dependency in your Gemfile then you already have the rspec-mocks gem available to use.

Things I've Heard in Relation to Mocking

  • Test Doubles
  • Stubs
  • Message Expectations

Next Steps

Over the next week I'll hopefully be able to give you all examples of successfully mocked API test for a project I'm working on, but in the meantime, please share with me anything that you think might be helpful!

Resources

1) Mocking with RSpec: Doubles and Expectations

2) Project: RSpec Mocks 3-9

AWS Q Developer image

Your AI Code Assistant

Generate and update README files, create data-flow diagrams, and keep your project fully documented. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →