File: expect_any_instance_of.feature

package info (click to toggle)
ruby-rspec-mocks 2.14.3-1~bpo70%2B1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy-backports
  • size: 868 kB
  • sloc: ruby: 8,131; makefile: 4
file content (27 lines) | stat: -rw-r--r-- 1,042 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
27
Feature: expect a message on any instance of a class

  Use `expect_any_instance_of(Class).to receive` to set an expectation that one
  (and only one) instance of a class receives a message before the example is
  completed. The spec will fail if no instance receives a message.

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

        it "verifies that one instance of the class receives the message" do
          o = Object.new
          expect(o.foo).to eq(:return_value)
        end

        it "fails unless an instance receives that message" do
          o = Object.new
        end
      end
      """
    When I run `rspec example_spec.rb`
    Then the output should contain "2 examples, 1 failure"
    And the output should contain "1) expect_any_instance_of fails unless an instance receives that message"