rspec-mocks 2.0.0.a1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/.document +5 -0
  2. data/.gitignore +6 -0
  3. data/License.txt +22 -0
  4. data/README.markdown +8 -0
  5. data/Rakefile +50 -0
  6. data/VERSION +1 -0
  7. data/VERSION.yml +5 -0
  8. data/lib/rspec/mocks.rb +201 -0
  9. data/lib/rspec/mocks/argument_expectation.rb +51 -0
  10. data/lib/rspec/mocks/argument_matchers.rb +233 -0
  11. data/lib/rspec/mocks/error_generator.rb +81 -0
  12. data/lib/rspec/mocks/errors.rb +10 -0
  13. data/lib/rspec/mocks/extensions.rb +1 -0
  14. data/lib/rspec/mocks/extensions/object.rb +3 -0
  15. data/lib/rspec/mocks/framework.rb +15 -0
  16. data/lib/rspec/mocks/message_expectation.rb +326 -0
  17. data/lib/rspec/mocks/methods.rb +63 -0
  18. data/lib/rspec/mocks/mock.rb +65 -0
  19. data/lib/rspec/mocks/order_group.rb +29 -0
  20. data/lib/rspec/mocks/proxy.rb +230 -0
  21. data/lib/rspec/mocks/space.rb +28 -0
  22. data/lib/rspec/mocks/spec_methods.rb +39 -0
  23. data/lib/spec/mocks.rb +1 -0
  24. data/spec/rspec/mocks/any_number_of_times_spec.rb +36 -0
  25. data/spec/rspec/mocks/argument_expectation_spec.rb +23 -0
  26. data/spec/rspec/mocks/at_least_spec.rb +97 -0
  27. data/spec/rspec/mocks/at_most_spec.rb +93 -0
  28. data/spec/rspec/mocks/bug_report_10260_spec.rb +8 -0
  29. data/spec/rspec/mocks/bug_report_10263_spec.rb +27 -0
  30. data/spec/rspec/mocks/bug_report_11545_spec.rb +32 -0
  31. data/spec/rspec/mocks/bug_report_15719_spec.rb +29 -0
  32. data/spec/rspec/mocks/bug_report_496_spec.rb +17 -0
  33. data/spec/rspec/mocks/bug_report_600_spec.rb +22 -0
  34. data/spec/rspec/mocks/bug_report_7611_spec.rb +19 -0
  35. data/spec/rspec/mocks/bug_report_7805_spec.rb +22 -0
  36. data/spec/rspec/mocks/bug_report_8165_spec.rb +31 -0
  37. data/spec/rspec/mocks/bug_report_8302_spec.rb +26 -0
  38. data/spec/rspec/mocks/bug_report_830_spec.rb +21 -0
  39. data/spec/rspec/mocks/failing_argument_matchers_spec.rb +95 -0
  40. data/spec/rspec/mocks/hash_including_matcher_spec.rb +90 -0
  41. data/spec/rspec/mocks/hash_not_including_matcher_spec.rb +67 -0
  42. data/spec/rspec/mocks/mock_ordering_spec.rb +94 -0
  43. data/spec/rspec/mocks/mock_space_spec.rb +54 -0
  44. data/spec/rspec/mocks/mock_spec.rb +583 -0
  45. data/spec/rspec/mocks/multiple_return_value_spec.rb +113 -0
  46. data/spec/rspec/mocks/nil_expectation_warning_spec.rb +63 -0
  47. data/spec/rspec/mocks/null_object_mock_spec.rb +54 -0
  48. data/spec/rspec/mocks/once_counts_spec.rb +53 -0
  49. data/spec/rspec/mocks/options_hash_spec.rb +35 -0
  50. data/spec/rspec/mocks/partial_mock_spec.rb +164 -0
  51. data/spec/rspec/mocks/partial_mock_using_mocks_directly_spec.rb +66 -0
  52. data/spec/rspec/mocks/passing_argument_matchers_spec.rb +145 -0
  53. data/spec/rspec/mocks/precise_counts_spec.rb +52 -0
  54. data/spec/rspec/mocks/record_messages_spec.rb +26 -0
  55. data/spec/rspec/mocks/stub_chain_spec.rb +34 -0
  56. data/spec/rspec/mocks/stub_implementation_spec.rb +31 -0
  57. data/spec/rspec/mocks/stub_spec.rb +198 -0
  58. data/spec/rspec/mocks/stubbed_message_expectations_spec.rb +26 -0
  59. data/spec/rspec/mocks/twice_counts_spec.rb +67 -0
  60. data/spec/spec_helper.rb +52 -0
  61. data/spec/support/macros.rb +29 -0
  62. metadata +172 -0
@@ -0,0 +1,26 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
+
3
+ module Rspec
4
+ module Mocks
5
+ describe "Example with stubbed and then called message" do
6
+ it "fails if the message is expected and then subsequently not called again" do
7
+ mock_obj = mock("mock", :msg => nil)
8
+ mock_obj.msg
9
+ mock_obj.should_receive(:msg)
10
+ lambda { mock_obj.rspec_verify }.should raise_error(Rspec::Mocks::MockExpectationError)
11
+ end
12
+
13
+ it "outputs arguments of all similar calls" do
14
+ m = mock('mock', :foo => true)
15
+ m.should_receive(:foo).with('first')
16
+ m.foo('second')
17
+ m.foo('third')
18
+ lambda do
19
+ m.rspec_verify
20
+ end.should raise_error(%q|Mock 'mock' expected :foo with ("first") but received it with (["second"], ["third"])|)
21
+ m.rspec_reset
22
+ end
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,67 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
+
3
+ module Rspec
4
+ module Mocks
5
+ describe "TwiceCounts" do
6
+ before(:each) do
7
+ @mock = mock("test mock")
8
+ end
9
+
10
+ it "twice should fail when call count is higher than expected" do
11
+ @mock.should_receive(:random_call).twice
12
+ @mock.random_call
13
+ @mock.random_call
14
+ @mock.random_call
15
+ lambda do
16
+ @mock.rspec_verify
17
+ end.should raise_error(MockExpectationError)
18
+ end
19
+
20
+ it "twice should fail when call count is lower than expected" do
21
+ @mock.should_receive(:random_call).twice
22
+ @mock.random_call
23
+ lambda do
24
+ @mock.rspec_verify
25
+ end.should raise_error(MockExpectationError)
26
+ end
27
+
28
+ it "twice should fail when called twice with wrong args on the first call" do
29
+ @mock.should_receive(:random_call).twice.with("1", 1)
30
+ lambda do
31
+ @mock.random_call(1, "1")
32
+ end.should raise_error(MockExpectationError)
33
+ @mock.rspec_reset
34
+ end
35
+
36
+ it "twice should fail when called twice with wrong args on the second call" do
37
+ @mock.should_receive(:random_call).twice.with("1", 1)
38
+ @mock.random_call("1", 1)
39
+ lambda do
40
+ @mock.random_call(1, "1")
41
+ end.should raise_error(MockExpectationError)
42
+ @mock.rspec_reset
43
+ end
44
+
45
+ it "twice should pass when called twice" do
46
+ @mock.should_receive(:random_call).twice
47
+ @mock.random_call
48
+ @mock.random_call
49
+ @mock.rspec_verify
50
+ end
51
+
52
+ it "twice should pass when called twice with specified args" do
53
+ @mock.should_receive(:random_call).twice.with("1", 1)
54
+ @mock.random_call("1", 1)
55
+ @mock.random_call("1", 1)
56
+ @mock.rspec_verify
57
+ end
58
+
59
+ it "twice should pass when called twice with unspecified args" do
60
+ @mock.should_receive(:random_call).twice
61
+ @mock.random_call("1")
62
+ @mock.random_call(1)
63
+ @mock.rspec_verify
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,52 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '/../../core/lib'))
2
+ require 'rspec/core'
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '/../lib'))
4
+ require 'rspec/mocks'
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '/../../expectations/lib'))
6
+ require 'rspec/expectations'
7
+
8
+ module Macros
9
+ def treats_method_missing_as_private(options = {:noop => true, :subject => nil})
10
+ it "should have method_missing as private" do
11
+ with_ruby 1.8 do
12
+ self.class.describes.private_instance_methods.should include("method_missing")
13
+ end
14
+ with_ruby 1.9 do
15
+ self.class.describes.private_instance_methods.should include(:method_missing)
16
+ end
17
+ end
18
+
19
+ it "should not respond_to? method_missing (because it's private)" do
20
+ formatter = options[:subject] || described_class.new({ }, StringIO.new)
21
+ formatter.should_not respond_to(:method_missing)
22
+ end
23
+
24
+ if options[:noop]
25
+ it "should respond_to? all messages" do
26
+ formatter = described_class.new({ }, StringIO.new)
27
+ formatter.should respond_to(:just_about_anything)
28
+ end
29
+
30
+ it "should respond_to? anything, when given the private flag" do
31
+ formatter = described_class.new({ }, StringIO.new)
32
+ formatter.respond_to?(:method_missing, true).should be_true
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ module Rspec
39
+ module Matchers
40
+ def with_ruby(version)
41
+ yield if RUBY_VERSION =~ Regexp.compile("^#{version.to_s}")
42
+ end
43
+ end
44
+ end
45
+
46
+ Rspec::Core.configure do |config|
47
+ config.mock_with :rspec
48
+ config.color_enabled = true
49
+ config.extend(Macros)
50
+ config.include(Rspec::Matchers)
51
+ config.include(Rspec::Mocks::Methods)
52
+ end
@@ -0,0 +1,29 @@
1
+ module Macros
2
+ def treats_method_missing_as_private(options = {:noop => true, :subject => nil})
3
+ it "should have method_missing as private" do
4
+ with_ruby 1.8 do
5
+ described_class.private_instance_methods.should include("method_missing")
6
+ end
7
+ with_ruby 1.9 do
8
+ described_class.private_instance_methods.should include(:method_missing)
9
+ end
10
+ end
11
+
12
+ it "should not respond_to? method_missing (because it's private)" do
13
+ formatter = options[:subject] || described_class.new({ }, StringIO.new)
14
+ formatter.should_not respond_to(:method_missing)
15
+ end
16
+
17
+ if options[:noop]
18
+ it "should respond_to? all messages" do
19
+ formatter = described_class.new({ }, StringIO.new)
20
+ formatter.should respond_to(:just_about_anything)
21
+ end
22
+
23
+ it "should respond_to? anything, when given the private flag" do
24
+ formatter = described_class.new({ }, StringIO.new)
25
+ formatter.respond_to?(:method_missing, true).should be_true
26
+ end
27
+ end
28
+ end
29
+ end
metadata ADDED
@@ -0,0 +1,172 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec-mocks
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0.a1
5
+ platform: ruby
6
+ authors:
7
+ - David Chelimsky
8
+ - Chad Humphries
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2009-09-16 00:00:00 -04:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rspec-core
18
+ type: :development
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 2.0.0.a1
25
+ version:
26
+ - !ruby/object:Gem::Dependency
27
+ name: rspec-expectations
28
+ type: :development
29
+ version_requirement:
30
+ version_requirements: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 2.0.0.a1
35
+ version:
36
+ description:
37
+ email: dchelimsky@gmail.com;chad.humphries@gmail.com
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files:
43
+ - README.markdown
44
+ files:
45
+ - .document
46
+ - .gitignore
47
+ - License.txt
48
+ - README.markdown
49
+ - Rakefile
50
+ - VERSION
51
+ - VERSION.yml
52
+ - lib/rspec/mocks.rb
53
+ - lib/rspec/mocks/argument_expectation.rb
54
+ - lib/rspec/mocks/argument_matchers.rb
55
+ - lib/rspec/mocks/error_generator.rb
56
+ - lib/rspec/mocks/errors.rb
57
+ - lib/rspec/mocks/extensions.rb
58
+ - lib/rspec/mocks/extensions/object.rb
59
+ - lib/rspec/mocks/framework.rb
60
+ - lib/rspec/mocks/message_expectation.rb
61
+ - lib/rspec/mocks/methods.rb
62
+ - lib/rspec/mocks/mock.rb
63
+ - lib/rspec/mocks/order_group.rb
64
+ - lib/rspec/mocks/proxy.rb
65
+ - lib/rspec/mocks/space.rb
66
+ - lib/rspec/mocks/spec_methods.rb
67
+ - lib/spec/mocks.rb
68
+ - spec/rspec/mocks/any_number_of_times_spec.rb
69
+ - spec/rspec/mocks/argument_expectation_spec.rb
70
+ - spec/rspec/mocks/at_least_spec.rb
71
+ - spec/rspec/mocks/at_most_spec.rb
72
+ - spec/rspec/mocks/bug_report_10260_spec.rb
73
+ - spec/rspec/mocks/bug_report_10263_spec.rb
74
+ - spec/rspec/mocks/bug_report_11545_spec.rb
75
+ - spec/rspec/mocks/bug_report_15719_spec.rb
76
+ - spec/rspec/mocks/bug_report_496_spec.rb
77
+ - spec/rspec/mocks/bug_report_600_spec.rb
78
+ - spec/rspec/mocks/bug_report_7611_spec.rb
79
+ - spec/rspec/mocks/bug_report_7805_spec.rb
80
+ - spec/rspec/mocks/bug_report_8165_spec.rb
81
+ - spec/rspec/mocks/bug_report_8302_spec.rb
82
+ - spec/rspec/mocks/bug_report_830_spec.rb
83
+ - spec/rspec/mocks/failing_argument_matchers_spec.rb
84
+ - spec/rspec/mocks/hash_including_matcher_spec.rb
85
+ - spec/rspec/mocks/hash_not_including_matcher_spec.rb
86
+ - spec/rspec/mocks/mock_ordering_spec.rb
87
+ - spec/rspec/mocks/mock_space_spec.rb
88
+ - spec/rspec/mocks/mock_spec.rb
89
+ - spec/rspec/mocks/multiple_return_value_spec.rb
90
+ - spec/rspec/mocks/nil_expectation_warning_spec.rb
91
+ - spec/rspec/mocks/null_object_mock_spec.rb
92
+ - spec/rspec/mocks/once_counts_spec.rb
93
+ - spec/rspec/mocks/options_hash_spec.rb
94
+ - spec/rspec/mocks/partial_mock_spec.rb
95
+ - spec/rspec/mocks/partial_mock_using_mocks_directly_spec.rb
96
+ - spec/rspec/mocks/passing_argument_matchers_spec.rb
97
+ - spec/rspec/mocks/precise_counts_spec.rb
98
+ - spec/rspec/mocks/record_messages_spec.rb
99
+ - spec/rspec/mocks/stub_chain_spec.rb
100
+ - spec/rspec/mocks/stub_implementation_spec.rb
101
+ - spec/rspec/mocks/stub_spec.rb
102
+ - spec/rspec/mocks/stubbed_message_expectations_spec.rb
103
+ - spec/rspec/mocks/twice_counts_spec.rb
104
+ - spec/spec_helper.rb
105
+ - spec/support/macros.rb
106
+ has_rdoc: true
107
+ homepage: http://github.com/rspec/mocks
108
+ licenses: []
109
+
110
+ post_install_message:
111
+ rdoc_options:
112
+ - --charset=UTF-8
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: "0"
120
+ version:
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: "0"
126
+ version:
127
+ requirements: []
128
+
129
+ rubyforge_project:
130
+ rubygems_version: 1.3.5
131
+ signing_key:
132
+ specification_version: 3
133
+ summary: rspec-mocks
134
+ test_files:
135
+ - spec/rspec/mocks/any_number_of_times_spec.rb
136
+ - spec/rspec/mocks/argument_expectation_spec.rb
137
+ - spec/rspec/mocks/at_least_spec.rb
138
+ - spec/rspec/mocks/at_most_spec.rb
139
+ - spec/rspec/mocks/bug_report_10260_spec.rb
140
+ - spec/rspec/mocks/bug_report_10263_spec.rb
141
+ - spec/rspec/mocks/bug_report_11545_spec.rb
142
+ - spec/rspec/mocks/bug_report_15719_spec.rb
143
+ - spec/rspec/mocks/bug_report_496_spec.rb
144
+ - spec/rspec/mocks/bug_report_600_spec.rb
145
+ - spec/rspec/mocks/bug_report_7611_spec.rb
146
+ - spec/rspec/mocks/bug_report_7805_spec.rb
147
+ - spec/rspec/mocks/bug_report_8165_spec.rb
148
+ - spec/rspec/mocks/bug_report_8302_spec.rb
149
+ - spec/rspec/mocks/bug_report_830_spec.rb
150
+ - spec/rspec/mocks/failing_argument_matchers_spec.rb
151
+ - spec/rspec/mocks/hash_including_matcher_spec.rb
152
+ - spec/rspec/mocks/hash_not_including_matcher_spec.rb
153
+ - spec/rspec/mocks/mock_ordering_spec.rb
154
+ - spec/rspec/mocks/mock_space_spec.rb
155
+ - spec/rspec/mocks/mock_spec.rb
156
+ - spec/rspec/mocks/multiple_return_value_spec.rb
157
+ - spec/rspec/mocks/nil_expectation_warning_spec.rb
158
+ - spec/rspec/mocks/null_object_mock_spec.rb
159
+ - spec/rspec/mocks/once_counts_spec.rb
160
+ - spec/rspec/mocks/options_hash_spec.rb
161
+ - spec/rspec/mocks/partial_mock_spec.rb
162
+ - spec/rspec/mocks/partial_mock_using_mocks_directly_spec.rb
163
+ - spec/rspec/mocks/passing_argument_matchers_spec.rb
164
+ - spec/rspec/mocks/precise_counts_spec.rb
165
+ - spec/rspec/mocks/record_messages_spec.rb
166
+ - spec/rspec/mocks/stub_chain_spec.rb
167
+ - spec/rspec/mocks/stub_implementation_spec.rb
168
+ - spec/rspec/mocks/stub_spec.rb
169
+ - spec/rspec/mocks/stubbed_message_expectations_spec.rb
170
+ - spec/rspec/mocks/twice_counts_spec.rb
171
+ - spec/spec_helper.rb
172
+ - spec/support/macros.rb