/usr/share/doc/ruby-rspec-mocks/features/old_syntax/stub.feature is in ruby-rspec-mocks 3.5.0c3e0m0s0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | @allow-old-syntax
Feature: `stub`
`stub` is the old way to [allow messages](../basics/allowing-messages) but carries the baggage of a
global monkey patch on all objects. It supports the same fluent
interface for [setting constraints](../setting-constraints) and [configuring responses](../configuring-responses). You can also pass `stub` a hash
of message/return-value pairs, which acts like `allow(obj).to receive_messages(hash)`,
but does not support further customization through the fluent interface.
Background:
Given a file named "spec/spec_helper.rb" with:
"""ruby
RSpec.configure do |config|
config.mock_with :rspec do |mocks|
mocks.syntax = :should
end
end
"""
And a file named ".rspec" with:
"""
--require spec_helper
"""
Scenario: Stub a method
Given a file named "spec/stub_spec.rb" with:
"""ruby
RSpec.describe "Stubbing a method" do
it "configures how the object responds" do
dbl = double
dbl.stub(:foo).and_return(13)
expect(dbl.foo).to eq(13)
end
end
"""
When I run `rspec spec/stub_spec.rb`
Then the examples should all pass
Scenario: Stub multiple methods by passing a hash
Given a file named "spec/stub_multiple_methods_spec.rb" with:
"""ruby
RSpec.describe "Stubbing multiple methods" do
it "stubs each named method with the given return value" do
dbl = double
dbl.stub(:foo => 13, :bar => 10)
expect(dbl.foo).to eq(13)
expect(dbl.bar).to eq(10)
end
end
"""
When I run `rspec spec/stub_multiple_methods_spec.rb`
Then the examples should all pass
|