Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: rspec/rspec-mocks
...
head fork: rspec/rspec-mocks
Checking mergeability… Don't worry, you can still create the pull request.
  • 4 commits
  • 4 files changed
  • 0 commit comments
  • 2 contributors
Commits on Jun 25, 2012
@myronmarston myronmarston Cleanup whitespace.
(Actually, I'm mostly doing this just to trigger a travis build. A
recent change in rspec-expectations[1] broke the rspec-mocks
travis build, and now that it's fixed[2], I want to see that the
rspec-mocks build is passing.  I figured I may as well make a useful
but non functional change while I'm at it, though).

[1] rspec/rspec-expectations@4024344#commitcomment-1496381
[2] rspec/rspec-expectations@a3e2839
28b284d
Commits on Jun 27, 2012
@amarshall amarshall Raise RuntimeError instead by default in and_raise to match Ruby default dc5e1a7
@myronmarston myronmarston Merge pull request #156 from amarshall/master
Raise RuntimeError instead of Exception by default in and_raise to match Ruby's default
c3539b9
@myronmarston myronmarston Update changelog. aa179ed
View
2  Changelog.md
@@ -19,6 +19,8 @@ Bug fixes
as an integer (`"%i" % double.as_null_object`). (Myron Marston)
* Fix `should_receive` so that null object behavior (e.g. returning
self) is preserved if no implementation is given (Myron Marston).
+* Fix `and_raise` so that it raises `RuntimeError` rather than
+ `Exception` by default, just like ruby does. (Andrew Marshall)
### 2.10.1 / 2012-05-05
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.10.0...v2.10.1)
View
34 lib/rspec/mocks/argument_matchers.rb
@@ -66,7 +66,7 @@ def description
"hash_including(#{@expected.inspect.sub(/^\{/,"").sub(/\}$/,"")})"
end
end
-
+
class HashExcludingMatcher
def initialize(expected)
@expected = expected
@@ -82,7 +82,7 @@ def description
"hash_not_including(#{@expected.inspect.sub(/^\{/,"").sub(/\}$/,"")})"
end
end
-
+
class DuckTypeMatcher
def initialize(*methods_to_respond_to)
@methods_to_respond_to = methods_to_respond_to
@@ -112,22 +112,22 @@ def ==(expected)
@given == expected
end
end
-
+
class InstanceOf
def initialize(klass)
@klass = klass
end
-
+
def ==(actual)
actual.instance_of?(@klass)
end
end
-
+
class KindOf
def initialize(klass)
@klass = klass
end
-
+
def ==(actual)
actual.kind_of?(@klass)
end
@@ -142,7 +142,7 @@ def ==(actual)
def any_args
AnyArgsMatcher.new
end
-
+
# Matches any argument at all.
#
# @example
@@ -151,7 +151,7 @@ def any_args
def anything
AnyArgMatcher.new(nil)
end
-
+
# Matches no arguments.
#
# @example
@@ -160,7 +160,7 @@ def anything
def no_args
NoArgsMatcher.new
end
-
+
# Matches if the actual argument responds to the specified messages.
#
# @example
@@ -179,7 +179,7 @@ def duck_type(*args)
def boolean
BooleanMatcher.new(nil)
end
-
+
# Matches a hash that includes the specified key(s) or key/value pairs.
# Ignores any additional keys.
#
@@ -191,7 +191,7 @@ def boolean
def hash_including(*args)
HashIncludingMatcher.new(anythingize_lonely_keys(*args))
end
-
+
# Matches a hash that doesn't include the specified key(s) or key/value.
#
# @example
@@ -204,7 +204,7 @@ def hash_excluding(*args)
end
alias_method :hash_not_including, :hash_excluding
-
+
# Matches if `arg.instance_of?(klass)`
#
# @example
@@ -213,9 +213,9 @@ def hash_excluding(*args)
def instance_of(klass)
InstanceOf.new(klass)
end
-
+
alias_method :an_instance_of, :instance_of
-
+
# Matches if `arg.kind_of?(klass)`
# @example
#
@@ -223,11 +223,11 @@ def instance_of(klass)
def kind_of(klass)
KindOf.new(klass)
end
-
+
alias_method :a_kind_of, :kind_of
-
+
private
-
+
def anythingize_lonely_keys(*args)
hash = args.last.class == Hash ? args.delete_at(-1) : {}
args.each { | arg | hash[arg] = anything }
View
2  lib/rspec/mocks/message_expectation.rb
@@ -115,7 +115,7 @@ def and_return(*values, &implementation)
# car.stub(:go).and_raise
# car.stub(:go).and_raise(OutOfGas)
# car.stub(:go).and_raise(OutOfGas.new(2, :oz))
- def and_raise(exception=Exception)
+ def and_raise(exception=RuntimeError)
@exception_to_raise = exception
end
View
7 spec/rspec/mocks/mock_spec.rb
@@ -215,7 +215,12 @@ def @double.method_with_default_argument(arg={}); end
end
it "raises when told to" do
- @double.should_receive(:something).and_raise(RuntimeError)
+ @double.should_receive(:something).and_raise(StandardError)
+ expect { @double.something }.to raise_error(StandardError)
+ end
+
+ it "raises RuntimeError by default" do
+ @double.should_receive(:something).and_raise
expect { @double.something }.to raise_error(RuntimeError)
end

No commit comments for this range

Something went wrong with that request. Please try again.