Skip to content

Commit

Permalink
Use Ruby v1.9 Hash syntax in docs
Browse files Browse the repository at this point in the history
We updated the code to use Ruby v1.9 Hash syntax in #598. This brings
the docs into line with that change.

Fixes #625.
  • Loading branch information
floehopper committed Nov 12, 2023
1 parent e7134d5 commit 6de2072
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class MiscExampleTest < Test::Unit::TestCase
end

def test_stubbing_instance_methods_on_real_objects
prices = [stub(:pence => 1000), stub(:pence => 2000)]
prices = [stub(pence: 1000), stub(pence: 2000)]
product = Product.new
product.stubs(:prices).returns(prices)
assert_equal [1000, 2000], product.prices.collect {|p| p.pence}
Expand All @@ -170,7 +170,7 @@ class MiscExampleTest < Test::Unit::TestCase
end

def test_shortcuts
object = stub(:method1 => :result1, :method2 => :result2)
object = stub(method1: :result1, method2: :result2)
assert_equal :result1, object.method1
assert_equal :result2, object.method2
end
Expand Down
6 changes: 3 additions & 3 deletions lib/mocha/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def self.extended(mod)
#
# @example Using expected_methods_vs_return_values Hash to setup expectations.
# def test_motor_starts_and_stops
# motor = mock('motor', :start => true, :stop => true)
# motor = mock('motor', start: true, stop: true)
# assert motor.start
# assert motor.stop
# # an error will be raised unless both Motor#start and Motor#stop have been called
Expand Down Expand Up @@ -88,7 +88,7 @@ def mock(*arguments)
#
# @example Using stubbed_methods_vs_return_values Hash to setup stubbed methods.
# def test_motor_starts_and_stops
# motor = stub('motor', :start => true, :stop => true)
# motor = stub('motor', start: true, stop: true)
# assert motor.start
# assert motor.stop
# # an error will not be raised even if either Motor#start or Motor#stop has not been called
Expand All @@ -115,7 +115,7 @@ def stub(*arguments)
#
# @example Ignore invocations of irrelevant methods.
# def test_motor_stops
# motor = stub_everything('motor', :stop => true)
# motor = stub_everything('motor', stop: true)
# assert_nil motor.irrelevant_method_1 # => no error raised
# assert_nil motor.irrelevant_method_2 # => no error raised
# assert motor.stop
Expand Down
4 changes: 2 additions & 2 deletions lib/mocha/mock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class Mock
#
# @example Setup multiple expectations using +expected_methods_vs_return_values+.
# object = mock()
# object.expects(:expected_method_one => :result_one, :expected_method_two => :result_two)
# object.expects(expected_method_one: :result_one, expected_method_two: :result_two)
#
# # is exactly equivalent to
#
Expand Down Expand Up @@ -138,7 +138,7 @@ def expects(method_name_or_hash, backtrace = nil)
#
# @example Setup multiple expectations using +stubbed_methods_vs_return_values+.
# object = mock()
# object.stubs(:stubbed_method_one => :result_one, :stubbed_method_two => :result_two)
# object.stubs(stubbed_method_one: :result_one, stubbed_method_two: :result_two)
#
# # is exactly equivalent to
#
Expand Down
4 changes: 2 additions & 2 deletions lib/mocha/object_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def stubba_class
#
# @example Setting up multiple expectations on a non-mock object.
# product = Product.new
# product.expects(:valid? => true, :save => true)
# product.expects(valid?: true, save: true)
#
# # exactly equivalent to
#
Expand Down Expand Up @@ -108,7 +108,7 @@ def expects(expected_methods_vs_return_values)
#
# @example Setting up multiple stubbed methods on a non-mock object.
# product = Product.new
# product.stubs(:valid? => true, :save => true)
# product.stubs(valid?: true, save: true)
#
# # exactly equivalent to
#
Expand Down
8 changes: 4 additions & 4 deletions lib/mocha/parameter_matchers/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ def to_matcher(_expectation = nil)
# @example Alternative ways to combine matchers with a logical AND.
# object = mock()
# object.expects(:run).with(all_of(has_key(:foo), has_key(:bar)))
# object.run(:foo => 'foovalue', :bar => 'barvalue')
# object.run(foo: 'foovalue', bar: 'barvalue')
#
# # is exactly equivalent to
#
# object.expects(:run).with(has_key(:foo) & has_key(:bar))
# object.run(:foo => 'foovalue', :bar => 'barvalue)
# object.run(foo: 'foovalue', bar: 'barvalue)
def &(other)
AllOf.new(self, other)
end
Expand All @@ -45,12 +45,12 @@ def &(other)
# @example Alternative ways to combine matchers with a logical OR.
# object = mock()
# object.expects(:run).with(any_of(has_key(:foo), has_key(:bar)))
# object.run(:foo => 'foovalue')
# object.run(foo: 'foovalue')
#
# # is exactly equivalent to
#
# object.expects(:run).with(has_key(:foo) | has_key(:bar))
# object.run(:foo => 'foovalue')
# object.run(foo: 'foovalue')
#
# @example Using an explicit {Equals} matcher in combination with {#|}.
# object.expects(:run).with(equals(1) | equals(2))
Expand Down
6 changes: 3 additions & 3 deletions lib/mocha/parameter_matchers/includes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module ParameterMatchers
# @example Actual parameter includes item which matches nested matcher.
# object = mock()
# object.expects(:method_1).with(includes(has_key(:key)))
# object.method_1(['foo', 'bar', {:key => 'baz'}])
# object.method_1(['foo', 'bar', {key: 'baz'}])
# # no error raised
#
# @example Actual parameter does not include item matching nested matcher.
Expand All @@ -44,11 +44,11 @@ module ParameterMatchers
# @example Actual parameter is a Hash including the given key.
# object = mock()
# object.expects(:method_1).with(includes(:bar))
# object.method_1({:foo => 1, :bar => 2})
# object.method_1({foo: 1, bar: 2})
# # no error raised
#
# @example Actual parameter is a Hash without the given key.
# object.method_1({:foo => 1, :baz => 2})
# object.method_1({foo: 1, baz: 2})
# # error raised, because hash does not include key 'bar'
#
# @example Actual parameter is a Hash with a key matching the given matcher.
Expand Down
2 changes: 1 addition & 1 deletion lib/mocha/parameter_matchers/responds_with.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module ParameterMatchers
#
# @example Actual parameter responds with "FOO" when :upcase is invoked and "oof" when :reverse is invoked.
# object = mock()
# object.expects(:method_1).with(responds_with(:upcase => "FOO", :reverse => "oof"))
# object.expects(:method_1).with(responds_with(upcase: "FOO", reverse: "oof"))
# object.method_1("foo")
# # no error raised, because "foo".upcase == "FOO" and "foo".reverse == "oof"
def responds_with(*options)
Expand Down

0 comments on commit 6de2072

Please sign in to comment.