Skip to content
This repository

Add new feature for receive_counts on mocks #77

Merged
merged 2 commits into from over 2 years ago

2 participants

Attila Domokos David Chelimsky
Attila Domokos

Adding a new cucumber feature to cover:

  • .once
  • .twice
  • exactly(n).times
  • at_least(:once)
  • at_least(n).times
  • at_most(:once)
  • at_most(n).times
Attila Domokos

Any update on this pull request?

features/message_expectations/receive_counts.feature
... ...
@@ -0,0 +1,212 @@
  1
+Feature: receive counts
  2
+
  3
+  The implicit expectation is that the message passed to should_receive()
4
David Chelimsky Owner

The implicit expectation is one time, and can be overridden explicitly.

Should I remove this comment? I just copied it from the old rspec site.

David Chelimsky Owner

So is this whole thing just copied over from rspec-1?

Line 3 and 4 did. I'll remove it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Attila Domokos

Removed the incorrect description. Is there anything else I should change?

David Chelimsky dchelimsky merged commit 8d35db6 into from
David Chelimsky dchelimsky closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 1 author.

Aug 26, 2011
Attila Domokos Add new feature for receive_counts on mocks 52daacc
Sep 01, 2011
Attila Domokos Removing incorrect description 14c52b9
This page is out of date. Refresh to see the latest.
209  features/message_expectations/receive_counts.feature
... ...
@@ -0,0 +1,209 @@
  1
+Feature: receive counts
  2
+
  3
+  Scenario: expect a message once
  4
+    Given a file named "spec/account_spec.rb" with:
  5
+      """
  6
+      class Account
  7
+        attr_accessor :logger
  8
+
  9
+        def open
  10
+          logger.account_opened
  11
+        end
  12
+      end
  13
+
  14
+      describe Account do
  15
+        context "when opened" do
  16
+          it "logger#account_opened was called once" do
  17
+            logger = double("logger")
  18
+            account = Account.new
  19
+            account.logger = logger
  20
+
  21
+            logger.should_receive(:account_opened).once
  22
+
  23
+            account.open
  24
+          end
  25
+        end
  26
+      end
  27
+      """
  28
+    When I run `rspec spec/account_spec.rb`
  29
+    Then the output should contain "1 example, 0 failures"
  30
+
  31
+  Scenario: expect a message twice
  32
+    Given a file named "spec/account_spec.rb" with:
  33
+      """
  34
+      class Account
  35
+        attr_accessor :logger
  36
+
  37
+        def open
  38
+          logger.account_opened
  39
+        end
  40
+      end
  41
+
  42
+      describe Account do
  43
+        context "when opened" do
  44
+          it "logger#account_opened was called once" do
  45
+            logger = double("logger")
  46
+            account = Account.new
  47
+            account.logger = logger
  48
+
  49
+            logger.should_receive(:account_opened).twice
  50
+
  51
+            account.open
  52
+            account.open
  53
+          end
  54
+        end
  55
+      end
  56
+      """
  57
+    When I run `rspec spec/account_spec.rb`
  58
+    Then the output should contain "1 example, 0 failures"
  59
+
  60
+  Scenario: expect a message 3 times
  61
+    Given a file named "spec/account_spec.rb" with:
  62
+      """
  63
+      class Account
  64
+        attr_accessor :logger
  65
+
  66
+        def open
  67
+          logger.account_opened
  68
+        end
  69
+      end
  70
+
  71
+      describe Account do
  72
+        context "when opened" do
  73
+          it "logger#account_opened was called once" do
  74
+            logger = double("logger")
  75
+            account = Account.new
  76
+            account.logger = logger
  77
+
  78
+            logger.should_receive(:account_opened).exactly(3).times
  79
+
  80
+            account.open
  81
+            account.open
  82
+            account.open
  83
+          end
  84
+        end
  85
+      end
  86
+      """
  87
+    When I run `rspec spec/account_spec.rb`
  88
+    Then the output should contain "1 example, 0 failures"
  89
+
  90
+  Scenario: expect a message at least (:once)
  91
+    Given a file named "spec/account_spec.rb" with:
  92
+      """
  93
+      class Account
  94
+        attr_accessor :logger
  95
+
  96
+        def open
  97
+          logger.account_opened
  98
+        end
  99
+      end
  100
+
  101
+      describe Account do
  102
+        context "when opened" do
  103
+          it "logger#account_opened was called once" do
  104
+            logger = double("logger")
  105
+            account = Account.new
  106
+            account.logger = logger
  107
+
  108
+            logger.should_receive(:account_opened).at_least(:once)
  109
+
  110
+            account.open
  111
+          end
  112
+        end
  113
+      end
  114
+      """
  115
+    When I run `rspec spec/account_spec.rb`
  116
+    Then the output should contain "1 example, 0 failures"
  117
+
  118
+
  119
+  Scenario: expect a message at least (n) times
  120
+    Given a file named "spec/account_spec.rb" with:
  121
+      """
  122
+      class Account
  123
+        attr_accessor :logger
  124
+
  125
+        def open
  126
+          logger.account_opened
  127
+        end
  128
+      end
  129
+
  130
+      describe Account do
  131
+        context "when opened" do
  132
+          it "logger#account_opened was called once" do
  133
+            logger = double("logger")
  134
+            account = Account.new
  135
+            account.logger = logger
  136
+
  137
+            logger.should_receive(:account_opened).at_least(3).times
  138
+
  139
+            # Note that I am calling method under test 4 times
  140
+            # and I specified it to be called at least 3 times
  141
+            account.open
  142
+            account.open
  143
+            account.open
  144
+            account.open
  145
+          end
  146
+        end
  147
+      end
  148
+      """
  149
+    When I run `rspec spec/account_spec.rb`
  150
+    Then the output should contain "1 example, 0 failures"
  151
+
  152
+  Scenario: expect a message at most (:once)
  153
+    Given a file named "spec/account_spec.rb" with:
  154
+      """
  155
+      class Account
  156
+        attr_accessor :logger
  157
+
  158
+        def open
  159
+          logger.account_opened
  160
+        end
  161
+      end
  162
+
  163
+      describe Account do
  164
+        context "when opened" do
  165
+          it "logger#account_opened was called once" do
  166
+            logger = double("logger")
  167
+            account = Account.new
  168
+            account.logger = logger
  169
+
  170
+            logger.should_receive(:account_opened).at_most(:once)
  171
+
  172
+            account.open
  173
+            account.open
  174
+          end
  175
+        end
  176
+      end
  177
+      """
  178
+    When I run `rspec spec/account_spec.rb`
  179
+    Then the output should contain "expected: 1 time"
  180
+     And the output should contain "received: 2 times"
  181
+
  182
+  Scenario: expect a message at most (n) times
  183
+    Given a file named "spec/account_spec.rb" with:
  184
+      """
  185
+      class Account
  186
+        attr_accessor :logger
  187
+
  188
+        def open
  189
+          logger.account_opened
  190
+        end
  191
+      end
  192
+
  193
+      describe Account do
  194
+        context "when opened" do
  195
+          it "logger#account_opened was called once" do
  196
+            logger = double("logger")
  197
+            account = Account.new
  198
+            account.logger = logger
  199
+
  200
+            logger.should_receive(:account_opened).at_most(2).times
  201
+
  202
+            account.open
  203
+            account.open
  204
+          end
  205
+        end
  206
+      end
  207
+      """
  208
+    When I run `rspec spec/account_spec.rb`
  209
+    Then the output should contain "1 example, 0 failures"
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.