-
Notifications
You must be signed in to change notification settings - Fork 14
MockingComponents
nesquena edited this page Sep 13, 2010
·
4 revisions
This section covers the specifics of setting up an application using the sinatra_more generators and each mocking component.
To use mocha, you must first install the gem:
$ sudo gem install mocha --source http://gemcutter.org
Now, you can invoke the generator:
$ sinatra_gen demo_app . -m mocha
You are now able to use mocha to mock and stub within your tests. To mock simply use:
SomeClass.expects(:some_class_method).times(2).returns(true)
SomeClass.any_instance.expects(:some_method).times(2).returns(true)
and to stub an object:
SomeClass.stubs(:some_class_method).returns(false)
or create a stub from scratch:
object = stub(:hello => "demo")
object.hello # => "demo"
For more information on mocha, check out the Mocha Documentation
To use rr, you must first install the gem:
$ sudo gem install rr --source http://gemcutter.org
Now, you can invoke the generator:
$ sinatra_gen demo_app . -m rr
You are now able to use rr to mock and stub within your tests. To mock simply use:
mock(SomeClass).some_class_method { true }
mock.instance_of(SomeClass).some_method {false}
and to stub an object:
stub(SomeClass).some_class_method { false }
or create a stub from scratch:
object = Object.new
stub(object).hello { "demo" }
object.hello # => "demo"
For more information on mocha, check out the RR Documentation