Simple stubbing of ruby methods
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
test
.travis.yml
Gemfile
Gemfile.lock
Rakefile
Readme.md

Readme.md

Simple ruby stubbing

Build Status

Opens up Object to add instance and class methods called instance_stub.

Stubbing all instances of a class

To stub a method universally (probably a bad idea to actually use):

String.instance_stub :to_s, "Bananas"
"Apples".to_s # "Bananas"

You can also stub a method locally to a block:

String.instance_stub :to_s, "Bananas" do
  "Apples".to_s # Bananas
end
"Apples".to_s # "Apples"

Stubbing a method for just one instance of an object

x = "Apples"
y = "Pears"

x.instance_stub :to_s, "Bananas"

x.to_s # Bananas
y.to_s # Pears

Development

Tests are done via minitest. Should be this simple:

bundle install
bundle exec rake test