rspec-mocks 3.0.0.beta2 → 3.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/Changelog.md +104 -36
  5. data/README.md +35 -4
  6. data/lib/rspec/mocks.rb +52 -13
  7. data/lib/rspec/mocks/any_instance.rb +10 -0
  8. data/lib/rspec/mocks/any_instance/chain.rb +17 -0
  9. data/lib/rspec/mocks/any_instance/expect_chain_chain.rb +1 -1
  10. data/lib/rspec/mocks/any_instance/expectation_chain.rb +9 -6
  11. data/lib/rspec/mocks/any_instance/message_chains.rb +10 -1
  12. data/lib/rspec/mocks/any_instance/proxy.rb +112 -0
  13. data/lib/rspec/mocks/any_instance/recorder.rb +49 -18
  14. data/lib/rspec/mocks/any_instance/stub_chain.rb +5 -3
  15. data/lib/rspec/mocks/any_instance/stub_chain_chain.rb +1 -1
  16. data/lib/rspec/mocks/argument_list_matcher.rb +5 -3
  17. data/lib/rspec/mocks/argument_matchers.rb +28 -12
  18. data/lib/rspec/mocks/configuration.rb +29 -0
  19. data/lib/rspec/mocks/error_generator.rb +2 -5
  20. data/lib/rspec/mocks/example_methods.rb +122 -13
  21. data/lib/rspec/mocks/instance_method_stasher.rb +26 -2
  22. data/lib/rspec/mocks/marshal_extension.rb +41 -0
  23. data/lib/rspec/mocks/matchers/expectation_customization.rb +20 -0
  24. data/lib/rspec/mocks/matchers/receive.rb +6 -20
  25. data/lib/rspec/mocks/matchers/receive_message_chain.rb +7 -5
  26. data/lib/rspec/mocks/matchers/receive_messages.rb +1 -2
  27. data/lib/rspec/mocks/message_chain.rb +9 -9
  28. data/lib/rspec/mocks/message_expectation.rb +6 -5
  29. data/lib/rspec/mocks/method_double.rb +67 -10
  30. data/lib/rspec/mocks/method_reference.rb +1 -1
  31. data/lib/rspec/mocks/mutate_const.rb +10 -14
  32. data/lib/rspec/mocks/object_reference.rb +7 -4
  33. data/lib/rspec/mocks/proxy.rb +95 -8
  34. data/lib/rspec/mocks/space.rb +58 -9
  35. data/lib/rspec/mocks/syntax.rb +128 -210
  36. data/lib/rspec/mocks/targets.rb +6 -8
  37. data/lib/rspec/mocks/test_double.rb +16 -25
  38. data/lib/rspec/mocks/verifying_double.rb +15 -12
  39. data/lib/rspec/mocks/verifying_message_expecation.rb +3 -3
  40. data/lib/rspec/mocks/verifying_proxy.rb +23 -17
  41. data/lib/rspec/mocks/version.rb +3 -1
  42. metadata +29 -257
  43. metadata.gz.sig +0 -0
  44. data/features/README.md +0 -75
  45. data/features/Scope.md +0 -17
  46. data/features/Upgrade.md +0 -22
  47. data/features/argument_matchers/README.md +0 -27
  48. data/features/argument_matchers/explicit.feature +0 -59
  49. data/features/argument_matchers/general_matchers.feature +0 -85
  50. data/features/argument_matchers/type_matchers.feature +0 -26
  51. data/features/message_expectations/README.md +0 -75
  52. data/features/message_expectations/allow_any_instance_of.feature +0 -26
  53. data/features/message_expectations/any_instance.feature +0 -43
  54. data/features/message_expectations/block_local_expectations.feature.pending +0 -55
  55. data/features/message_expectations/call_original.feature +0 -23
  56. data/features/message_expectations/expect_message_using_expect.feature +0 -107
  57. data/features/message_expectations/expect_message_using_should_receive.feature +0 -118
  58. data/features/message_expectations/message_chains_using_expect.feature +0 -49
  59. data/features/message_expectations/receive_counts.feature +0 -209
  60. data/features/message_expectations/warn_when_expectation_is_set_on_nil.feature +0 -50
  61. data/features/method_stubs/README.md +0 -77
  62. data/features/method_stubs/allow_any_instance_of.feature +0 -136
  63. data/features/method_stubs/as_null_object.feature +0 -40
  64. data/features/method_stubs/receive_message_chain.feature +0 -51
  65. data/features/method_stubs/simple_return_value_with_allow.feature +0 -44
  66. data/features/method_stubs/simple_return_value_with_stub.feature +0 -64
  67. data/features/method_stubs/stub_implementation.feature +0 -48
  68. data/features/method_stubs/to_ary.feature +0 -51
  69. data/features/mutating_constants/README.md +0 -82
  70. data/features/mutating_constants/hiding_defined_constant.feature +0 -64
  71. data/features/mutating_constants/stub_defined_constant.feature +0 -78
  72. data/features/mutating_constants/stub_undefined_constant.feature +0 -50
  73. data/features/outside_rspec/standalone.feature +0 -33
  74. data/features/spies/spy_partial_mock_method.feature +0 -34
  75. data/features/spies/spy_pure_mock_method.feature +0 -76
  76. data/features/spies/spy_unstubbed_method.feature +0 -18
  77. data/features/step_definitions/additional_cli_steps.rb +0 -11
  78. data/features/support/env.rb +0 -22
  79. data/features/support/rubinius.rb +0 -6
  80. data/features/test_frameworks/test_unit.feature +0 -54
  81. data/features/verifying_doubles/README.md +0 -17
  82. data/features/verifying_doubles/class_doubles.feature +0 -73
  83. data/features/verifying_doubles/dynamic_classes.feature +0 -71
  84. data/features/verifying_doubles/instance_doubles.feature +0 -103
  85. data/features/verifying_doubles/object_doubles.feature +0 -65
  86. data/features/verifying_doubles/partial_doubles.feature +0 -34
  87. data/lib/rspec/mocks/extensions/marshal.rb +0 -17
  88. data/lib/rspec/mocks/framework.rb +0 -35
  89. data/lib/rspec/mocks/method_signature_verifier.rb +0 -207
  90. data/lib/rspec/mocks/ruby_features.rb +0 -24
  91. data/spec/rspec/mocks/and_call_original_spec.rb +0 -268
  92. data/spec/rspec/mocks/and_return_spec.rb +0 -23
  93. data/spec/rspec/mocks/and_yield_spec.rb +0 -126
  94. data/spec/rspec/mocks/any_instance/message_chains_spec.rb +0 -41
  95. data/spec/rspec/mocks/any_instance_spec.rb +0 -1045
  96. data/spec/rspec/mocks/array_including_matcher_spec.rb +0 -41
  97. data/spec/rspec/mocks/at_least_spec.rb +0 -123
  98. data/spec/rspec/mocks/at_most_spec.rb +0 -90
  99. data/spec/rspec/mocks/before_all_spec.rb +0 -132
  100. data/spec/rspec/mocks/block_return_value_spec.rb +0 -70
  101. data/spec/rspec/mocks/combining_implementation_instructions_spec.rb +0 -204
  102. data/spec/rspec/mocks/configuration_spec.rb +0 -242
  103. data/spec/rspec/mocks/double_spec.rb +0 -874
  104. data/spec/rspec/mocks/example_methods_spec.rb +0 -13
  105. data/spec/rspec/mocks/extensions/marshal_spec.rb +0 -54
  106. data/spec/rspec/mocks/failing_argument_matchers_spec.rb +0 -184
  107. data/spec/rspec/mocks/hash_excluding_matcher_spec.rb +0 -67
  108. data/spec/rspec/mocks/hash_including_matcher_spec.rb +0 -94
  109. data/spec/rspec/mocks/instance_method_stasher_spec.rb +0 -74
  110. data/spec/rspec/mocks/matchers/have_received_spec.rb +0 -347
  111. data/spec/rspec/mocks/matchers/receive_message_chain_spec.rb +0 -198
  112. data/spec/rspec/mocks/matchers/receive_messages_spec.rb +0 -140
  113. data/spec/rspec/mocks/matchers/receive_spec.rb +0 -418
  114. data/spec/rspec/mocks/method_signature_verifier_spec.rb +0 -272
  115. data/spec/rspec/mocks/methods_spec.rb +0 -26
  116. data/spec/rspec/mocks/mock_expectation_error_spec.rb +0 -22
  117. data/spec/rspec/mocks/mock_ordering_spec.rb +0 -114
  118. data/spec/rspec/mocks/multiple_return_value_spec.rb +0 -132
  119. data/spec/rspec/mocks/mutate_const_spec.rb +0 -542
  120. data/spec/rspec/mocks/nil_expectation_warning_spec.rb +0 -52
  121. data/spec/rspec/mocks/null_object_mock_spec.rb +0 -133
  122. data/spec/rspec/mocks/once_counts_spec.rb +0 -52
  123. data/spec/rspec/mocks/options_hash_spec.rb +0 -35
  124. data/spec/rspec/mocks/order_group_spec.rb +0 -27
  125. data/spec/rspec/mocks/partial_double_spec.rb +0 -308
  126. data/spec/rspec/mocks/partial_double_using_mocks_directly_spec.rb +0 -95
  127. data/spec/rspec/mocks/passing_argument_matchers_spec.rb +0 -145
  128. data/spec/rspec/mocks/precise_counts_spec.rb +0 -68
  129. data/spec/rspec/mocks/record_messages_spec.rb +0 -26
  130. data/spec/rspec/mocks/serialization_spec.rb +0 -90
  131. data/spec/rspec/mocks/space_spec.rb +0 -244
  132. data/spec/rspec/mocks/stash_spec.rb +0 -46
  133. data/spec/rspec/mocks/stub_chain_spec.rb +0 -168
  134. data/spec/rspec/mocks/stub_implementation_spec.rb +0 -81
  135. data/spec/rspec/mocks/stub_spec.rb +0 -327
  136. data/spec/rspec/mocks/stubbed_message_expectations_spec.rb +0 -58
  137. data/spec/rspec/mocks/syntax_agnostic_message_matchers_spec.rb +0 -101
  138. data/spec/rspec/mocks/syntax_spec.rb +0 -19
  139. data/spec/rspec/mocks/test_double_spec.rb +0 -49
  140. data/spec/rspec/mocks/to_ary_spec.rb +0 -54
  141. data/spec/rspec/mocks/twice_counts_spec.rb +0 -66
  142. data/spec/rspec/mocks/verifying_double_spec.rb +0 -590
  143. data/spec/rspec/mocks/verifying_message_expecation_spec.rb +0 -69
  144. data/spec/rspec/mocks_spec.rb +0 -192
  145. data/spec/spec_helper.rb +0 -121
@@ -1,55 +0,0 @@
1
- Feature: block local expectations
2
-
3
- Background:
4
- Given a file named "lib/account.rb" with:
5
- """
6
- class Account
7
- def self.create
8
- yield new
9
- end
10
-
11
- def opening_balance(amount, currency)
12
- end
13
- end
14
- """
15
-
16
- Scenario: passing example
17
- Given a file named "spec/account_spec.rb" with:
18
- """
19
- require 'account'
20
-
21
- describe "account DSL" do
22
- it "it succeeds when the block local receives the given call" do
23
- account = double("Account")
24
- Account.should_receive(:create).and_yield(account) do |account|
25
- account.should_receive(:opening_balance).with(100, :USD)
26
- end
27
- Account.create do |account|
28
- account.opening_balance 100, :USD
29
- end
30
- end
31
- end
32
- """
33
- When I run `rspec spec/account_spec.rb`
34
- Then the output should contain "1 example, 0 failures"
35
-
36
- Scenario: failing example
37
-
38
- Given a file named "spec/account_spec.rb" with:
39
- """
40
- require 'account'
41
-
42
- describe "account DSL" do
43
- it "fails when the block local does not receive the expected call" do
44
- Account.should_receive(:create).and_yield do |account|
45
- account.should_receive(:opening_balance).with(100, :USD)
46
- end
47
- Account.create do |account|
48
- # opening_balance is not called here
49
- end
50
- end
51
- end
52
- """
53
-
54
- When I run `rspec spec/account_spec.rb`
55
- Then the output should contain "1 example, 1 failure"
@@ -1,23 +0,0 @@
1
- Feature: Calling the original method
2
-
3
- You can use `and_call_original` on the fluent interface
4
- to "pass through" the received message to the original method.
5
-
6
- Scenario: expect a message
7
- Given a file named "call_original_spec.rb" with:
8
- """ruby
9
- class Addition
10
- def self.two_plus_two
11
- 4
12
- end
13
- end
14
-
15
- describe "and_call_original" do
16
- it "delegates the message to the original implementation" do
17
- expect(Addition).to receive(:two_plus_two).and_call_original
18
- expect(Addition.two_plus_two).to eq(4)
19
- end
20
- end
21
- """
22
- When I run `rspec call_original_spec.rb`
23
- Then the examples should all pass
@@ -1,107 +0,0 @@
1
- Feature: expect message using `expect`
2
-
3
- Use `expect(object).to receive(:message)` to set an expectation that
4
- `object` should receive the message `:message` before the example is
5
- completed.
6
-
7
- Note: You can use `expect_any_instance_of` when you don't have a reference
8
- to the object that receives a message in your test. For more information,
9
- see the message_expectations/expect_any_instance_of feature.
10
-
11
- Scenario: expect a message
12
- Given a file named "spec/account_spec.rb" with:
13
- """ruby
14
- require "account"
15
-
16
- describe Account do
17
- context "when closed" do
18
- it "logs an account closed message" do
19
- logger = double("logger")
20
- account = Account.new logger
21
-
22
- expect(logger).to receive(:account_closed)
23
-
24
- account.close
25
- end
26
- end
27
- end
28
- """
29
- And a file named "lib/account.rb" with:
30
- """ruby
31
- Account = Struct.new(:logger) do
32
- def close
33
- logger.account_closed
34
- end
35
- end
36
- """
37
- When I run `rspec spec/account_spec.rb`
38
- Then the output should contain "1 example, 0 failures"
39
-
40
- Scenario: expect a message with an argument
41
- Given a file named "spec/account_spec.rb" with:
42
- """ruby
43
- require "account"
44
-
45
- describe Account do
46
- context "when closed" do
47
- it "logs an account closed message" do
48
- logger = double("logger")
49
- account = Account.new logger
50
-
51
- expect(logger).to receive(:account_closed).with(account)
52
-
53
- account.close
54
- end
55
- end
56
- end
57
- """
58
- And a file named "lib/account.rb" with:
59
- """ruby
60
- Account = Struct.new(:logger) do
61
- def close
62
- logger.account_closed(self)
63
- end
64
- end
65
- """
66
- When I run `rspec spec/account_spec.rb`
67
- Then the output should contain "1 example, 0 failures"
68
-
69
- Scenario: provide a return value
70
- Given a file named "spec/message_expectation_spec.rb" with:
71
- """ruby
72
-
73
- describe "a message expectation with a return value" do
74
- context "specified in a block" do
75
- it "returns the specified value" do
76
- object = double("object")
77
- expect(object).to receive(:message) { :return_value }
78
- expect(object.message).to eq(:return_value)
79
- end
80
- end
81
-
82
- context "specified with and_return" do
83
- it "returns the specified value" do
84
- object = double("object")
85
- expect(object).to receive(:message).and_return(:return_value)
86
- expect(object.message).to eq(:return_value)
87
- end
88
- end
89
- end
90
- """
91
- When I run `rspec spec/message_expectation_spec.rb`
92
- Then the output should contain "2 examples, 0 failures"
93
-
94
- Scenario: expect a specific number of calls
95
- Given a file named "spec/message_count_spec.rb" with:
96
- """ruby
97
- describe "a message expectation with a count" do
98
- it "passes if the expected number of calls happen" do
99
- string = "hi"
100
- expect(string).to receive(:length).exactly(3).times
101
-
102
- 3.times { string.length }
103
- end
104
- end
105
- """
106
- When I run `rspec spec/message_count_spec.rb`
107
- Then the output should contain "1 example, 0 failures"
@@ -1,118 +0,0 @@
1
- Feature: expect message using `should_receive`
2
-
3
- Use `object.should_receive(:message)` to set an expectation that
4
- `object` should receive the message `:message` before the example is
5
- completed.
6
-
7
- Background:
8
- Given a file named "spec/spec_helper.rb" with:
9
- """ruby
10
- RSpec.configure do |config|
11
- config.mock_with :rspec do |mocks|
12
- mocks.syntax = :should
13
- end
14
- end
15
- """
16
-
17
- Scenario: expect a message
18
- Given a file named "spec/account_spec.rb" with:
19
- """ruby
20
- require "account"
21
- require "spec_helper"
22
-
23
- describe Account do
24
- context "when closed" do
25
- it "logs an account closed message" do
26
- logger = double("logger")
27
- account = Account.new logger
28
-
29
- logger.should_receive(:account_closed)
30
-
31
- account.close
32
- end
33
- end
34
- end
35
- """
36
- And a file named "lib/account.rb" with:
37
- """ruby
38
- Account = Struct.new(:logger) do
39
- def close
40
- logger.account_closed
41
- end
42
- end
43
- """
44
- When I run `rspec spec/account_spec.rb`
45
- Then the output should contain "1 example, 0 failures"
46
-
47
- Scenario: expect a message with an argument
48
- Given a file named "spec/account_spec.rb" with:
49
- """ruby
50
- require "account"
51
- require "spec_helper"
52
-
53
- describe Account do
54
- context "when closed" do
55
- it "logs an account closed message" do
56
- logger = double("logger")
57
- account = Account.new logger
58
-
59
- logger.should_receive(:account_closed).with(account)
60
-
61
- account.close
62
- end
63
- end
64
- end
65
- """
66
- And a file named "lib/account.rb" with:
67
- """ruby
68
- Account = Struct.new(:logger) do
69
- def close
70
- logger.account_closed(self)
71
- end
72
- end
73
- """
74
- When I run `rspec spec/account_spec.rb`
75
- Then the output should contain "1 example, 0 failures"
76
-
77
- Scenario: provide a return value
78
- Given a file named "spec/message_expectation_spec.rb" with:
79
- """ruby
80
- require "spec_helper"
81
-
82
- describe "a message expectation with a return value" do
83
- context "specified in a block" do
84
- it "returns the specified value" do
85
- object = double("object")
86
- object.should_receive(:message) { :return_value }
87
- expect(object.message).to eq(:return_value)
88
- end
89
- end
90
-
91
- context "specified with and_return" do
92
- it "returns the specified value" do
93
- object = double("object")
94
- object.should_receive(:message).and_return(:return_value)
95
- expect(object.message).to eq(:return_value)
96
- end
97
- end
98
- end
99
- """
100
- When I run `rspec spec/message_expectation_spec.rb`
101
- Then the output should contain "2 examples, 0 failures"
102
-
103
- Scenario: expect a specific number of calls
104
- Given a file named "spec/message_count_spec.rb" with:
105
- """ruby
106
- require "spec_helper"
107
-
108
- describe "a message expectation with a count" do
109
- it "passes if the expected number of calls happen" do
110
- string = "hi"
111
- string.should_receive(:length).exactly(3).times
112
-
113
- 3.times { string.length }
114
- end
115
- end
116
- """
117
- When I run `rspec spec/message_count_spec.rb`
118
- Then the output should contain "1 example, 0 failures"
@@ -1,49 +0,0 @@
1
- Feature: Message chains in the expect syntax
2
-
3
- You can use `receive_message_chain` to stub nested calls
4
- on both partial and pure mock objects.
5
-
6
- Scenario: allow a chained message
7
- Given a file named "spec/chained_messages.rb" with:
8
- """ruby
9
- describe "a chained message expectation" do
10
- it "passes if the expected number of calls happen" do
11
- d = double
12
- allow(d).to receive_message_chain(:to_a, :length)
13
-
14
- d.to_a.length
15
- end
16
- end
17
- """
18
- When I run `rspec spec/chained_messages.rb`
19
- Then the output should contain "1 example, 0 failures"
20
-
21
- Scenario: allow a chained message with a return value
22
- Given a file named "spec/chained_messages.rb" with:
23
- """ruby
24
- describe "a chained message expectation" do
25
- it "passes if the expected number of calls happen" do
26
- d = double
27
- allow(d).to receive_message_chain(:to_a, :length).and_return(3)
28
-
29
- expect(d.to_a.length).to eq(3)
30
- end
31
- end
32
- """
33
- When I run `rspec spec/chained_messages.rb`
34
- Then the output should contain "1 example, 0 failures"
35
-
36
- Scenario: expect a chained message with a return value
37
- Given a file named "spec/chained_messages.rb" with:
38
- """ruby
39
- describe "a chained message expectation" do
40
- it "passes if the expected number of calls happen" do
41
- d = double
42
- expect(d).to receive_message_chain(:to_a, :length).and_return(3)
43
-
44
- expect(d.to_a.length).to eq(3)
45
- end
46
- end
47
- """
48
- When I run `rspec spec/chained_messages.rb`
49
- Then the output should contain "1 example, 0 failures"
@@ -1,209 +0,0 @@
1
- Feature: receive counts
2
-
3
- Scenario: expect a message once
4
- Given a file named "spec/account_spec.rb" with:
5
- """ruby
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
- expect(logger).to 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
- """ruby
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
- expect(logger).to 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
- """ruby
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
- expect(logger).to 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
- """ruby
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
- expect(logger).to 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
- """ruby
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
- expect(logger).to 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
- """ruby
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
- expect(logger).to 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: at most 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
- """ruby
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
- expect(logger).to 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"