Jump to content

User:Dguttik/sandbox: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Dguttik (talk | contribs)
Dguttik (talk | contribs)
Line 31: Line 31:
# https://www.ruby-toolbox.com/projects/bogus
# https://www.ruby-toolbox.com/projects/bogus
# https://packages.debian.org/sid/ruby/ruby-bogus
# https://packages.debian.org/sid/ruby/ruby-bogus
# http://gunpowderlabs.com/blog/write-safer-tests-with-bogus/
# https://coderwall.com/p/d1dksg/safe-stubbing-with-bogus

Revision as of 20:12, 10 February 2017

Bogus (Ruby gem)

Bogus is a ruby API library used for minimizing risks involved in isolated unit testing. It is initially released in July 2012 by rubygems.org. Through bogus a piece of code can be tested in a fast and safe manner, without any actual integration with external programs . Bogus provides a safe mock external framework by ensuring that a user cannot mock or stub methods not present in the required external environment.

Features

Ruby provides various features to achieve required testing framework.

Fakes

Fakes are light weight objects that mock actual object's interface. In order to test a class in isolation, usually some test doubles or anonymous objects are used in place of integrated classes with required methods stubbed in it. But there is a problem with this approach, If the class is changed in between, those changes are not reflected in mock objects and tests run without any integration exceptions. Fakes resolve this problem as they will have exact interface of real collaborator and will raise an exception whenever the actual class is modified.

Fakes can be implemented using following methodologies

Faking Real classes

A fake is created by calling fake method :

Syntax:

fake(fake_name, options) { ClassToCopy }

"fake_name" is the name of created fake and can be used to identify the fake while using contract tests. if it is omitted then an anonymous fake is created.Fake provides options to return an instance or a copy of class depending on the requirement. Fakes can be applied to stub methods as well.

Global Configuration

Fakes avoid the need of stubbing and eliminate much of configuration things like (as: :class / as: :instance). Regardless, this type of configuration should be added to fake definitions and the more collaborators one has there will be more duplication. Bogus deals this problem by introducing DSL to configure fakes in single place thus unifying it's use in all the tests. Stubbed methods can be overridden using fake macros or fake helper functions.

Nameless Test Doubles

Anonymous test doubles can be used while migrating objects from another testing library. Fakes in bogus library respond to all methods by default.

References

  1. https://www.relishapp.com/bogus/bogus/v/0-1-6/docs/getting-started
  2. https://github.com/psyho/bogus
  3. https://github.com/groyoh/bogus
  4. https://www.ruby-toolbox.com/projects/bogus
  5. https://packages.debian.org/sid/ruby/ruby-bogus
  6. http://gunpowderlabs.com/blog/write-safer-tests-with-bogus/
  7. https://coderwall.com/p/d1dksg/safe-stubbing-with-bogus