All Projects → featurist → Strictly_fake

featurist / Strictly_fake

Licence: mit
Stub that automatically verifies that stubbed methods exist and the signatures match the original.

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Strictly fake

Fake server
FakeServer integrates with ExUnit to make external APIs testing simpler
Stars: ✭ 64 (+255.56%)
Mutual labels:  fake, stub
Mocha
Mocha is a mocking and stubbing library for Ruby
Stars: ✭ 1,065 (+5816.67%)
Mutual labels:  stub, minitest
Clj Fakes
An isolation framework for Clojure/ClojureScript.
Stars: ✭ 26 (+44.44%)
Mutual labels:  fake, stub
Impersonator
Ruby library to record and replay object interactions
Stars: ✭ 100 (+455.56%)
Mutual labels:  fake, stub
ts-mock-imports
Intuitive mocking library for Typescript class imports
Stars: ✭ 103 (+472.22%)
Mutual labels:  stub, fake
Stubmatic
Mock HTTP calls without coding. Designed specially for testing and testers.
Stars: ✭ 118 (+555.56%)
Mutual labels:  stub, fake
Faker.Portable
C# faked data generation for testing and prototyping purpose.
Stars: ✭ 12 (-33.33%)
Mutual labels:  stub, fake
stub-server
Stub server for REST APIs
Stars: ✭ 14 (-22.22%)
Mutual labels:  stub, fake
Fako
Struct Faker for Go
Stars: ✭ 329 (+1727.78%)
Mutual labels:  stub
Bogus
📇 A simple and sane fake data generator for C#, F#, and VB.NET. Based on and ported from the famed faker.js.
Stars: ✭ 5,083 (+28138.89%)
Mutual labels:  fake
Project Stub
deps
Stars: ✭ 300 (+1566.67%)
Mutual labels:  stub
Mocker Data Generator
A simplified way to generate masive mock data based on a schema, using the awesome fake/random data generators like (FakerJs, ChanceJs, CasualJs and RandExpJs), all in one tool to generate your fake data for testing.
Stars: ✭ 333 (+1750%)
Mutual labels:  fake
Fakewechatloc
手把手教你制作一款iOS越狱App
Stars: ✭ 463 (+2472.22%)
Mutual labels:  fake
Mimesis
Mimesis is a high-performance fake data generator for Python, which provides data for a variety of purposes in a variety of languages.
Stars: ✭ 3,439 (+19005.56%)
Mutual labels:  fake
Amber
Reflective PE packer.
Stars: ✭ 594 (+3200%)
Mutual labels:  stub
Minitest
minitest provides a complete suite of testing facilities supporting TDD, BDD, mocking, and benchmarking.
Stars: ✭ 2,962 (+16355.56%)
Mutual labels:  minitest
Awesomefakenews
This repository contains recent research on fake news.
Stars: ✭ 270 (+1400%)
Mutual labels:  fake
Fakelogonscreen
Fake Windows logon screen to steal passwords
Stars: ✭ 710 (+3844.44%)
Mutual labels:  fake
Ohhttpstubs
Stub your network requests easily! Test your apps with fake network data and custom response time, response code and headers!
Stars: ✭ 4,831 (+26738.89%)
Mutual labels:  stub
Knapsack
Knapsack splits tests evenly across parallel CI nodes to run fast CI build and save you time.
Stars: ✭ 430 (+2288.89%)
Mutual labels:  minitest

StrictlyFake Build Status Gem Version

Sometimes fakes are a good choice. But the price is high. In particular, they make changing code harder. You rename a method, but all tests that stub the previous version keep passing. It would be nice if those started to fail so that when they're green again, you can be certain that everything that had to be updated was updated. Well, now you can.

To be fair, you already can in Rspec with their verifying double. But what about Minitest? And there are still differences. Unlike verifying double:

  • here you need to supply real objects to create fakes. That's controversial - as it goes against the idea of testing in isolation - but realistically, at least in Rails, everything is loaded anyway, so that's a moot point;
  • strictly_fake is aware of autogenerated methods (e.g. ActiveRecord model accessors);
  • strictly_fake does not stub constants (e.g. classes). You can, however, pass a fake to Minitest's Object#stub to achieve this (see example below);
  • strictly_fake performs a full parameter check, comparing required, optional and keyword arguments (veryfing double only checks arity afaik).

Installation

Add this line to your application's Gemfile:

gem 'strictly_fake'

And then execute:

$ bundle install

Usage

require 'strictly_fake'

# Given we don't want to actually pay in tests
class PaymentGateway
  def pay(recipient, amount, reference = nil);
    # calls remote payment provider...
  end
end

# We can use a fake instead
payment_gateway = StrictlyFake.new(PaymentGateway.new)

# Let's stub a method that _isn't_ defined in PaymentGateway:
payment_gateway.stub(:bar)
# => throws "Can't stub non-existent method PaymentGateway#bar (StrictlyFake::Error)"

# Let's stub an existing method, but with a wrong signature: 
payment_gateway.stub(:pay) { |amount| }
# => throws "Expected PaymentGateway#pay stub to accept (req, req, opt=), but was (req) (StrictlyFake::Error)"

# All good now!
payment_gateway.stub(:pay) { |recipient, amount, reference = nil| 'Success!' }

payment_gateway.pay('Dave', 10)
# => 'Success!'

# Makeshift mock
invoked = false
payment_gateway.stub(:pay) do |recipient, amount, reference = nil|
  # Further arguments check
  assert(amount.is_a?(Money))
  invoked = true
end

payment_gateway.pay('Dave', Money.new(10))
assert(invoked)
# => Pass

# Stubbing class methods is no different
time = StrictlyFake.new(Time)

time.stub(:now) { 'XYZ' }
time.now
# => 'XYZ'

# Combine with Minitest stub to actually stub constant
Time.stub :now, time.now do
  Time.now
  # => 'XYZ'
end

Note: Minitest is required for assert* to work.

Development

After checking out the repo, run bundle install to install dependencies. Then, run bundle exec rspec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/featurist/strictly_fake.

License

The gem is available as open source under the terms of the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].