Permalink
Browse files

expose matcher DSL to example groups for scoped matchers

  • Loading branch information...
1 parent b557c2d commit 62377e2b228c8f99581d10860a503fb8a4b014ce @dchelimsky dchelimsky committed Jul 27, 2010
Showing with 44 additions and 4 deletions.
  1. +40 −4 features/matchers/define_matcher.feature
  2. +4 −0 lib/rspec/matchers/dsl.rb
View
44 features/matchers/define_matcher.feature
@@ -191,7 +191,7 @@ Feature: define matcher
Then the exit status should be 0
And the stdout should contain "1 example, 0 failures"
- Scenario: scoped
+ Scenario: scoped in a module
Given a file named "scoped_matcher_spec.rb" with:
"""
require 'rspec/expectations'
@@ -207,16 +207,52 @@ Feature: define matcher
describe "group with MyHelpers" do
include MyHelpers
it "has access to the defined matcher" do
- self.should respond_to(:be_just_like)
+ 5.should be_just_like(5)
end
end
describe "group without MyHelpers" do
it "does not have access to the defined matcher" do
- self.should_not respond_to(:be_just_like)
+ expect do
+ 5.should be_just_like(5)
+ end.to raise_exception
end
end
"""
When I run "rspec ./scoped_matcher_spec.rb"
- Then the stdout should contain "1 failure"
+ Then the stdout should contain "2 examples, 0 failures"
+
+ Scenario: scoped in an example group
+ Given a file named "scoped_matcher_spec.rb" with:
+ """
+ require 'rspec/expectations'
+
+ describe "group with matcher" do
+ matcher :be_just_like do |expected|
+ match {|actual| actual == expected}
+ end
+
+ it "has access to the defined matcher" do
+ 5.should be_just_like(5)
+ end
+
+ describe "nested group" do
+ it "has access to the defined matcher" do
+ 5.should be_just_like(5)
+ end
+ end
+
+ end
+
+ describe "group without matcher" do
+ it "does not have access to the defined matcher" do
+ expect do
+ 5.should be_just_like(5)
+ end.to raise_exception
+ end
+ end
+ """
+
+ When I run "rspec scoped_matcher_spec.rb"
+ Then the output should contain "3 examples, 0 failures"
View
4 lib/rspec/matchers/dsl.rb
@@ -10,6 +10,10 @@ def define(name, &declarations)
end
alias_method :matcher, :define
+
+ if RSpec.respond_to?(:configure)
+ RSpec.configure {|c| c.extend self}
+ end
end
end
end

0 comments on commit 62377e2

Please sign in to comment.