Permalink
Browse files

Don't pollute Object's namespace. Closes GH-19

  • Loading branch information...
1 parent 3e2230f commit 61147a9b4a72f947d55027b60aceb43b19654a97 @cavalle committed Nov 16, 2010
Showing with 81 additions and 9 deletions.
  1. +2 −2 lib/rspec-1/steak.rb
  2. +10 −7 lib/rspec-2/steak.rb
  3. +26 −0 spec/acceptance/rspec-1/basic_spec.rb
  4. +43 −0 spec/acceptance/rspec-2/basic_spec.rb
View
4 lib/rspec-1/steak.rb
@@ -3,8 +3,8 @@ module Spec::Example::ExampleGroupMethods
alias background before
end
-module Spec::DSL::Main
- alias feature describe
+class << self
+ alias feature describe
end
if defined?(Spec::Rails)
View
17 lib/rspec-2/steak.rb
@@ -9,14 +9,17 @@ def self.included(base)
end
end
end
-end
-module RSpec::Core::ObjectExtensions
- def feature(*args, &block)
- args << {} unless args.last.is_a?(Hash)
- args.last.update :type => :acceptance, :steak => true
- describe(*args, &block)
+ module DSL
+ def feature(*args, &block)
+ args << {} unless args.last.is_a?(Hash)
+ args.last.update :type => :acceptance, :steak => true, :caller => caller
+ describe(*args, &block)
+ end
end
end
-RSpec.configuration.include Steak::AcceptanceExampleGroup, :type => :acceptance
+extend Steak::DSL
+
+RSpec.configuration.include Steak::AcceptanceExampleGroup, :type => :acceptance
+
View
26 spec/acceptance/rspec-1/basic_spec.rb
@@ -47,4 +47,30 @@
output = run_spec spec_file
output.should =~ /1 example, 0 failures/
end
+
+ scenario "Steak should not pollute Object methods namespace" do
+ spec_file = create_spec <<-SPEC
+ require '#{File.dirname(__FILE__) + "/../../../lib/steak"}'
+
+ class Wadus
+ def call_feature
+ feature
+ end
+
+ def method_missing(meth, *args, &blk)
+ return "Hello!"
+ end
+ end
+
+ feature "Wadus class" do
+ scenario "should not be polluted by Steak" do
+ w = Wadus.new
+ w.should_not respond_to(:feature)
+ w.call_feature.should == "Hello!"
+ end
+ end
+ SPEC
+ output = run_spec spec_file
+ output.should =~ /1 example, 0 failures/
+ end
end
View
43 spec/acceptance/rspec-2/basic_spec.rb
@@ -55,6 +55,7 @@
scenario "should have acceptance metadata" do
example.metadata[:type].should == :acceptance
example.metadata[:steak].should be_true
+ example.metadata[:file_path].should == __FILE__
end
end
SPEC
@@ -75,4 +76,46 @@
output = run_spec spec_file
output.should =~ /1 example, 0 failures/
end
+
+ scenario "Feature-level file path metadata filtering" do
+ spec_file = create_spec <<-SPEC
+ require '#{File.dirname(__FILE__) + "/../../../lib/steak"}'
+ RSpec.configuration.before(:each, :example_group => {:file_path => __FILE__}) do
+ @executed = true
+ end
+ feature "Minimal spec" do
+ scenario "should have run the before block" do
+ @executed.should be_true
+ end
+ end
+ SPEC
+ output = run_spec spec_file
+ output.should =~ /1 example, 0 failures/
+ end
+
+ scenario "Steak should not pollute Object methods namespace" do
+ spec_file = create_spec <<-SPEC
+ require '#{File.dirname(__FILE__) + "/../../../lib/steak"}'
+
+ class Wadus
+ def call_feature
+ feature
+ end
+
+ def method_missing(meth, *args, &blk)
+ return "Hello!"
+ end
+ end
+
+ feature "Wadus class" do
+ scenario "should not be polluted by Steak" do
+ w = Wadus.new
+ w.should_not respond_to(:feature)
+ w.call_feature.should == "Hello!"
+ end
+ end
+ SPEC
+ output = run_spec spec_file
+ output.should =~ /1 example, 0 failures/
+ end
end

0 comments on commit 61147a9

Please sign in to comment.