If you tag your examples with something that requires this setup, then declare 
a context level hook, the setup will be run before example contexts (`describe` 
and `context` blocks) that will require it, if your code uses a circuit breaker 
this can mean it is only run once per suite.

```
`# in your spec_helper.rb
module ExpensiveSetup
  module_function
  def perform
    @perform ||=
      begin
        # expensive setup
      end
   end
end

RSpec.configure do |config|
  config.before(:context, :expensive_elastic_search_setup => true) do
    ExpensiveSetup.perform
`  end
end

`# in your specs
RSpec.describe "some tricky search stuff", :expensive_elastic_search_setup => 
true do
` # ...
end
```

On Mon, 15 Aug 2022, at 3:27 PM, sshaw wrote:
> I need to perform costly Elasticsearch-specific setup  when it's being 
> targeted. If one is explicitly excluding it then no need for it. 
> 
> On Tuesday, July 19, 2022 at 2:23:01 PM UTC-4 [email protected] wrote:
>> 
>> Hi Skye,
>> 
>> Can you describe your use case, why would examples need to know that?
>> 
>> - Phil
>> 
>>> On 19 Jul 2022, at 19:57, sshaw <[email protected]> wrote:
>>> If one calls with: 
>>> 
>>>     rspec -t ~foo
>>> 
>>> Is it possible to determine from the spec code, in or out of an example, 
>>> that the current invocation specifies running examples without the foo tag?
>>> 
>>> I have looked at doing this at the example level via the 
>>> RSpec::Core::Example instance passed to the block as well as poking around 
>>> in RSpec.configuration but cannot find that foo tag has been excluded. Is 
>>> it even possible? 
>>> 
>>> Thanks
>>> 
>>> 
>>> 
>>> 
>>> -- 
>>> You received this message because you are subscribed to the Google Groups 
>>> "rspec" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an 
>>> email to [email protected].
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/rspec/bc6d474c-d4ac-49b1-ad46-4fb278d1e6c1n%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/rspec/bc6d474c-d4ac-49b1-ad46-4fb278d1e6c1n%40googlegroups.com?utm_medium=email&utm_source=footer>.
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "rspec" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/rspec/ceeff597-7d88-42c9-bc7c-39f400f0c5f5n%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/rspec/ceeff597-7d88-42c9-bc7c-39f400f0c5f5n%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rspec/2cb650bb-8a85-49be-9877-6cade05daa39%40www.fastmail.com.

Reply via email to