Skip to content

Commit

Permalink
Added "rspec/mocks/standalone"
Browse files Browse the repository at this point in the history
- 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 be136a4
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 5 deletions.
7 changes: 7 additions & 0 deletions History.markdown
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,12 @@
## rspec-mocks release history (incomplete) ## 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 ### 2.1.0 / 2010-11-07


[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.0.1...v2.1.0) [full changelog](http://github.com/rspec/rspec-mocks/compare/v2.0.1...v2.1.0)
Expand Down
14 changes: 14 additions & 0 deletions Upgrade.markdown
Original file line number Original file line Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions features/outside_rspec/standalone.feature
Original file line number Original file line Diff line number Diff line change
@@ -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"
4 changes: 2 additions & 2 deletions lib/rspec/mocks.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'rspec/mocks/framework' require 'rspec/mocks/framework'
require 'rspec/mocks/version' require 'rspec/mocks/version'
require 'rspec/mocks/spec_methods'


module RSpec module RSpec
# == Test Doubles # == Test Doubles
Expand Down Expand Up @@ -176,8 +177,7 @@ class << self
attr_accessor :space attr_accessor :space


def setup(includer) def setup(includer)
require 'rspec/mocks/extensions/object' Object.class_eval { include RSpec::Mocks::Methods } unless Object < RSpec::Mocks::Methods
require 'rspec/mocks/spec_methods'
(class << includer; self; end).class_eval do (class << includer; self; end).class_eval do
include RSpec::Mocks::ExampleMethods include RSpec::Mocks::ExampleMethods
end end
Expand Down
3 changes: 0 additions & 3 deletions lib/rspec/mocks/extensions/object.rb

This file was deleted.

3 changes: 3 additions & 0 deletions lib/rspec/mocks/standalone.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,3 @@
require 'rspec/mocks'

RSpec::Mocks.setup(self)

0 comments on commit be136a4

Please sign in to comment.