rspec-mocks 2.0.0.rc → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile CHANGED
@@ -7,6 +7,7 @@ gem "autotest"
7
7
  gem "rspec-mocks", :path => "."
8
8
  gem "rspec-core", :path => "../rspec-core"
9
9
  gem "rspec-expectations", :path => "../rspec-expectations"
10
+ gem "relish"
10
11
 
11
12
  case RUBY_VERSION.to_s
12
13
  when '1.9.2'
@@ -1,5 +1,9 @@
1
1
  ## rspec-mocks release history (incomplete)
2
2
 
3
+ ### 2.0.0 / 2010-10-10
4
+
5
+ [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.0.0.beta.22...v2.0.0)
6
+
3
7
  ### 2.0.0.rc / 2010-10-05
4
8
 
5
9
  [full changelog](http://github.com/rspec/rspec-mocks/compare/v2.0.0.beta.22...v2.0.0.rc)
data/Rakefile CHANGED
@@ -7,13 +7,6 @@ require 'rspec/core/rake_task'
7
7
  require 'rspec/mocks/version'
8
8
  require 'cucumber/rake/task'
9
9
 
10
- RSpec::Core::RakeTask.new(:spec)
11
-
12
- RSpec::Core::RakeTask.new(:rcov) do |spec|
13
- spec.rcov = true
14
- spec.rcov_opts = %[--exclude "core,expectations,gems/*,spec/resources,spec/spec,spec/spec_helper.rb,db/*,/Library/Ruby/*,config/*" --text-summary --sort coverage]
15
- end
16
-
17
10
  class Cucumber::Rake::Task::ForkedCucumberRunner
18
11
  # When cucumber shells out, we still need it to run in the context of our
19
12
  # bundle.
@@ -22,10 +15,38 @@ class Cucumber::Rake::Task::ForkedCucumberRunner
22
15
  end
23
16
  end
24
17
 
25
- Cucumber::Rake::Task.new do |t|
26
- t.cucumber_opts = %w{--format progress}
18
+ task :cleanup_rcov_files do
19
+ rm_rf 'coverage.data'
20
+ end
21
+
22
+ desc "Run all examples"
23
+ RSpec::Core::RakeTask.new(:spec) do |t|
24
+ t.rspec_opts = %w[--color]
25
+ end
26
+
27
+ Cucumber::Rake::Task.new(:cucumber)
28
+
29
+ namespace :spec do
30
+ desc "Run all examples using rcov"
31
+ RSpec::Core::RakeTask.new :rcov => :cleanup_rcov_files do |t|
32
+ t.rcov = true
33
+ t.rcov_opts = %[-Ilib -Ispec --exclude "gems/*,features"]
34
+ t.rcov_opts << %[--text-report --sort coverage --no-html --aggregate coverage.data]
35
+ end
36
+ end
37
+
38
+ namespace :cucumber do
39
+ desc "Run cucumber features using rcov"
40
+ Cucumber::Rake::Task.new :rcov => :cleanup_rcov_files do |t|
41
+ t.cucumber_opts = %w{--format progress}
42
+ t.rcov = true
43
+ t.rcov_opts = %[-Ilib -Ispec --exclude "gems/*,features"]
44
+ t.rcov_opts << %[--text-report --sort coverage --aggregate coverage.data]
45
+ end
27
46
  end
28
47
 
48
+ task :default => [:spec, :cucumber]
49
+
29
50
  task :clobber do
30
51
  rm_rf 'pkg'
31
52
  rm_rf 'tmp'
@@ -40,4 +61,10 @@ Rake::RDocTask.new do |rdoc|
40
61
  rdoc.rdoc_files.include('lib/**/*.rb')
41
62
  end
42
63
 
64
+ desc "Push cukes to relishapp using the relish-client-gem"
65
+ task :relish, :version do |t, args|
66
+ raise "rake relish[VERSION]" unless args[:version]
67
+ sh "bundle exec relish --organization rspec --project rspec-mocks -v #{args[:version]} push"
68
+ end
69
+
43
70
  task :default => [:spec, :cucumber]
@@ -1,12 +1,30 @@
1
- # Cucumber features
1
+ rspec-mocks is used to create dynamic "doubles", which stand in for real
2
+ objects in examples. You can set message expectations on them (i.e. mock
3
+ methods), and/or stub return values for arbitrary messages:
2
4
 
3
- RSpec is specified using both RSpec and
4
- [Cucumber](http://github.com/aslakhellesoy/cucumber). Cucumber provides
5
- _executable documentation_. This means that the _.feature_ files below this
6
- directory serve as specification, documentation _and_ regression tests of the
7
- behaviour.
5
+ describe Account do
6
+ context "when closed" do
7
+ it "logs an account closed message" do
8
+ logger = double()
9
+ account = Account.new
10
+ account.logger = logger
11
+
12
+ logger.should_receive(:account_closed).with(account)
13
+
14
+ account.close
15
+ end
16
+ end
17
+ end
18
+
19
+ Message expectations like the one in the example above are verified at
20
+ the end of each example.
8
21
 
9
22
  ## Issues
10
23
 
11
- If you find this documentation incomplete or confusing, please [submit an
12
- issue](http://github.com/rspec/rspec-mocks/issues).
24
+ The documentation for rspec-mocks is a work in progress. We'll be adding
25
+ Cucumber features over time, and clarifying existing ones. If you have
26
+ specific features you'd like to see added, find the existing documentation
27
+ incomplete or confusing, or, better yet, wish to write a missing Cucumber
28
+ feature yourself, please [submit an
29
+ issue](http://github.com/rspec/rspec-mocks/issues) or a [pull
30
+ request](http://github.com/rspec/rspec-mocks).
@@ -14,27 +14,28 @@ Feature: block local expectations
14
14
  """
15
15
 
16
16
  Scenario: passing example
17
- Given a file named "spec/account_passing_spec.rb" with:
17
+ Given a file named "spec/account_spec.rb" with:
18
18
  """
19
19
  require 'account'
20
20
 
21
21
  describe "account DSL" do
22
22
  it "it succeeds when the block local receives the given call" do
23
- Account.should_receive(:create).and_yield do |account|
23
+ account = double("Account")
24
+ Account.should_receive(:create).and_yield(account) do |account|
24
25
  account.should_receive(:opening_balance).with(100, :USD)
25
26
  end
26
- Account.create do
27
- opening_balance 100, :USD
27
+ Account.create do |account|
28
+ account.opening_balance 100, :USD
28
29
  end
29
30
  end
30
31
  end
31
32
  """
32
- When I run "rspec ./spec/account_passing_spec.rb"
33
+ When I run "rspec ./spec/account_spec.rb"
33
34
  Then the output should contain "1 example, 0 failures"
34
35
 
35
36
  Scenario: failing example
36
37
 
37
- Given a file named "spec/account_failing_spec.rb" with:
38
+ Given a file named "spec/account_spec.rb" with:
38
39
  """
39
40
  require 'account'
40
41
 
@@ -43,12 +44,12 @@ Feature: block local expectations
43
44
  Account.should_receive(:create).and_yield do |account|
44
45
  account.should_receive(:opening_balance).with(100, :USD)
45
46
  end
46
- Account.create do
47
+ Account.create do |account|
47
48
  # opening_balance is not called here
48
49
  end
49
50
  end
50
51
  end
51
52
  """
52
53
 
53
- When I run "rspec ./spec/account_failing_spec.rb"
54
+ When I run "rspec ./spec/account_spec.rb"
54
55
  Then the output should contain "1 example, 1 failure"
@@ -0,0 +1,94 @@
1
+ Feature: Expect a message
2
+
3
+ Use should_receive() to set an expectation that a receiver should receive a
4
+ message before the example is completed.
5
+
6
+ Scenario: expect a message
7
+ Given a file named "spec/account_spec.rb" with:
8
+ """
9
+ require "account"
10
+
11
+ describe Account do
12
+ context "when closed" do
13
+ it "logs an account closed message" do
14
+ logger = double("logger")
15
+ account = Account.new
16
+ account.logger = logger
17
+
18
+ logger.should_receive(:account_closed)
19
+
20
+ account.close
21
+ end
22
+ end
23
+ end
24
+ """
25
+ And a file named "lib/account.rb" with:
26
+ """
27
+ class Account
28
+ attr_accessor :logger
29
+
30
+ def close
31
+ logger.account_closed
32
+ end
33
+ end
34
+ """
35
+ When I run "rspec spec/account_spec.rb"
36
+ Then the output should contain "1 example, 0 failures"
37
+
38
+ Scenario: expect a message with an argument
39
+ Given a file named "spec/account_spec.rb" with:
40
+ """
41
+ require "account"
42
+
43
+ describe Account do
44
+ context "when closed" do
45
+ it "logs an account closed message" do
46
+ logger = double("logger")
47
+ account = Account.new
48
+ account.logger = logger
49
+
50
+ logger.should_receive(:account_closed).with(account)
51
+
52
+ account.close
53
+ end
54
+ end
55
+ end
56
+ """
57
+ And a file named "lib/account.rb" with:
58
+ """
59
+ class Account
60
+ attr_accessor :logger
61
+
62
+ def close
63
+ logger.account_closed(self)
64
+ end
65
+ end
66
+ """
67
+ When I run "rspec spec/account_spec.rb"
68
+ Then the output should contain "1 example, 0 failures"
69
+
70
+ Scenario: provide a return value
71
+ Given a file named "message_expectation_spec.rb" with:
72
+ """
73
+ describe "a message expectation" do
74
+ context "with a return value" do
75
+ context "specified in a block" do
76
+ it "returns the specified value" do
77
+ receiver = double("receiver")
78
+ receiver.should_receive(:message) { :return_value }
79
+ receiver.message.should eq(:return_value)
80
+ end
81
+ end
82
+
83
+ context "specified with and_return" do
84
+ it "returns the specified value" do
85
+ receiver = double("receiver")
86
+ receiver.should_receive(:message).and_return(:return_value)
87
+ receiver.message.should eq(:return_value)
88
+ end
89
+ end
90
+ end
91
+ end
92
+ """
93
+ When I run "rspec message_expectation_spec.rb"
94
+ Then the output should contain "2 examples, 0 failures"
@@ -1,4 +1,4 @@
1
- Feature: warn when expectation is set on nil
1
+ Feature: Warn when expectation is set on nil
2
2
 
3
3
  Scenario: nil instance variable
4
4
  Given a file named "example_spec.rb" with:
@@ -1,4 +1,4 @@
1
- Feature: configure a test frawework to use rspec-mocks
1
+ Feature: Configure any test framework to use rspec-mocks
2
2
 
3
3
  Test frameworks that want to use rspec-mocks can use
4
4
  RSpec::Mocks::setup(self) to hook into rspec-mocks. Doing so adds the
@@ -0,0 +1,55 @@
1
+ Feature: Stub with simple return value
2
+
3
+ Use the stub() method on a test double or a real object to tell the object to
4
+ return a value (or values) in response to a given message. If the message is
5
+ never received, nothing happens.
6
+
7
+ Scenario: simple stub with no return value
8
+ Given a file named "example_spec.rb" with:
9
+ """
10
+ describe "a simple stub with no return value specified" do
11
+ let(:receiver) { double("receiver") }
12
+
13
+ it "returns nil" do
14
+ receiver.stub(:message)
15
+ receiver.message.should be(nil)
16
+ end
17
+
18
+ it "quietly carries on when not called" do
19
+ receiver.stub(:message)
20
+ end
21
+ end
22
+ """
23
+ When I run "rspec example_spec.rb"
24
+ Then the output should contain "0 failures"
25
+
26
+ Scenario: single return value
27
+ Given a file named "example_spec.rb" with:
28
+ """
29
+ describe "a simple stub with a return value" do
30
+ context "specified in a block" do
31
+ it "returns the specified value" do
32
+ receiver = double("receiver")
33
+ receiver.stub(:message) { :return_value }
34
+ receiver.message.should eq(:return_value)
35
+ end
36
+ end
37
+
38
+ context "specified in the double declaration" do
39
+ it "returns the specified value" do
40
+ receiver = double("receiver", :message => :return_value)
41
+ receiver.message.should eq(:return_value)
42
+ end
43
+ end
44
+
45
+ context "specified with and_return" do
46
+ it "returns the specified value" do
47
+ receiver = double("receiver")
48
+ receiver.stub(:message).and_return(:return_value)
49
+ receiver.message.should eq(:return_value)
50
+ end
51
+ end
52
+ end
53
+ """
54
+ When I run "rspec example_spec.rb"
55
+ Then the output should contain "0 failures"
@@ -1,4 +1,4 @@
1
- Feature: stub_chain
1
+ Feature: Stub a chain of methods
2
2
 
3
3
  The stub_chain method lets you to stub a chain of methods in one statement.
4
4
  Method chains are considered a design smell, but it's not really the method
@@ -1,15 +1,11 @@
1
- Feature: stub implementation
1
+ Feature: Stub with substitute implementation
2
2
 
3
- As an rspec user, I want to stub a complete implementation, not just a
4
- return value.
3
+ You can stub an implementation of a method (a.k.a. fake) by passing a block
4
+ to the stub() method.
5
5
 
6
6
  Scenario: stub implementation
7
7
  Given a file named "stub_implementation_spec.rb" with:
8
8
  """
9
- RSpec.configure do |c|
10
- c.mock_with :rspec
11
- end
12
-
13
9
  describe "a stubbed implementation" do
14
10
  it "works" do
15
11
  object = Object.new
@@ -21,8 +17,8 @@ Feature: stub implementation
21
17
  end
22
18
  end
23
19
 
24
- object.foo(:this).should == "got this"
25
- object.foo(:that).should == "got that"
20
+ object.foo(:this).should eq("got this")
21
+ object.foo(:that).should eq("got that")
26
22
  end
27
23
  end
28
24
  """
@@ -1,7 +1,7 @@
1
1
  module RSpec # :nodoc:
2
2
  module Mocks # :nodoc:
3
3
  module Version # :nodoc:
4
- STRING = '2.0.0.rc'
4
+ STRING = '2.0.0'
5
5
  end
6
6
  end
7
7
  end
@@ -88,7 +88,14 @@ module RSpec
88
88
  @mock.rspec_verify
89
89
  end
90
90
 
91
- it "returns nil if no return value set" do
91
+ it "returns the previously stubbed value if no return value is set" do
92
+ @mock.stub!(:something).with("a","b","c").and_return(:stubbed_value)
93
+ @mock.should_receive(:something).with("a","b","c")
94
+ @mock.something("a","b","c").should == :stubbed_value
95
+ @mock.rspec_verify
96
+ end
97
+
98
+ it "returns nil if no return value is set and there is no previously stubbed value" do
92
99
  @mock.should_receive(:something).with("a","b","c")
93
100
  @mock.something("a","b","c").should be_nil
94
101
  @mock.rspec_verify
@@ -144,9 +151,11 @@ module RSpec
144
151
  }.to raise_error(RSpec::Mocks::MockExpectationError, /Double \"test double\" received :something but passed block failed with: expected false to be true/)
145
152
  end
146
153
 
147
- it "passes block to expectation block" do
154
+ it "passes block to expectation block", :ruby => '> 1.8.6' do
148
155
  a = nil
149
- @mock.should_receive(:something) { |&block| a = block }
156
+ # We eval this because Ruby 1.8.6's syntax parser barfs on { |&block| ... }
157
+ # and prevents the entire spec suite from running.
158
+ eval("@mock.should_receive(:something) { |&block| a = block }")
150
159
  b = lambda { }
151
160
  @mock.something(&b)
152
161
  a.should == b
@@ -38,4 +38,15 @@ RSpec.configure do |config|
38
38
  config.color_enabled = true
39
39
  config.extend(Macros)
40
40
  config.include(RSpec::Mocks::Methods)
41
+
42
+ config.filter_run_excluding :ruby => lambda {|version|
43
+ case version.to_s
44
+ when "!jruby"
45
+ RUBY_ENGINE != "jruby"
46
+ when /^> (.*)/
47
+ !(RUBY_VERSION.to_s > $1)
48
+ else
49
+ !(RUBY_VERSION.to_s =~ /^#{version.to_s}/)
50
+ end
51
+ }
41
52
  end
metadata CHANGED
@@ -1,14 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-mocks
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7712058
5
- prerelease: true
4
+ prerelease: false
6
5
  segments:
7
6
  - 2
8
7
  - 0
9
8
  - 0
10
- - rc
11
- version: 2.0.0.rc
9
+ version: 2.0.0
12
10
  platform: ruby
13
11
  authors:
14
12
  - David Chelimsky
@@ -17,43 +15,39 @@ autorequire:
17
15
  bindir: bin
18
16
  cert_chain: []
19
17
 
20
- date: 2010-10-04 00:00:00 -05:00
18
+ date: 2010-10-10 00:00:00 -05:00
21
19
  default_executable:
22
20
  dependencies:
23
21
  - !ruby/object:Gem::Dependency
24
- version_requirements: &id001 !ruby/object:Gem::Requirement
22
+ name: rspec-core
23
+ requirement: &id001 !ruby/object:Gem::Requirement
25
24
  none: false
26
25
  requirements:
27
26
  - - "="
28
27
  - !ruby/object:Gem::Version
29
- hash: 7712058
30
28
  segments:
31
29
  - 2
32
30
  - 0
33
31
  - 0
34
- - rc
35
- version: 2.0.0.rc
36
- requirement: *id001
32
+ version: 2.0.0
37
33
  type: :runtime
38
- name: rspec-core
39
34
  prerelease: false
35
+ version_requirements: *id001
40
36
  - !ruby/object:Gem::Dependency
41
- version_requirements: &id002 !ruby/object:Gem::Requirement
37
+ name: rspec-expectations
38
+ requirement: &id002 !ruby/object:Gem::Requirement
42
39
  none: false
43
40
  requirements:
44
41
  - - "="
45
42
  - !ruby/object:Gem::Version
46
- hash: 7712058
47
43
  segments:
48
44
  - 2
49
45
  - 0
50
46
  - 0
51
- - rc
52
- version: 2.0.0.rc
53
- requirement: *id002
47
+ version: 2.0.0
54
48
  type: :runtime
55
- name: rspec-expectations
56
49
  prerelease: false
50
+ version_requirements: *id002
57
51
  description: RSpec's 'test double' framework, with support for stubbing and mocking
58
52
  email: dchelimsky@gmail.com;chad.humphries@gmail.com
59
53
  executables: []
@@ -74,9 +68,11 @@ files:
74
68
  - autotest/discover.rb
75
69
  - cucumber.yml
76
70
  - features/README.markdown
77
- - features/configuration.feature
78
- - features/mocks/block_local_expectations.feature
79
- - features/mocks/warn_when_expectation_is_set_on_nil.feature
71
+ - features/message_expectations/block_local_expectations.feature.pending
72
+ - features/message_expectations/expect_message.feature
73
+ - features/message_expectations/warn_when_expectation_is_set_on_nil.feature
74
+ - features/outside_rspec/configuration.feature
75
+ - features/stubs/simple_return_value.feature
80
76
  - features/stubs/stub_chain.feature
81
77
  - features/stubs/stub_implementation.feature
82
78
  - features/support/env.rb
@@ -159,33 +155,33 @@ required_ruby_version: !ruby/object:Gem::Requirement
159
155
  requirements:
160
156
  - - ">="
161
157
  - !ruby/object:Gem::Version
162
- hash: 3
158
+ hash: -3165430952158630133
163
159
  segments:
164
160
  - 0
165
161
  version: "0"
166
162
  required_rubygems_version: !ruby/object:Gem::Requirement
167
163
  none: false
168
164
  requirements:
169
- - - ">"
165
+ - - ">="
170
166
  - !ruby/object:Gem::Version
171
- hash: 25
167
+ hash: -3165430952158630133
172
168
  segments:
173
- - 1
174
- - 3
175
- - 1
176
- version: 1.3.1
169
+ - 0
170
+ version: "0"
177
171
  requirements: []
178
172
 
179
173
  rubyforge_project: rspec
180
174
  rubygems_version: 1.3.7
181
175
  signing_key:
182
176
  specification_version: 3
183
- summary: rspec-mocks-2.0.0.rc
177
+ summary: rspec-mocks-2.0.0
184
178
  test_files:
185
179
  - features/README.markdown
186
- - features/configuration.feature
187
- - features/mocks/block_local_expectations.feature
188
- - features/mocks/warn_when_expectation_is_set_on_nil.feature
180
+ - features/message_expectations/block_local_expectations.feature.pending
181
+ - features/message_expectations/expect_message.feature
182
+ - features/message_expectations/warn_when_expectation_is_set_on_nil.feature
183
+ - features/outside_rspec/configuration.feature
184
+ - features/stubs/simple_return_value.feature
189
185
  - features/stubs/stub_chain.feature
190
186
  - features/stubs/stub_implementation.feature
191
187
  - features/support/env.rb