File: allowing_messages.feature

package info (click to toggle)
ruby-rspec 3.13.0c0e0m0s1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,856 kB
  • sloc: ruby: 70,868; sh: 1,423; makefile: 99
file content (35 lines) | stat: -rw-r--r-- 1,370 bytes parent folder | download | duplicates (6)
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
Feature: Allowing messages

  [Test doubles](./test-doubles) are "strict" by default -- messages that have not been specifically
  allowed or expected will trigger an error. Use `allow(...).to receive(...)` to configure
  which messages the double is allowed to receive. You can also use `allow(...).to
  receive_messages(...)` to configure allowed messages (and return values) in bulk.

  Scenario: Allowed messages return nil by default
    Given a file named "allow_message_spec.rb" with:
      """ruby
      RSpec.describe "allow" do
        it "returns nil from allowed messages" do
          dbl = double("Some Collaborator")
          allow(dbl).to receive(:foo)
          expect(dbl.foo).to be_nil
        end
      end
      """
     When I run `rspec allow_message_spec.rb`
     Then the examples should all pass

  Scenario: Messages can be allowed in bulk using `receive_messages`
    Given a file named "receive_messages_spec.rb" with:
      """ruby
      RSpec.describe "receive_messages" do
        it "configures return values for the provided messages" do
          dbl = double("Some Collaborator")
          allow(dbl).to receive_messages(:foo => 2, :bar => 3)
          expect(dbl.foo).to eq(2)
          expect(dbl.bar).to eq(3)
        end
      end
      """
     When I run `rspec receive_messages_spec.rb`
     Then the examples should all pass