Skip to content

Commit

Permalink
cleanup and add some rdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
dchelimsky committed Oct 16, 2011
1 parent b3832f5 commit f646743
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 61 deletions.
19 changes: 0 additions & 19 deletions README.md
Expand Up @@ -3,21 +3,6 @@
rspec-mocks provides a test-double framework for rspec including support
for method stubs, fakes, and message expectations.

[![build status](http://travis-ci.org/rspec/rspec-mocks.png)](http://travis-ci.org/rspec/rspec-mocks)

## Documentation

The [Cucumber features](http://relishapp.com/rspec/rspec-mocks) are the
most comprehensive and up-to-date docs for end-users.

The [RDoc](http://rubydoc.info/gems/rspec-mocks/2.3.0/frames) provides additional
information for contributors and/or extenders.

All of the documentation is open source and a work in progress. If you find it
lacking or confusing, you can help improve it by submitting requests and
patches to the [rspec-mocks issue
tracker](https://github.com/rspec/rspec-mocks/issues).

## Install

gem install rspec # for rspec-core, rspec-expectations, rspec-mocks
Expand Down Expand Up @@ -48,10 +33,6 @@ tracker](https://github.com/rspec/rspec-mocks/issues).
end
end

## Contribute

See [http://github.com/rspec/rspec-dev](http://github.com/rspec/rspec-dev)

## Also see

* [http://github.com/rspec/rspec](http://github.com/rspec/rspec)
Expand Down
44 changes: 19 additions & 25 deletions lib/rspec/mocks/argument_matchers.rb
Expand Up @@ -138,71 +138,65 @@ def ==(actual)
end
end

# :call-seq:
# object.should_receive(:message).with(any_args())
#
# Passes if object receives :message with any args at all. This is
# really a more explicit variation of object.should_receive(:message)
#
# == Examples
# object.should_receive(:message).with(any_args())
def any_args
AnyArgsMatcher.new
end

# :call-seq:
# object.should_receive(:message).with(anything())
#
# Passes as long as there is an argument.
#
# == Examples
# object.should_receive(:message).with(anything())
def anything
AnyArgMatcher.new(nil)
end

# :call-seq:
# object.should_receive(:message).with(no_args)
#
# Passes if no arguments are passed along with the message
#
# == Examples
# object.should_receive(:message).with(no_args)
def no_args
NoArgsMatcher.new
end

# :call-seq:
# object.should_receive(:message).with(duck_type(:hello))
# object.should_receive(:message).with(duck_type(:hello, :goodbye))
#
# Passes if the argument responds to the specified messages.
#
# == Examples
#
# array = []
# display = double('display')
# display.should_receive(:present_names).with(duck_type(:length, :each))
# => passes
# object.should_receive(:message).with(duck_type(:hello))
# object.should_receive(:message).with(duck_type(:hello, :goodbye))
def duck_type(*args)
DuckTypeMatcher.new(*args)
end

# :call-seq:
# == Examples
# object.should_receive(:message).with(boolean())
#
# Passes if the argument is boolean.
def boolean
BooleanMatcher.new(nil)
end

# :call-seq:
# Passes if the argument is a hash that includes the specified key(s) or key/value
# pairs. If the hash includes other keys, it will still pass.
#
# == Examples
# object.should_receive(:message).with(hash_including(:key => val))
# object.should_receive(:message).with(hash_including(:key))
# object.should_receive(:message).with(hash_including(:key, :key2 => val2))
# Passes if the argument is a hash that includes the specified key(s) or key/value
# pairs. If the hash includes other keys, it will still pass.
def hash_including(*args)
HashIncludingMatcher.new(anythingize_lonely_keys(*args))
end

# :call-seq:
# Passes if the argument is a hash that doesn't include the specified key(s) or key/value
#
# == Examples
# object.should_receive(:message).with(hash_not_including(:key => val))
# object.should_receive(:message).with(hash_not_including(:key))
# object.should_receive(:message).with(hash_not_including(:key, :key2 => :val2))
#
# Passes if the argument is a hash that doesn't include the specified key(s) or key/value
def hash_not_including(*args)
HashNotIncludingMatcher.new(anythingize_lonely_keys(*args))
end
Expand Down
11 changes: 7 additions & 4 deletions lib/rspec/mocks/message_expectation.rb
Expand Up @@ -63,17 +63,20 @@ def and_return(*values, &return_block)
@return_block = block_given? ? return_block : lambda { value }
end

# :call-seq:
# and_raise()
# and_raise(Exception) #any exception class
# and_raise(exception) #any exception object
# Tells the mock or stub to raise an exception when the message
# is received.
#
# == Warning
#
# When you pass an exception class, the MessageExpectation will
# raise an instance of it, creating it with +new+. If the exception
# class initializer requires any parameters, you must pass in an
# instance and not the class.
#
# == Examples
# and_raise()
# and_raise(Exception) #any exception class
# and_raise(exception) #any exception object
def and_raise(exception=Exception)
@exception_to_raise = exception
end
Expand Down
12 changes: 5 additions & 7 deletions lib/rspec/mocks/methods.rb
Expand Up @@ -24,15 +24,13 @@ def unstub(sym)
alias_method :stub!, :stub
alias_method :unstub!, :unstub

# :call-seq:
# double.stub_chain("foo.bar") { :baz }
# double.stub_chain(:foo, :bar) { :baz }
#
# Stubs a chain of methods. Especially useful with fluent and/or
# composable interfaces.
#
# == Examples
#
# double.stub_chain("foo.bar") { :baz }
# double.stub_chain(:foo, :bar) { :baz }
# Article.stub_chain("recent.published") { [Article.new] }
def stub_chain(*chain, &blk)
chain, blk = format_chain(*chain, &blk)
Expand All @@ -50,15 +48,15 @@ def stub_chain(*chain, &blk)
end
end

def received_message?(sym, *args, &block) #:nodoc:
def received_message?(sym, *args, &block)
__mock_proxy.received_message?(sym.to_sym, *args, &block)
end

def rspec_verify #:nodoc:
def rspec_verify
__mock_proxy.verify
end

def rspec_reset #:nodoc:
def rspec_reset
__mock_proxy.reset
end

Expand Down
6 changes: 3 additions & 3 deletions lib/rspec/mocks/proxy.rb
Expand Up @@ -45,11 +45,11 @@ def as_null_object
@object
end

def already_proxied_respond_to # :nodoc:
def already_proxied_respond_to
@already_proxied_respond_to = true
end

def already_proxied_respond_to? # :nodoc:
def already_proxied_respond_to?
@already_proxied_respond_to
end

Expand All @@ -69,7 +69,7 @@ def remove_stub(method_name)
method_double[method_name].remove_stub
end

def verify #:nodoc:
def verify
method_doubles.each {|d| d.verify}
ensure
reset
Expand Down
6 changes: 3 additions & 3 deletions lib/rspec/mocks/version.rb
@@ -1,6 +1,6 @@
module RSpec # :nodoc:
module Mocks # :nodoc:
module Version # :nodoc:
module RSpec
module Mocks
module Version
STRING = '2.7.0.rc1'
end
end
Expand Down

0 comments on commit f646743

Please sign in to comment.