0.0
No release in over 3 years
Low commit activity in last 3 years
A tiny mocking framework focused on the Arrange-Act-Assert test pattern. Grasshopper is heavily modeled after Mockito.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

Grasshopper

A tiny mocking framework focused on the Arrage-Act-Assert test pattern. Grasshopper is heavily modeled after Mockito.

Examples

For more examples, see the unit tests

Mock

Mock is a person who listens carefully but never says anything. You can say anything to Mock, but you'll only get crickets back.

mock = Grasshopper::Mock.new
mock.hello                   #=> nil
mock.how_are_you?            #=> nil
Grasshopper::Mock.verify(mock).hello      # yes, someone did tell me hello.
Grasshopper::Mock.verify(mock).goodbye    # wait(AssertionFailed)! they left without saying goodbye!

Stub

Stub is a person who holds something for you and gives it to anyone who knows how to ask. You can ask Stub for anything, but you'll only get out what you put into it.

stub = Grasshopper::Stub.new
Grasshopper::Stub.when(stub.keys).then_return([:door_key, :mail_key])
Grasshopper::Stub.when(stub.money("gimmie")).then_return(5)
stub.keys                    #=> [:door_key, :mail_key]
stub.money("gimmie")         #=> 5
stub.monkey                  #=> nil

or you can use this shorter style if you prefer:

Grasshopper::Stub.like(:keys => [:door_key, :mail_key], :money => 5)
stub.keys                    #=> [:door_key, :mail_key]
stub.money("gimmie")         #=> 5
stub.monkey                  #=> nil

Naming

Grasshopper is named for a restaurant in Allston, MA that serves up all sorts of great mocks.

Copyright

Copyright 2011-2021 Position Development, LLC.

Grasshopper is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Grasshopper is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with Grasshopper. If not, see http://www.gnu.org/licenses/.