File: spy_pure_mock_method.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 (76 lines) | stat: -rw-r--r-- 2,795 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
Feature: Spy on a stubbed method on a pure mock

  You can use `have_received` to verify that a stubbed method was invoked,
  rather than setting an expectation for it to be invoked beforehand.

  Scenario: verify a stubbed method
    Given a file named "verified_spy_spec.rb" with:
      """ruby
      describe "have_received" do
        it "passes when the expectation is met" do
          invitation = double('invitation', :deliver => true)
          invitation.deliver
          invitation.should have_received(:deliver)
        end
      end
      """
    When I run `rspec verified_spy_spec.rb`
    Then the examples should all pass

  Scenario: verify a stubbed method with message expectations
    Given a file named "verified_message_expectations_spec.rb" with:
      """ruby
      describe "have_received" do
        it "passes when the expectation is met" do
          invitation = double('invitation', :deliver => true)
          2.times { invitation.deliver(:expected, :arguments) }
          invitation.should have_received(:deliver).
            with(:expected, :arguments).
            twice
        end
      end
      """
    When I run `rspec verified_message_expectations_spec.rb`
    Then the examples should all pass

  Scenario: fail to verify a stubbed method
    Given a file named "failed_spy_spec.rb" with:
      """ruby
      describe "have_received" do
        it "fails when the expectation is not met" do
          invitation = double('invitation', :deliver => true)
          invitation.should have_received(:deliver)
        end
      end
      """
    When I run `rspec failed_spy_spec.rb`
    Then the output should contain "expected: 1 time"
     And the output should contain "received: 0 times"

  Scenario: fail to verify message expectations
    Given a file named "failed_message_expectations_spec.rb" with:
      """ruby
      describe "have_received" do
        it "fails when the arguments are different" do
          invitation = double('invitation', :deliver => true)
          invitation.deliver(:unexpected)
          invitation.should have_received(:deliver).with(:expected, :arguments)
        end
      end
      """
    When I run `rspec failed_message_expectations_spec.rb`
    Then the output should contain "expected: (:expected, :arguments)"
    And the output should contain "got: (:unexpected)"

  Scenario: generate a spy message
    Given a file named "spy_message_spec.rb" with:
      """ruby
      describe "have_received" do
      subject(:invitation) { double('invitation', :deliver => true) }
        before { invitation.deliver }

        it { should have_received(:deliver) }
      end
      """
    When I run `rspec --format documentation spy_message_spec.rb`
    Then the output should contain "should have received deliver"