Git Product home page Git Product logo

fakery's Introduction

fakery

Descripton

Faking Ruby objects from JSON API responses

Usage

Registering fakes

Automatically register all fakes stored in JSON files under their respective filenames:

require 'fakery'
Fakery.register_files Dir[Rails.root + 'spec/support/fakes/*.json']

Building fakes

Fakery.build(:foo) now builds a fake object for the file named foo.json in the the spec/support/fakes directory. Fakery.build(:foo, with: { bar: "something" }) builds the fake with its bar attribute set to the string "something".

For integration testing of services you can stub an API response with Fakery.build(:the_response).to_json for your specs.

Instantiate objects with fake data

Fakery.instance(:foo, as: TheModel) instantiates the model TheModel with the fake's data by passing it as a hash to the model's constructor. Fakery.instance(:foo, as: TheModel, with: { bar: "something" }) does the same with the instances bar attribute set to the string "something".

Seeding fake data from API endpoints

Fakery.seed('http://api.example.com/foo/bar.json') returns a fake initialized from the URL's JSON content. Fakery.seed('http://api.example.com/foo/bar.json', register: :foo_bar) also registers the fake with the name foo_bar. Fakery.reseed(:foo_bar) then reseeds the fake named foo_bar from the same URL.

Badges

Build Status

fakery's People

Contributors

flori avatar xijo avatar

Watchers

Daniel Hahn avatar Johannes Kulick avatar  avatar Tobias avatar Felix Wolfsteller avatar  avatar James Cloos avatar Loïc Nogues avatar Axel avatar Barbora Blo avatar Katrin Fritz avatar Marco Pagni avatar Kamil Piwko avatar  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.