This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
| name | age | message | |
|---|---|---|---|
| |
.gitignore | Sat Jun 07 16:16:55 -0700 2008 | |
| |
MIT-LICENSE | Tue Jan 22 18:05:40 -0800 2008 | |
| |
README | Wed Feb 13 22:53:33 -0800 2008 | |
| |
Rakefile | Thu May 01 02:09:08 -0700 2008 | |
| |
TODO | Sun Feb 03 16:52:42 -0800 2008 | |
| |
lib/ | Thu Jul 23 09:14:40 -0700 2009 | |
| |
not_a_mock.gemspec | Sat Jun 07 16:18:35 -0700 2008 | |
| |
spec/ | Thu Jul 23 09:14:40 -0700 2009 |
README
= Not A Mock A cleaner and DRYer alternative to mocking and stubbing with RSpec. http://notahat.com/not_a_mock == A Quick Introduction === Mocking (Not) When you're setting up for a spec, you can ask that method calls on an object be recorded: object.track_methods(:name, :length) Once your code has run, you can make assertions about what methods were called, what arguments they took, their results, etc. object.should have_received(:length).without_args.and_returned(42) object.should have_received(:name).twice See NotAMock::Matchers for an explanation of the available assertions, plus Object#track_methods and Object#untrack_methods. === Stubbing ==== Stubbing Methods You can replace a method on an object with a stub version like this: object.stub_method(:method => return_value) Any call to +method+ after this will return +return_value+ without invoking the method's usual code. Calls to stub methods are recorded as if you had called +track_methods+ on them, so you can make assertions about them as shown above. See Object#stub_methods, Object#unstub_methods. ==== Stubbing Objects You can also replace an entire object with a stub version like this: my_object = MyClass.stub_instance(:method_a => return_value, :method_b => return_value, ...) The returned +my_object+ is a stub instance of MyClass with the given methods defined to provide the corresponding return values. See Object.stub_instance. ==== Stubbing ActiveRecord Instances When you call +stub_instance+ on an ActiveRecord::Base subclass, Not A Mock automatically provides an +id+ method and generates an id for the object. == Installation (The following describes using NotAMock with Rails. It should also be possible to use it outside of Rails, but I haven't tried it.) First, install the rspec and rspec_on_rails plugins: ruby script/plugin install http://rspec.rubyforge.org/svn/tags/CURRENT/rspec ruby script/plugin install http://rspec.rubyforge.org/svn/tags/CURRENT/rspec_on_rails ruby script/generate rspec (See http://rspec.info/documentation/rails/install.html for more details.) Second, install the not_a_mock plugin: ruby script/plugin install http://svn.notahat.com/not_a_mock/trunk Finally, add the following to your project's spec/spec_helper.rb: config.mock_with NotAMock::RspecMockFrameworkAdapter == Contributing Send bugs, patches, and suggestions to Pete Yandell (pete@notahat.com) Thanks to Pat Allan and Steve Hayes for contributing patches.







