Skip to content

Commit

Permalink
Don't pollute Object's namespace. Closes GH-19
Browse files Browse the repository at this point in the history
  • Loading branch information
cavalle committed Nov 16, 2010
1 parent 3e2230f commit 61147a9
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/rspec-1/steak.rb
Expand Up @@ -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)
Expand Down
17 changes: 10 additions & 7 deletions lib/rspec-2/steak.rb
Expand Up @@ -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

26 changes: 26 additions & 0 deletions spec/acceptance/rspec-1/basic_spec.rb
Expand Up @@ -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
43 changes: 43 additions & 0 deletions spec/acceptance/rspec-2/basic_spec.rb
Expand Up @@ -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
Expand All @@ -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.