Giter Site home page Giter Site logo

dmv_practice's Introduction

The DMV

Upgrading our testing.

Using Stubs

Remember this project from 3 years... I mean 3 weeks ago?

Recall we were making a LIVE API call in the dmv_data_service.rb file.

If we look in the spec file vehicle_factory_spec.rb, we can see that in the setup block, we are calling on methods from dmv_data_service that result in live network calls, every time we run our tests.

Why might this be bad?

  • Slooooooooow test times especially as the test suite grows and the data sets grow. We're just calling on two states worth of data here, what if we were calling on all 50 states? This would be really slow.
  • API have limits with how many times you can hit them. Hitting an API too many times can result in fees or lockout.

If we think about this from a testing perspective, we cannot control the data that comes from the API so we don't need to test their data. We want to test that the methods we wrote in our own code base work properly with the assumed input of the API data.

So how can we write our tests using assumed data? Enter Stubs!

Open vehicle_factory_spec.rb. In the test setup (before block), see if you can add a stub that tells the test that when .wa_ev_registrations is called on a dmv_service, it should return the data located in the method at the bottom of the spec file called wa_ev_reg_test_data.

Now do the same for the @ny_registrations data.

Using a Mock

Look again at the vehicle_factory_spec.rb, in the before(:each) block where we are initializing a new DmvDataService object.

Is it necessary that we actually instantiate this object?

How would we update this code to use a mock or double instead for the DmvDataService object?

Does this code still pass? What advantages does this provide? What drawbacks?

dmv_practice's People

Contributors

kaileykaes avatar katbrandt avatar epintozzi avatar jamisonordway avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.