ProductPromotion
Logo

Ruby

made by https://0x3d.site

GitHub - rr/rr: RR is a test double framework that features a rich selection of double techniques and a terse syntax. ⛺
RR is a test double framework that features a rich selection of double techniques and a terse syntax. ⛺ - rr/rr
Visit Site

GitHub - rr/rr: RR is a test double framework that features a rich selection of double techniques and a terse syntax. ⛺

GitHub - rr/rr: RR is a test double framework that features a rich selection of double techniques and a terse syntax. ⛺

RR Gem Version Build Status Code Climate GPA

RR is a test double framework for Ruby that features a rich selection of double techniques and a terse syntax.


Learning more

  1. A whirlwind tour of RR
  2. What is a test double?
  3. Syntax between RR and other double/mock frameworks
  4. API overview - Full listing of DSL methods

A whirlwind tour of RR

Stubs

# Stub a method to return nothing
stub(object).foo
stub(MyClass).foo

# Stub a method to always return a value
stub(object).foo { 'bar' }
stub(MyClass).foo { 'bar' }

# Stub a method to return a value when called with certain arguments
stub(object).foo(1, 2) { 'bar' }
stub(MyClass).foo(1, 2) { 'bar' }

Mocks

# Create an expectation on a method
mock(object).foo
mock(MyClass).foo

# Create an expectation on a method and stub it to always return a value
mock(object).foo { 'bar' }
mock(MyClass).foo { 'bar' }

# Create an expectation on a method with certain arguments and stub it to return
# a value when called that way
mock(object).foo(1, 2) { 'bar' }
mock(MyClass).foo(1, 2) { 'bar' }

Spies

# RSpec
stub(object).foo
expect(object).to have_received.foo

# Test::Unit
stub(object).foo
assert_received(object) {|o| o.foo }

Proxies

# Intercept a existing method without completely overriding it, and create a
# new return value from the existing one
stub.proxy(object).foo {|str| str.upcase }
stub.proxy(MyClass).foo {|str| str.upcase }

# Do the same thing except also create an expectation
mock.proxy(object).foo {|str| str.upcase }
mock.proxy(MyClass).foo {|str| str.upcase }

# Intercept a class's new method and define a double on the return value
stub.proxy(MyClass).new {|obj| stub(obj).foo; obj }

# Do the same thing except also create an expectation on .new
mock.proxy(MyClass).new {|obj| stub(obj).foo; obj }

Class instances

# Stub a method on an instance of MyClass when it is created
any_instance_of(MyClass) do |klass|
  stub(klass).foo { 'bar' }
end

# Another way to do this which gives you access to the instance itself
stub.proxy(MyClass).new do |obj|
  stub(obj).foo { 'bar' }
end

Installing RR into your project

NOTE: If you want to use RR with test-unit, use test-unit-rr. You don't need to read the following subsections.

For minimal setup, RR looks for an existing test framework and then hooks itself into it. Hence, RR works best when loaded after the test framework that you are using is loaded.

If you are using Bundler, you can achieve this by specifying the dependency on RR with require: false; then, require RR directly following your test framework.

Here's what this looks like for different kinds of projects:

Ruby project (without Bundler)

require 'your/test/framework'
require 'rr'

Ruby project (with Bundler)

# Gemfile
gem 'rr', require: false

# test helper
require 'your/test/framework'
require 'rr'

Rails project

# Gemfile
group :test do
  gem 'rr', require: false
end

# test helper
require File.expand_path('../../config/environment', __FILE__)
require 'your/test/framework'  # if you are using something other than MiniTest / Test::Unit
require 'rr'

Compatibility

RR is designed and tested to work against the following Ruby versions:

  • 2.4
  • 2.5
  • 2.6
  • 2.7
  • 3.0
  • JRuby 1.7.4

as well as the following test frameworks:

Help!

If you have a question or are having trouble, simply post it as an issue and I'll respond as soon as I can.

Contributing

Want to contribute a bug fix or new feature to RR? Great! Follow these steps:

  1. Make sure you have a recent Ruby (check the compatibility table above).
  2. Clone the repo (you probably knew that already).
  3. Make a new branch off of master with a descriptive name.
  4. Work on your patch.
  5. Run bundle install.
  6. Ensure all of the tests pass by running bundle exec rake.
  7. If you want to go the extra mile, install the other Ruby versions listed above in the compatibility table, and repeat steps 5-6. See the "Running test suites" section below for more information.
  8. When you're done, push your branch and create a pull request from it. I'll respond as soon as I can.

Running tests

As indicated by the compatibility list above, in order to test support for multiple Ruby versions and environments, there are multiple test suites, and Rake tasks to run these suites. The list of available Rake tasks depends on which version of Ruby you are under, but you can get the full list with:

bundle exec rake -D spec:

To run all the suites, simply say:

bundle exec rake

(Incidentally, this is also the command which Travis runs.)

Author/Contact

RR was originally written by Brian Takita. And it was maintained by Elliot Winkler ([email protected]). It is currently maintained by Kouhei Sutou ([email protected]).

Credits

With any development effort, there are countless people who have contributed to making it possible; RR is no exception! You can read the full list of credits here.

License

RR is available under the MIT license.

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory