diff --git a/lib/rspec/core.rb b/lib/rspec/core.rb index 087e0713f7..126f17e06c 100644 --- a/lib/rspec/core.rb +++ b/lib/rspec/core.rb @@ -129,37 +129,10 @@ def self.current_example=(example) RSpec::Support.thread_local_data[:current_example] = example end - class ScopeSymbol - # @api private - EXAMPLE_CONTEXT = [:before_each_hook, :example, :after_each_hook] - - # @api private - # Used whenever you set RSpec.current_scope = :something - def self.wrap(thing) - thing.is_a?(self) ? thing : new(thing) - end - - # @private - def initialize(sym) - raise ArgumentError, "I only wrap symbols" unless sym.is_a?(Symbol) || sym.nil? - @sym = sym - end - - # Allows comparisons w/ real symbols - def ==(other) - @sym == other - end - - # Find out whether you're in the execution context of a single example (either before, during or after) - def in_example_context? - EXAMPLE_CONTEXT.include?(@sym) - end - end - # Set the current scope rspec is executing in # @api private def self.current_scope=(scope) - RSpec::Support.thread_local_data[:current_scope] = ScopeSymbol.wrap(scope) + RSpec::Support.thread_local_data[:current_scope] = scope end RSpec.current_scope = :suite @@ -173,7 +146,7 @@ def self.current_scope=(scope) # Returns `:example` inside it/example blocks # # Returns `nil` after your suite and all hooks are done - # @return [ScopeSymbol/Nil] + # @return [Symbol/Nil] def self.current_scope RSpec::Support.thread_local_data[:current_scope] end diff --git a/spec/rspec/core_spec.rb b/spec/rspec/core_spec.rb index 91a1e3e117..8d01a03b50 100644 --- a/spec/rspec/core_spec.rb +++ b/spec/rspec/core_spec.rb @@ -134,58 +134,44 @@ raise "bad current scope: #{RSpec.current_scope.inspect}" end - if RSpec.current_scope.in_example_context? - raise "this is not an example context" - end - RSpec.configure do |c| c.before :suite do expect(RSpec.current_scope).to eq(:before_suite_hook) - expect(RSpec.current_scope.in_example_context?).to eq(false) end c.before :all do expect(RSpec.current_scope).to eq(:before_all_hook) - expect(RSpec.current_scope.in_example_context?).to eq(false) end c.before :each do expect(RSpec.current_scope).to eq(:before_each_hook) - expect(RSpec.current_scope.in_example_context?).to eq(true) end c.around :each do |ex| expect(RSpec.current_scope).to eq(:before_each_hook) - expect(RSpec.current_scope.in_example_context?).to eq(true) ex.run - expect(RSpec.current_scope.in_example_context?).to eq(true) expect(RSpec.current_scope).to eq(:after_each_hook) end c.after :each do expect(RSpec.current_scope).to eq(:after_each_hook) - expect(RSpec.current_scope.in_example_context?).to eq(true) end c.after :all do expect(RSpec.current_scope).to eq(:after_all_hook) - expect(RSpec.current_scope.in_example_context?).to eq(false) end c.after :suite do expect(RSpec.current_scope).to eq(:after_suite_hook) - expect(RSpec.current_scope.in_example_context?).to eq(false) end end before :all do - expect(RSpec.current_scope.in_example_context?).to eq(false) expect(RSpec.current_scope).to eq(:before_all_hook) end before :each do expect(RSpec.current_scope).to eq(:before_each_hook) - expect(RSpec.current_scope.in_example_context?).to eq(true) end around :each do |ex| @@ -195,23 +181,19 @@ end after :each do - expect(RSpec.current_scope.in_example_context?).to eq(true) expect(RSpec.current_scope).to eq(:after_each_hook) end after :all do expect(RSpec.current_scope).to eq(:after_all_hook) - expect(RSpec.current_scope.in_example_context?).to eq(false) end it "returns :example inside an example" do expect(RSpec.current_scope).to eq(:example) - expect(RSpec.current_scope.in_example_context?).to eq(true) end it "works for more than one example in a describe block" do expect(RSpec.current_scope).to eq(:example) - expect(RSpec.current_scope.in_example_context?).to eq(true) end end