Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: rspec/rspec-core
base: master
...
head fork: rspec/rspec-core
compare: limit_monkey_patching_of_describe
Checking mergeability… Don’t worry, you can still create the pull request.
  • 1 commit
  • 4 files changed
  • 0 commit comments
  • 1 contributor
Commits on Jun 16, 2012
@myronmarston myronmarston Don't add `describe` to every object.
Instead, make it only available on:
  - The main object--so it can be used at the top level.
  - Modules--so example groups can be declared nested
    within modules, as is the common practice.

Besides this, the only other place we need describe is from within
example groups (so we can nest them), and this is taken care of by
RSpec::Core::ExampleGroup.describe.

I got the idea for this from a recent change in Sinatra that similarly
limits the DSL to just the main object rather than all objects:

sinatra/sinatra@46bdb7d
b45c10e
View
2  Changelog.md
@@ -12,6 +12,8 @@ Enhancements
for background.
* thanks to Bradley Schaefer for suggesting it and Avdi Grimm for almost
suggesting it.
+* Limit monkey patching of `describe` onto just the objects
+ that need it rather than every object in the system (Myron Marston).
Bug fixes
View
7 lib/rspec/core/dsl.rb
@@ -21,4 +21,9 @@ def describe(*args, &example_group_block)
end
end
-include RSpec::Core::DSL
+# make describe available on the main object, but not all objects
+extend RSpec::Core::DSL
+
+# make describe available on modules so example groups
+# can be nested within them.
+Module.send(:include, RSpec::Core::DSL)
View
17 spec/rspec/core/dsl_spec.rb
@@ -0,0 +1,17 @@
+require 'spec_helper'
+
+main = self
+describe "The describe method" do
+ it 'is available on the main object' do
+ main.should respond_to(:describe)
+ end
+
+ it 'is available on modules (so example groups can be nested inside them)' do
+ Module.new.should respond_to(:describe)
+ end
+
+ it 'is not available on other types of objects' do
+ Object.new.should_not respond_to(:describe)
+ end
+end
+
View
3  spec/rspec/core/example_group_spec.rb
@@ -863,6 +863,9 @@ def metadata_hash(*args)
end
end
+ extend Forwardable
+ def_delegators "RSpec::Core::ExampleGroup", :describe
+
context "with all examples passing" do
it "returns true" do
group = describe("something") do

No commit comments for this range

Something went wrong with that request. Please try again.