• Stars
    star
    13
  • Rank 1,465,120 (Top 30 %)
  • Language
    Crystal
  • License
    MIT License
  • Created almost 9 years ago
  • Updated about 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Doubles (stubs and mocks) library for Crystal, inspired by the API of rspec-mocks

Mock Build Status

Mock is a doubles (stubs and mocks) library for Crystal, inspired by the API of rspec-mocks (but it implements a small basic subset of it to the date).

Installation

Add this to your application's shard.yml:

development_dependencies:
  mock:
    github: porras/mock

You can now run shards to install it.

Usage

Require it in your tests and you can start using it.

require "mock"

Creating a double

Just call the double() method.

Stubbing a method

Calling stub on that double object will set a method stub:

my_object = double()
my_object.stub(:my_method)

You can establish a return value for the stub method (if you don't, method stubs return nil):

my_object = double()
my_object.stub(:my_method).and_return("my value")

my_object.my_method.should eq("my value")

You can also filter my arguments, establishing different stubs for the same method:

my_object = double()
my_object.stub(:my_method).with(1).and_return("value 1")
my_object.stub(:my_method).with(2).and_return("value 2")

my_object.my_method(1).should eq("value 1")
my_object.my_method(2).should eq("value 2")

Setting expectations

You can also set the expectation that a method will be called, and it will be automatically checked at the end of the test:

my_object = double()
my_object.should_receive(:my_method).with(1).and_return("my value")

# if we omit this line, the test will fail
my_object.my_method(1).should eq("value 1")

See example_spec.cr for more examples.

Contributing

  1. Fork it ( https://github.com/porras/mock/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

License

This code is released under the MIT License.

Contributors

More Repositories

1

crul

Command line HTTP client written in Crystal
Crystal
112
star
2

i3-keyboard-layout

Change keyboard layout with a keystroke + show it in the status bar
Shell
93
star
3

dmenu-emoji

Search an emoji by name and copy it to the clipboard [i3, dmenu, rofi]
Shell
63
star
4

mrproper

Property Based Testing in Ruby
Ruby
34
star
5

imdb

Wrapper library to search IMDB parsing its HTML
Ruby
29
star
6

duct

Duct allows you to embed a Gemfile in a single file script
Ruby
27
star
7

livevalidation

Client-side validations for Ruby on Rails (using javascript library livevalidation.com)
Ruby
26
star
8

tlcr

Simple terminal-based client for TLDR pages, written in Crystal. TLDR pages is a collection of simplified and community-driven man pages.
Crystal
23
star
9

session

Cookie based sessions in Crystal HTTP applications
Crystal
23
star
10

rakegrowl

Get Growled when your long running rake tasks finish
Ruby
19
star
11

ghcontributors

Github Contributors
JavaScript
13
star
12

evil-ruby-text-objects

Emacs package that adds some text objects and keybindings to work with Ruby code with Evil.
Emacs Lisp
10
star
13

rosendo

Minimalistic and naive Sinatra reimplementation, without any dependencies other than the ruby socket library
Ruby
9
star
14

language_detection

Rails plugin to detect the language of a given string
Ruby
8
star
15

sonic-pi-akai-apc-mini

Utility functions to use the Akai APC mini MIDI controller with Sonic Pi
Ruby
6
star
16

includer

Easy way to include files into another files
Ruby
6
star
17

store

File based storage library for Crystal (inspired by Ruby's PStore)
Crystal
6
star
18

random_items

Rails plugin to pick random items from a model (without using :order => "RAND()")
Ruby
6
star
19

rubystdlib

Slides, examples and reference links from my talk โ€œ5 gems of the Ruby Standard Libraryโ€
Ruby
5
star
20

madrid-rb-feb-2010

Sample application I used in my talk about acceptance testing with Steak and Capybara in Madrid-rb
Ruby
5
star
21

RGSoC_material

Ruby
5
star
22

tkn2

Tkn2 is a presentation tool for the terminal heavily inspired by Xavier Noria's tkn (Terminal Keynote)
Ruby
5
star
23

pipes

Ruby
4
star
24

nested_open_struct

Ruby
4
star
25

enumerator-talk

Examples for the talk about Enumerable and Enumerator I gave in RUG::B July 2015
3
star
26

-

Semantically awesome testing library
Ruby
3
star
27

twitter_common_friends

GreaseMonkey script which shows your common friends with any other Twitter user (a la Facebook)
JavaScript
3
star
28

hyperdelegate

Rails plugin which adds two options to delegate to make it more flexible and support two frequent patterns in delegation.
3
star
29

trenza

Ruby
2
star
30

pouchdb_test

JavaScript
2
star
31

ujfalusi

Ruby
2
star
32

sem_ver

Semantic Versioning parser
Ruby
1
star
33

magit-spinner

Emacs Lisp
1
star
34

fragments

1
star
35

sonic-pi-mode

Emacs Lisp
1
star