rspec-mocks 2.0.0.beta.20 → 2.0.0.beta.22

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,15 +1,16 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  gem "rake"
4
- gem "jeweler"
5
4
  gem "cucumber"
6
5
  gem "aruba", ">= 0.2.0"
7
6
  gem "autotest"
8
7
  gem "rspec-mocks", :path => "."
9
8
  gem "rspec-core", :path => "../rspec-core"
10
9
  gem "rspec-expectations", :path => "../rspec-expectations"
11
- if RUBY_VERSION.to_s =~ /1.9/
10
+
11
+ case RUBY_VERSION.to_s
12
+ when '1.9.2'
12
13
  gem "ruby-debug19"
13
- else
14
+ when /^1.8/
14
15
  gem "ruby-debug"
15
16
  end
@@ -0,0 +1,10 @@
1
+ ## rspec-mocks release history (incomplete)
2
+
3
+ ### 2.0.0.beta.22 / 2010-09-12
4
+
5
+ [full changelog](http://github.com/rspec/rspec-mocks/compare/v2.0.0.beta.20...v2.0.0.beta.22)
6
+
7
+ * Bug fixes
8
+ * fixed regression that broke obj.stub_chain(:a, :b => :c)
9
+ * fixed regression that broke obj.stub_chain(:a, :b) { :c }
10
+ * respond_to? always returns true when using as_null_object
data/Rakefile CHANGED
@@ -1,36 +1,11 @@
1
1
  require 'bundler'
2
2
  Bundler.setup
3
+ Bundler::GemHelper.install_tasks
3
4
 
4
5
  require 'rake'
5
- require 'rspec/mocks/version'
6
6
  require 'rspec/core/rake_task'
7
7
  require 'cucumber/rake/task'
8
8
 
9
- begin
10
- require 'jeweler'
11
- Jeweler::Tasks.new do |gem|
12
- gem.name = "rspec-mocks"
13
- gem.version = RSpec::Mocks::Version::STRING
14
- gem.summary = "rspec-mocks-#{RSpec::Mocks::Version::STRING}"
15
- gem.description = "RSpec's 'test double' framework, with support for stubbing and mocking"
16
- gem.email = "dchelimsky@gmail.com;chad.humphries@gmail.com"
17
- gem.homepage = "http://github.com/rspec/mocks"
18
- gem.authors = ["David Chelimsky", "Chad Humphries"]
19
- gem.rubyforge_project = "rspec"
20
- gem.add_development_dependency 'rspec-core', RSpec::Mocks::Version::STRING
21
- gem.add_development_dependency 'rspec-expectations', RSpec::Mocks::Version::STRING
22
- end
23
- rescue LoadError
24
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
25
- end
26
-
27
- namespace :gem do
28
- desc "push to gemcutter"
29
- task :push => :build do
30
- system "gem push pkg/rspec-mocks-#{RSpec::Mocks::Version::STRING}.gem"
31
- end
32
- end
33
-
34
9
  RSpec::Core::RakeTask.new(:spec)
35
10
 
36
11
  RSpec::Core::RakeTask.new(:rcov) do |spec|
@@ -64,4 +39,4 @@ Rake::RDocTask.new do |rdoc|
64
39
  rdoc.rdoc_files.include('lib/**/*.rb')
65
40
  end
66
41
 
67
- task :default => [:check_dependencies, :spec, :cucumber]
42
+ task :default => [:spec, :cucumber]
@@ -0,0 +1,44 @@
1
+ Feature: stub_chain
2
+
3
+ The stub_chain method lets you to stub a chain of methods in one statement.
4
+ Method chains are considered a design smell, but it's not really the method
5
+ chain that is the problem - it's the dependency chain represented by a chain
6
+ of messages to different objects:
7
+
8
+ foo.get_bar.get_baz
9
+
10
+ This is a Law of Demeter violation if get_bar() returns an object other than
11
+ foo, and get_baz() returns yet another object.
12
+
13
+ Fluent interfaces look similar from a caller's perspective, but don't
14
+ represent a dependency chain (the caller depends only on the object it is
15
+ calling). Consider this common example from Ruby on Rails:
16
+
17
+ Article.recent.by(current_user)
18
+
19
+ The recent() and by() methods return the same object, so this is not
20
+ a Law of Demeter violation.
21
+
22
+ Scenario: stub a chain of methods
23
+ Given a file named "stub_chain_spec.rb" with:
24
+ """
25
+ describe "stubbing a chain of methods" do
26
+ subject { Object.new }
27
+
28
+ context "given symbols representing methods" do
29
+ it "returns the correct value" do
30
+ subject.stub_chain(:one, :two, :three).and_return(:four)
31
+ subject.one.two.three.should eq(:four)
32
+ end
33
+ end
34
+
35
+ context "given a string of methods separated by dots" do
36
+ it "returns the correct value" do
37
+ subject.stub_chain("one.two.three").and_return(:four)
38
+ subject.one.two.three.should eq(:four)
39
+ end
40
+ end
41
+ end
42
+ """
43
+ When I run "rspec stub_chain_spec.rb"
44
+ Then the output should contain "2 examples, 0 failures"
@@ -34,19 +34,19 @@ module RSpec
34
34
  # == Examples
35
35
  #
36
36
  # Article.stub_chain("recent.published") { [Article.new] }
37
- def stub_chain(*chain)
38
- methods = chain.join('.').split('.')
39
- if methods.length > 1
40
- if matching_stub = __mock_proxy.__send__(:find_matching_method_stub, methods[0].to_sym)
41
- methods.shift
42
- matching_stub.invoke.stub_chain(*methods)
37
+ def stub_chain(*chain, &blk)
38
+ chain, blk = format_chain(*chain, &blk)
39
+ if chain.length > 1
40
+ if matching_stub = __mock_proxy.__send__(:find_matching_method_stub, chain[0].to_sym)
41
+ chain.shift
42
+ matching_stub.invoke.stub_chain(*chain)
43
43
  else
44
44
  next_in_chain = Object.new
45
- stub(methods.shift) { next_in_chain }
46
- next_in_chain.stub_chain(*methods)
45
+ stub(chain.shift) { next_in_chain }
46
+ next_in_chain.stub_chain(*chain, &blk)
47
47
  end
48
48
  else
49
- stub(methods.shift)
49
+ stub(chain.shift, &blk)
50
50
  end
51
51
  end
52
52
 
@@ -79,6 +79,17 @@ module RSpec
79
79
  @mock_proxy ||= Proxy.new(self)
80
80
  end
81
81
  end
82
+
83
+ def format_chain(*chain, &blk)
84
+ if Hash === chain.last
85
+ hash = chain.pop
86
+ hash.each do |k,v|
87
+ chain << k
88
+ blk = lambda { v }
89
+ end
90
+ end
91
+ return chain.join('.').split('.'), blk
92
+ end
82
93
  end
83
94
  end
84
95
  end
@@ -34,6 +34,10 @@ module RSpec
34
34
 
35
35
  alias_method :to_str, :to_s
36
36
 
37
+ def respond_to?(sym, incl_private=false)
38
+ __mock_proxy.null_object? ? true : super
39
+ end
40
+
37
41
  private
38
42
 
39
43
  def method_missing(sym, *args, &block)
@@ -37,7 +37,7 @@ module RSpec
37
37
  def null_object?
38
38
  @null_object
39
39
  end
40
-
40
+
41
41
  # Tells the object to ignore any messages that aren't explicitly set as
42
42
  # stubs or message expectations.
43
43
  def as_null_object
@@ -1,7 +1,7 @@
1
1
  module RSpec # :nodoc:
2
2
  module Mocks # :nodoc:
3
3
  module Version # :nodoc:
4
- STRING = File.readlines(File.expand_path('../../../../VERSION', __FILE__)).first
4
+ STRING = '2.0.0.beta.22'
5
5
  end
6
6
  end
7
7
  end
@@ -1,170 +1,28 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
1
  # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
3
+ require "rspec/mocks/version"
5
4
 
6
5
  Gem::Specification.new do |s|
7
- s.name = %q{rspec-mocks}
8
- s.version = "2.0.0.beta.20"
6
+ s.name = "rspec-mocks"
7
+ s.version = RSpec::Mocks::Version::STRING
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["David Chelimsky", "Chad Humphries"]
10
+ s.email = "dchelimsky@gmail.com;chad.humphries@gmail.com"
11
+ s.homepage = "http://github.com/rspec/rspec-mocks"
12
+ s.summary = "rspec-mocks-#{RSpec::Mocks::Version::STRING}"
13
+ s.description = "RSpec's 'test double' framework, with support for stubbing and mocking"
9
14
 
10
- s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["David Chelimsky", "Chad Humphries"]
12
- s.date = %q{2010-08-24}
13
- s.description = %q{RSpec's 'test double' framework, with support for stubbing and mocking}
14
- s.email = %q{dchelimsky@gmail.com;chad.humphries@gmail.com}
15
- s.extra_rdoc_files = [
16
- "README.markdown"
17
- ]
18
- s.files = [
19
- ".autotest",
20
- ".document",
21
- ".gitignore",
22
- "Gemfile",
23
- "License.txt",
24
- "README.markdown",
25
- "Rakefile",
26
- "VERSION",
27
- "autotest/discover.rb",
28
- "cucumber.yml",
29
- "features/README.markdown",
30
- "features/configuration.feature",
31
- "features/mocks/block_local_expectations.feature",
32
- "features/mocks/warn_when_expectation_is_set_on_nil.feature",
33
- "features/stubs/stub_implementation.feature",
34
- "features/support/env.rb",
35
- "lib/rspec/mocks.rb",
36
- "lib/rspec/mocks/argument_expectation.rb",
37
- "lib/rspec/mocks/argument_matchers.rb",
38
- "lib/rspec/mocks/error_generator.rb",
39
- "lib/rspec/mocks/errors.rb",
40
- "lib/rspec/mocks/extensions.rb",
41
- "lib/rspec/mocks/extensions/instance_exec.rb",
42
- "lib/rspec/mocks/extensions/object.rb",
43
- "lib/rspec/mocks/framework.rb",
44
- "lib/rspec/mocks/message_expectation.rb",
45
- "lib/rspec/mocks/method_double.rb",
46
- "lib/rspec/mocks/methods.rb",
47
- "lib/rspec/mocks/mock.rb",
48
- "lib/rspec/mocks/order_group.rb",
49
- "lib/rspec/mocks/proxy.rb",
50
- "lib/rspec/mocks/space.rb",
51
- "lib/rspec/mocks/spec_methods.rb",
52
- "lib/rspec/mocks/version.rb",
53
- "lib/spec/mocks.rb",
54
- "rspec-mocks.gemspec",
55
- "spec/rspec/mocks/and_yield_spec.rb",
56
- "spec/rspec/mocks/any_number_of_times_spec.rb",
57
- "spec/rspec/mocks/argument_expectation_spec.rb",
58
- "spec/rspec/mocks/at_least_spec.rb",
59
- "spec/rspec/mocks/at_most_spec.rb",
60
- "spec/rspec/mocks/block_return_value_spec.rb",
61
- "spec/rspec/mocks/bug_report_10260_spec.rb",
62
- "spec/rspec/mocks/bug_report_10263_spec.rb",
63
- "spec/rspec/mocks/bug_report_11545_spec.rb",
64
- "spec/rspec/mocks/bug_report_15719_spec.rb",
65
- "spec/rspec/mocks/bug_report_496_spec.rb",
66
- "spec/rspec/mocks/bug_report_600_spec.rb",
67
- "spec/rspec/mocks/bug_report_7611_spec.rb",
68
- "spec/rspec/mocks/bug_report_7805_spec.rb",
69
- "spec/rspec/mocks/bug_report_8165_spec.rb",
70
- "spec/rspec/mocks/bug_report_8302_spec.rb",
71
- "spec/rspec/mocks/bug_report_830_spec.rb",
72
- "spec/rspec/mocks/bug_report_957_spec.rb",
73
- "spec/rspec/mocks/double_spec.rb",
74
- "spec/rspec/mocks/failing_argument_matchers_spec.rb",
75
- "spec/rspec/mocks/hash_including_matcher_spec.rb",
76
- "spec/rspec/mocks/hash_not_including_matcher_spec.rb",
77
- "spec/rspec/mocks/mock_ordering_spec.rb",
78
- "spec/rspec/mocks/mock_space_spec.rb",
79
- "spec/rspec/mocks/mock_spec.rb",
80
- "spec/rspec/mocks/multiple_return_value_spec.rb",
81
- "spec/rspec/mocks/nil_expectation_warning_spec.rb",
82
- "spec/rspec/mocks/null_object_mock_spec.rb",
83
- "spec/rspec/mocks/once_counts_spec.rb",
84
- "spec/rspec/mocks/options_hash_spec.rb",
85
- "spec/rspec/mocks/partial_mock_spec.rb",
86
- "spec/rspec/mocks/partial_mock_using_mocks_directly_spec.rb",
87
- "spec/rspec/mocks/passing_argument_matchers_spec.rb",
88
- "spec/rspec/mocks/precise_counts_spec.rb",
89
- "spec/rspec/mocks/record_messages_spec.rb",
90
- "spec/rspec/mocks/stash_spec.rb",
91
- "spec/rspec/mocks/stub_chain_spec.rb",
92
- "spec/rspec/mocks/stub_implementation_spec.rb",
93
- "spec/rspec/mocks/stub_spec.rb",
94
- "spec/rspec/mocks/stubbed_message_expectations_spec.rb",
95
- "spec/rspec/mocks/twice_counts_spec.rb",
96
- "spec/rspec/mocks_spec.rb",
97
- "spec/spec_helper.rb",
98
- "spec/support/macros.rb",
99
- "specs.watchr"
100
- ]
101
- s.homepage = %q{http://github.com/rspec/mocks}
102
- s.rdoc_options = ["--charset=UTF-8"]
103
- s.require_paths = ["lib"]
104
- s.rubyforge_project = %q{rspec}
105
- s.rubygems_version = %q{1.3.7}
106
- s.summary = %q{rspec-mocks-2.0.0.beta.20}
107
- s.test_files = [
108
- "spec/rspec/mocks/and_yield_spec.rb",
109
- "spec/rspec/mocks/any_number_of_times_spec.rb",
110
- "spec/rspec/mocks/argument_expectation_spec.rb",
111
- "spec/rspec/mocks/at_least_spec.rb",
112
- "spec/rspec/mocks/at_most_spec.rb",
113
- "spec/rspec/mocks/block_return_value_spec.rb",
114
- "spec/rspec/mocks/bug_report_10260_spec.rb",
115
- "spec/rspec/mocks/bug_report_10263_spec.rb",
116
- "spec/rspec/mocks/bug_report_11545_spec.rb",
117
- "spec/rspec/mocks/bug_report_15719_spec.rb",
118
- "spec/rspec/mocks/bug_report_496_spec.rb",
119
- "spec/rspec/mocks/bug_report_600_spec.rb",
120
- "spec/rspec/mocks/bug_report_7611_spec.rb",
121
- "spec/rspec/mocks/bug_report_7805_spec.rb",
122
- "spec/rspec/mocks/bug_report_8165_spec.rb",
123
- "spec/rspec/mocks/bug_report_8302_spec.rb",
124
- "spec/rspec/mocks/bug_report_830_spec.rb",
125
- "spec/rspec/mocks/bug_report_957_spec.rb",
126
- "spec/rspec/mocks/double_spec.rb",
127
- "spec/rspec/mocks/failing_argument_matchers_spec.rb",
128
- "spec/rspec/mocks/hash_including_matcher_spec.rb",
129
- "spec/rspec/mocks/hash_not_including_matcher_spec.rb",
130
- "spec/rspec/mocks/mock_ordering_spec.rb",
131
- "spec/rspec/mocks/mock_space_spec.rb",
132
- "spec/rspec/mocks/mock_spec.rb",
133
- "spec/rspec/mocks/multiple_return_value_spec.rb",
134
- "spec/rspec/mocks/nil_expectation_warning_spec.rb",
135
- "spec/rspec/mocks/null_object_mock_spec.rb",
136
- "spec/rspec/mocks/once_counts_spec.rb",
137
- "spec/rspec/mocks/options_hash_spec.rb",
138
- "spec/rspec/mocks/partial_mock_spec.rb",
139
- "spec/rspec/mocks/partial_mock_using_mocks_directly_spec.rb",
140
- "spec/rspec/mocks/passing_argument_matchers_spec.rb",
141
- "spec/rspec/mocks/precise_counts_spec.rb",
142
- "spec/rspec/mocks/record_messages_spec.rb",
143
- "spec/rspec/mocks/stash_spec.rb",
144
- "spec/rspec/mocks/stub_chain_spec.rb",
145
- "spec/rspec/mocks/stub_implementation_spec.rb",
146
- "spec/rspec/mocks/stub_spec.rb",
147
- "spec/rspec/mocks/stubbed_message_expectations_spec.rb",
148
- "spec/rspec/mocks/twice_counts_spec.rb",
149
- "spec/rspec/mocks_spec.rb",
150
- "spec/spec_helper.rb",
151
- "spec/support/macros.rb"
152
- ]
15
+ s.rubygems_version = "1.3.7"
16
+ s.rubyforge_project = "rspec"
153
17
 
154
- if s.respond_to? :specification_version then
155
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
156
- s.specification_version = 3
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.extra_rdoc_files = [ "README.markdown" ]
22
+ s.rdoc_options = ["--charset=UTF-8"]
23
+ s.require_path = "lib"
157
24
 
158
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
159
- s.add_development_dependency(%q<rspec-core>, ["= 2.0.0.beta.20"])
160
- s.add_development_dependency(%q<rspec-expectations>, ["= 2.0.0.beta.20"])
161
- else
162
- s.add_dependency(%q<rspec-core>, ["= 2.0.0.beta.20"])
163
- s.add_dependency(%q<rspec-expectations>, ["= 2.0.0.beta.20"])
164
- end
165
- else
166
- s.add_dependency(%q<rspec-core>, ["= 2.0.0.beta.20"])
167
- s.add_dependency(%q<rspec-expectations>, ["= 2.0.0.beta.20"])
168
- end
25
+ s.add_dependency "rspec-core", RSpec::Mocks::Version::STRING
26
+ s.add_dependency "rspec-expectations", RSpec::Mocks::Version::STRING
169
27
  end
170
28
 
@@ -2,45 +2,57 @@ require 'spec_helper'
2
2
 
3
3
  module RSpec
4
4
  module Mocks
5
- describe "a mock acting as a NullObject" do
5
+ describe "a double _not_ acting as a null object" do
6
6
  before(:each) do
7
- @mock = RSpec::Mocks::Mock.new("null_object").as_null_object
7
+ @double = double('non-null object')
8
+ end
9
+
10
+ it "says it does not respond to messages it doesn't understand" do
11
+ @double.should_not respond_to(:foo)
12
+ end
13
+
14
+ it "says it responds to messages it does understand" do
15
+ @double.stub(:foo)
16
+ @double.should respond_to(:foo)
17
+ end
18
+ end
19
+
20
+ describe "a double acting as a null object" do
21
+ before(:each) do
22
+ @double = double('null object').as_null_object
23
+ end
24
+
25
+ it "says it responds to everything" do
26
+ @double.should respond_to(:any_message_it_gets)
8
27
  end
9
28
 
10
29
  it "allows explicit expectation" do
11
- @mock.should_receive(:something)
12
- @mock.something
30
+ @double.should_receive(:something)
31
+ @double.something
13
32
  end
14
33
 
15
34
  it "fails verification when explicit exception not met" do
16
35
  lambda do
17
- @mock.should_receive(:something)
18
- @mock.rspec_verify
36
+ @double.should_receive(:something)
37
+ @double.rspec_verify
19
38
  end.should raise_error(RSpec::Mocks::MockExpectationError)
20
39
  end
21
40
 
22
41
  it "ignores unexpected methods" do
23
- @mock.random_call("a", "d", "c")
24
- @mock.rspec_verify
42
+ @double.random_call("a", "d", "c")
43
+ @double.rspec_verify
25
44
  end
26
45
 
27
46
  it "allows expected message with different args first" do
28
- @mock.should_receive(:message).with(:expected_arg)
29
- @mock.message(:unexpected_arg)
30
- @mock.message(:expected_arg)
47
+ @double.should_receive(:message).with(:expected_arg)
48
+ @double.message(:unexpected_arg)
49
+ @double.message(:expected_arg)
31
50
  end
32
51
 
33
52
  it "allows expected message with different args second" do
34
- @mock.should_receive(:message).with(:expected_arg)
35
- @mock.message(:expected_arg)
36
- @mock.message(:unexpected_arg)
37
- end
38
- end
39
-
40
- describe "#null_object?" do
41
- it "defaults to false" do
42
- obj = double('anything')
43
- obj.should_not be_null_object
53
+ @double.should_receive(:message).with(:expected_arg)
54
+ @double.message(:expected_arg)
55
+ @double.message(:unexpected_arg)
44
56
  end
45
57
  end
46
58
 
@@ -50,5 +62,12 @@ module RSpec
50
62
  obj.should be_null_object
51
63
  end
52
64
  end
65
+
66
+ describe "#null_object?" do
67
+ it "defaults to false" do
68
+ obj = double('anything')
69
+ obj.should_not be_null_object
70
+ end
71
+ end
53
72
  end
54
73
  end
@@ -134,34 +134,19 @@ module RSpec
134
134
 
135
135
  it 'keeps public methods public' do
136
136
  @object.should_receive(:public_method)
137
- with_ruby('1.9') do
138
- @object.public_methods.should include(:public_method)
139
- end
140
- with_ruby('1.8') do
141
- @object.public_methods.should include('public_method')
142
- end
137
+ @object.public_methods.should include_method(:public_method)
143
138
  @object.public_method
144
139
  end
145
140
 
146
141
  it 'keeps private methods private' do
147
142
  @object.should_receive(:private_method)
148
- with_ruby('1.9') do
149
- @object.private_methods.should include(:private_method)
150
- end
151
- with_ruby('1.8') do
152
- @object.private_methods.should include('private_method')
153
- end
143
+ @object.private_methods.should include_method(:private_method)
154
144
  @object.public_method
155
145
  end
156
146
 
157
147
  it 'keeps protected methods protected' do
158
148
  @object.should_receive(:protected_method)
159
- with_ruby('1.9') do
160
- @object.protected_methods.should include(:protected_method)
161
- end
162
- with_ruby('1.8') do
163
- @object.protected_methods.should include('protected_method')
164
- end
149
+ @object.protected_methods.should include_method(:protected_method)
165
150
  @object.public_method
166
151
  end
167
152
 
@@ -7,14 +7,81 @@ module RSpec
7
7
  @subject = Object.new
8
8
  end
9
9
 
10
- it "returns expected value from chaining only one method call" do
11
- @subject.stub_chain(:msg1).and_return(:return_value)
12
- @subject.msg1.should equal(:return_value)
10
+
11
+ context "with one method in chain" do
12
+ context "using and_return" do
13
+ it "returns expected value from chaining only one method call" do
14
+ @subject.stub_chain(:msg1).and_return(:return_value)
15
+ @subject.msg1.should equal(:return_value)
16
+ end
17
+ end
18
+
19
+ context "using a block" do
20
+ it "returns the correct value" do
21
+ @subject.stub_chain(:msg1) { :return_value }
22
+ @subject.msg1.should equal(:return_value)
23
+ end
24
+ end
25
+
26
+ context "using a hash" do
27
+ it "returns the value of the key/value pair" do
28
+ @subject.stub_chain(:msg1 => :return_value)
29
+ @subject.msg1.should equal(:return_value)
30
+ end
31
+ end
32
+ end
33
+
34
+ context "with two methods in chain" do
35
+ context "using and_return" do
36
+ it "returns expected value from chaining two method calls" do
37
+ @subject.stub_chain(:msg1, :msg2).and_return(:return_value)
38
+ @subject.msg1.msg2.should equal(:return_value)
39
+ end
40
+ end
41
+
42
+ context "using a block" do
43
+ it "returns the correct value" do
44
+ @subject.stub_chain(:msg1, :msg2) { :return_value }
45
+ @subject.msg1.msg2.should equal(:return_value)
46
+ end
47
+ end
48
+
49
+ context "using a hash" do
50
+ it "returns the value of the key/value pair" do
51
+ @subject.stub_chain(:msg1, :msg2 => :return_value)
52
+ @subject.msg1.msg2.should equal(:return_value)
53
+ end
54
+ end
13
55
  end
14
56
 
15
- it "returns expected value from chaining two method calls" do
16
- @subject.stub_chain(:msg1, :msg2).and_return(:return_value)
17
- @subject.msg1.msg2.should equal(:return_value)
57
+ context "with four methods in chain" do
58
+ context "using and_return" do
59
+ it "returns expected value from chaining two method calls" do
60
+ @subject.stub_chain(:msg1, :msg2, :msg3, :msg4).and_return(:return_value)
61
+ @subject.msg1.msg2.msg3.msg4.should equal(:return_value)
62
+ end
63
+ end
64
+
65
+ context "using a block" do
66
+ it "returns the correct value" do
67
+ @subject.stub_chain(:msg1, :msg2, :msg3, :msg4) { :return_value }
68
+ @subject.msg1.msg2.msg3.msg4.should equal(:return_value)
69
+ end
70
+ end
71
+
72
+ context "using a hash" do
73
+ it "returns the value of the key/value pair" do
74
+ @subject.stub_chain(:msg1, :msg2, :msg3, :msg4 => :return_value)
75
+ @subject.msg1.msg2.msg3.msg4.should equal(:return_value)
76
+ end
77
+ end
78
+
79
+ context "using a hash with a string key" do
80
+ it "returns the value of the key/value pair" do
81
+ @subject.stub_chain("msg1.msg2.msg3.msg4" => :return_value)
82
+ @subject.msg1.msg2.msg3.msg4.should equal(:return_value)
83
+ end
84
+ end
18
85
  end
19
86
 
20
87
  it "returns expected value from chaining four method calls" do
@@ -61,8 +61,8 @@ module RSpec
61
61
  obj = Object.new
62
62
  lambda do
63
63
  obj.unstub(:foo)
64
- end.should raise_error(MockExpectationError)
64
+ end.should raise_error(RSpec::Mocks::MockExpectationError)
65
65
  end
66
66
  end
67
67
  end
68
- end
68
+ end
@@ -5,12 +5,7 @@ require 'rspec/expectations'
5
5
  module Macros
6
6
  def treats_method_missing_as_private(options = {:noop => true, :subject => nil})
7
7
  it "has method_missing as private" do
8
- with_ruby 1.8 do
9
- self.class.describes.private_instance_methods.should include("method_missing")
10
- end
11
- with_ruby 1.9 do
12
- self.class.describes.private_instance_methods.should include(:method_missing)
13
- end
8
+ self.class.describes.private_instance_methods.should include_method(:method_missing)
14
9
  end
15
10
 
16
11
  it "does not respond_to? method_missing (because it's private)" do
@@ -32,11 +27,9 @@ module Macros
32
27
  end
33
28
  end
34
29
 
35
- module RSpec
36
- module Matchers
37
- def with_ruby(version)
38
- yield if RUBY_VERSION =~ Regexp.compile("^#{version.to_s}")
39
- end
30
+ RSpec::Matchers.define :include_method do |expected|
31
+ match do |actual|
32
+ actual.map { |m| m.to_s }.include?(expected.to_s)
40
33
  end
41
34
  end
42
35
 
@@ -44,6 +37,5 @@ RSpec.configure do |config|
44
37
  config.mock_with :rspec
45
38
  config.color_enabled = true
46
39
  config.extend(Macros)
47
- config.include(RSpec::Matchers)
48
40
  config.include(RSpec::Mocks::Methods)
49
41
  end
metadata CHANGED
@@ -7,8 +7,8 @@ version: !ruby/object:Gem::Version
7
7
  - 0
8
8
  - 0
9
9
  - beta
10
- - 20
11
- version: 2.0.0.beta.20
10
+ - 22
11
+ version: 2.0.0.beta.22
12
12
  platform: ruby
13
13
  authors:
14
14
  - David Chelimsky
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2010-08-24 00:00:00 -05:00
20
+ date: 2010-09-12 00:00:00 -05:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
@@ -32,9 +32,9 @@ dependencies:
32
32
  - 0
33
33
  - 0
34
34
  - beta
35
- - 20
36
- version: 2.0.0.beta.20
37
- type: :development
35
+ - 22
36
+ version: 2.0.0.beta.22
37
+ type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: *id001
40
40
  - !ruby/object:Gem::Dependency
@@ -49,9 +49,9 @@ dependencies:
49
49
  - 0
50
50
  - 0
51
51
  - beta
52
- - 20
53
- version: 2.0.0.beta.20
54
- type: :development
52
+ - 22
53
+ version: 2.0.0.beta.22
54
+ type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: *id002
57
57
  description: RSpec's 'test double' framework, with support for stubbing and mocking
@@ -67,16 +67,17 @@ files:
67
67
  - .document
68
68
  - .gitignore
69
69
  - Gemfile
70
+ - History.md
70
71
  - License.txt
71
72
  - README.markdown
72
73
  - Rakefile
73
- - VERSION
74
74
  - autotest/discover.rb
75
75
  - cucumber.yml
76
76
  - features/README.markdown
77
77
  - features/configuration.feature
78
78
  - features/mocks/block_local_expectations.feature
79
79
  - features/mocks/warn_when_expectation_is_set_on_nil.feature
80
+ - features/stubs/stub_chain.feature
80
81
  - features/stubs/stub_implementation.feature
81
82
  - features/support/env.rb
82
83
  - lib/rspec/mocks.rb
@@ -84,7 +85,6 @@ files:
84
85
  - lib/rspec/mocks/argument_matchers.rb
85
86
  - lib/rspec/mocks/error_generator.rb
86
87
  - lib/rspec/mocks/errors.rb
87
- - lib/rspec/mocks/extensions.rb
88
88
  - lib/rspec/mocks/extensions/instance_exec.rb
89
89
  - lib/rspec/mocks/extensions/object.rb
90
90
  - lib/rspec/mocks/framework.rb
@@ -142,10 +142,9 @@ files:
142
142
  - spec/rspec/mocks/twice_counts_spec.rb
143
143
  - spec/rspec/mocks_spec.rb
144
144
  - spec/spec_helper.rb
145
- - spec/support/macros.rb
146
145
  - specs.watchr
147
146
  has_rdoc: true
148
- homepage: http://github.com/rspec/mocks
147
+ homepage: http://github.com/rspec/rspec-mocks
149
148
  licenses: []
150
149
 
151
150
  post_install_message:
@@ -158,7 +157,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
158
157
  requirements:
159
158
  - - ">="
160
159
  - !ruby/object:Gem::Version
161
- hash: -4186066668250905798
160
+ hash: -2717904534021083883
162
161
  segments:
163
162
  - 0
164
163
  version: "0"
@@ -178,8 +177,15 @@ rubyforge_project: rspec
178
177
  rubygems_version: 1.3.7
179
178
  signing_key:
180
179
  specification_version: 3
181
- summary: rspec-mocks-2.0.0.beta.20
180
+ summary: rspec-mocks-2.0.0.beta.22
182
181
  test_files:
182
+ - features/README.markdown
183
+ - features/configuration.feature
184
+ - features/mocks/block_local_expectations.feature
185
+ - features/mocks/warn_when_expectation_is_set_on_nil.feature
186
+ - features/stubs/stub_chain.feature
187
+ - features/stubs/stub_implementation.feature
188
+ - features/support/env.rb
183
189
  - spec/rspec/mocks/and_yield_spec.rb
184
190
  - spec/rspec/mocks/any_number_of_times_spec.rb
185
191
  - spec/rspec/mocks/argument_expectation_spec.rb
@@ -223,4 +229,3 @@ test_files:
223
229
  - spec/rspec/mocks/twice_counts_spec.rb
224
230
  - spec/rspec/mocks_spec.rb
225
231
  - spec/spec_helper.rb
226
- - spec/support/macros.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 2.0.0.beta.20
File without changes
@@ -1,29 +0,0 @@
1
- module Macros
2
- def treats_method_missing_as_private(options = {:noop => true, :subject => nil})
3
- it "has 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 "does 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