Permalink
Browse files

Added "rspec/mocks/standalone"

- useful in irb to explore the framework
- also eliminated two require calls per example when using rspec-mocks
  with rspec-core - huge performance boost (20% range)
  • Loading branch information...
dchelimsky committed Nov 19, 2010
1 parent beffc1e commit be136a4402bbb8508b82380e8fc1089c0fb300a6
View
@@ -1,5 +1,12 @@
## rspec-mocks release history (incomplete)
+### 2.2.0 / in development
+
+[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.1.0...v2.2.0)
+
+* Enhancements
+ * Added "rspec/mocks/standalone" for exploring the rspec-mocks in irb.
+
### 2.1.0 / 2010-11-07
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.0.1...v2.1.0)
View
@@ -0,0 +1,14 @@
+# rspec-mocks-2.2
+
+## What's new
+
+### `require "rspec/mocks/standalone"`
+
+Sets up top-level environment to explore rspec-mocks. Mostly useful in irb:
+
+ $ irb
+ > require 'rspec/mocks/standalone'
+ > foo = double()
+ > foo.stub(:bar) { :baz }
+ > foo.bar
+ => :baz
@@ -0,0 +1,32 @@
+Feature: standalone
+
+ require "rspec/mocks/standalone" to expose the mock framework
+ outside the RSpec environment. This is especially useful for
+ exploring rspec-mocks in irb.
+
+ Scenario: stub outside rspec
+ Given a file named "example.rb" with:
+ """
+ require "rspec/mocks/standalone"
+
+ greeter = double("greeter")
+ greeter.stub(:say_hi) { "Hello!" }
+ puts greeter.say_hi
+ """
+ When I run "ruby example.rb"
+ Then the output should contain "Hello!"
+
+ Scenario: message expectation outside rspec
+ Given a file named "example.rb" with:
+ """
+ require "rspec/mocks/standalone"
+
+ greeter = double("greeter")
+ greeter.should_receive(:say_hi)
+
+ RSpec::Mocks.verify
+ """
+ When I run "ruby example.rb"
+ Then the output should contain "say_hi(any args) (RSpec::Mocks::MockExpectationError)"
+ Then the output should contain "expected: 1 time"
+ Then the output should contain "received: 0 times"
View
@@ -1,5 +1,6 @@
require 'rspec/mocks/framework'
require 'rspec/mocks/version'
+require 'rspec/mocks/spec_methods'
module RSpec
# == Test Doubles
@@ -176,8 +177,7 @@ class << self
attr_accessor :space
def setup(includer)
- require 'rspec/mocks/extensions/object'
- require 'rspec/mocks/spec_methods'
+ Object.class_eval { include RSpec::Mocks::Methods } unless Object < RSpec::Mocks::Methods
(class << includer; self; end).class_eval do
include RSpec::Mocks::ExampleMethods
end
@@ -1,3 +0,0 @@
-class Object
- include RSpec::Mocks::Methods
-end
@@ -0,0 +1,3 @@
+require 'rspec/mocks'
+
+RSpec::Mocks.setup(self)

0 comments on commit be136a4

Please sign in to comment.