Skip to content

Instantly share code, notes, and snippets.

@wincent
Created July 3, 2010 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wincent/462638 to your computer and use it in GitHub Desktop.
Save wincent/462638 to your computer and use it in GitHub Desktop.
From cffa1be105cc94c2e886c5fb59e490da08293373 Mon Sep 17 00:00:00 2001
From: Wincent Colaiuta <win@wincent.com>
Date: Sat, 3 Jul 2010 17:31:02 +0200
Subject: [PATCH] WIP
---
features/compatibility.feature | 36 ++++++++++++++++++++++++++++++++++++
lib/rspec/mocks.rb | 2 +-
2 files changed, 37 insertions(+), 1 deletions(-)
create mode 100644 features/compatibility.feature
diff --git a/features/compatibility.feature b/features/compatibility.feature
new file mode 100644
index 0000000..b1bd2ca
--- /dev/null
+++ b/features/compatibility.feature
@@ -0,0 +1,36 @@
+Feature: compatibility with other mocking libraries
+
+ As an RSpec user
+ I want RSpec mocks to keep the global namespace clean
+ So that I am free to use other mocking libraries
+
+ Scenario: not using rspec-mocks
+ Given a file named "spec/global_namespace_spec.rb" with:
+ """
+ # global namespace should be clean even with this require:
+ require 'rspec/mocks'
+
+ RSpec.configure do |config|
+ config.mock_framework = :none
+ end
+
+ describe 'the global namespace' do
+ it "doesn't include RSpec mocking methods by default" do
+ lambda { Object.should_receive :foo }.should raise_error(NoMethodError)
+ end
+ end
+ """
+ When I run "rspec ./spec/global_namespace_spec.rb"
+ Then I should see "1 example, 0 failures"
+
+ Scenario: using rspec-mocks
+ Given a file named "spec/global_namespace_spec.rb" with:
+ """
+ describe 'the global namespace' do
+ it "includes RSpec mocking methods by default" do
+ Object.should respond_to(:should_receive)
+ end
+ end
+ """
+ When I run "rspec ./spec/global_namespace_spec.rb"
+ Then I should see "1 example, 0 failures"
diff --git a/lib/rspec/mocks.rb b/lib/rspec/mocks.rb
index b031087..6cc2359 100644
--- a/lib/rspec/mocks.rb
+++ b/lib/rspec/mocks.rb
@@ -1,5 +1,4 @@
require 'rspec/mocks/framework'
-require 'rspec/mocks/extensions/object'
require 'rspec/mocks/version'
module RSpec
@@ -177,6 +176,7 @@ module RSpec
attr_accessor :space
def setup
+ require 'rspec/mocks/extensions/object'
self.space ||= RSpec::Mocks::Space.new
end
--
1.7.1.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment