File: allow_any_instance_of.feature

package info (click to toggle)
ruby-rspec-mocks 2.14.5-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 868 kB
  • ctags: 725
  • sloc: ruby: 8,227; makefile: 4
file content (26 lines) | stat: -rw-r--r-- 888 bytes parent folder | download | duplicates (2)
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
Feature: allow a message on any instance of a class

  Use `allow_any_instance_of(Class).to receive` when you want to configure how
  instances of the given class respond to a message without setting an
  expectation that the message will be received.

  Scenario: allowing a message on any instance of a class
    Given a file named "example_spec.rb" with:
      """ruby
      describe "any_instance.should_receive" do
        before do
          allow_any_instance_of(Object).to receive(:foo).and_return(:return_value)
        end

        it "allows any instance of the class to receive the message" do
          o = Object.new
          expect(o.foo).to eq(:return_value)
        end

        it "passes even if no instances receive that message" do
          o = Object.new
        end
      end
      """
    When I run `rspec example_spec.rb`
    Then the examples should all pass