Skip to content

Commit

Permalink
pull in spec helper material from rspec-core
Browse files Browse the repository at this point in the history
  • Loading branch information
dchelimsky committed May 11, 2010
1 parent ccb61c5 commit 9e21b65
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
4 changes: 0 additions & 4 deletions spec/rspec/rails/example/view_rendering_spec.rb
Expand Up @@ -64,9 +64,5 @@
group.run(double.as_null_object)
rendering_views.should be_true
end

after do
Rspec::Core::world.example_groups.pop
end
end

18 changes: 17 additions & 1 deletion spec/spec_helper.rb
Expand Up @@ -3,11 +3,27 @@

require 'rspec/rails'

Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}

# TODO - most of this is borrowed from rspec-core's spec_helper - should
# be extracted to something we can use here
def in_editor?
ENV.has_key?('TM_MODE') || ENV.has_key?('EMACS') || ENV.has_key?('VIM')
end

class Rspec::Core::ExampleGroup
def self.run_all(reporter=nil)
run(reporter || Rspec::Mocks::Mock.new('reporter').as_null_object)
end
end

Rspec.configure do |c|
c.color_enabled = !in_editor?
c.before(:each) do
@real_world = Rspec.world
Rspec.instance_variable_set(:@world, Rspec::Core::World.new)
end
c.after(:each) do
Rspec.instance_variable_set(:@world, @real_world)
end
end

20 changes: 20 additions & 0 deletions spec/support/helpers.rb
@@ -0,0 +1,20 @@
module Helpers
def stub_metadata(additional_metadata)
stub_metadata = metadata_with(additional_metadata)
Rspec::Core::ExampleGroup.stub(:metadata) { stub_metadata }
end

def metadata_with(additional_metadata)
m = Rspec::Core::Metadata.new
m.process("example group")

group_metadata = additional_metadata.delete(:example_group)
if group_metadata
m[:example_group].merge!(group_metadata)
end
m.merge!(additional_metadata)
m
end

Rspec.configure {|c| c.include self}
end

0 comments on commit 9e21b65

Please sign in to comment.