Giter VIP home page Giter VIP logo

webmock-rspec-helper's Introduction

WebMock RSpec Helper

This gem provides a helper method webmock which makes it easier to stub requests.

Installation

Add this line to your application's Gemfile and bundle:

gem 'webmock-rspec-helper'

Usage

Use the webmock method to map regular expressions to a filename. Files should be spec/support/stubs. The webmock method will parse any digits between periods out of the filename to infer the status code (defaulting to 200).

Given the directory tree:

spec/
  support/
    stubs/
      GET_google.json
      GET_google.401.json
  webmock_spec.rb

You can use webmock within webmock_spec.rb like this:

# Will stub requests to Google to return the contents of GET_google.json. Requests will return a 200 status code.
webmock :get, %r[google.com] => 'GET_google.json'

# Stub requests to Google to return the contents of GET_google.401.json. Requests will return a 401 status code.
webmock :get, %r[google.com] => 'GET_google.401.json'

# Stub requests to Google to return a 204 status code and an empty body
webmock :get, %r[google.com] => 204

# Stub requests to Google to return the contents of GET_google.json when the query parameters match { test: '123' }
webmock :get, %r[:google.com] => 'GET_google.json', with: Hash[query: { test: '123' }]

Contributing

  1. Fork it ( https://github.com/[my-github-username]/webmock-rspec-helper/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

webmock-rspec-helper's People

Contributors

pingortle 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.