That works, or you can use `RSpec::Mocks.with_temporary_scope { ... }` to
create a scope for use within your `before(:all)` hook.  See this for more
information:

https://relishapp.com/rspec/rspec-mocks/v/3-7/docs/basics/scope#use-%60with-temporary-scope%60-to-create-and-use-a-double-in-a-%60before(:context)%60-hook

On Tue, Jul 3, 2018 at 7:00 AM belgoros <[email protected]> wrote:

> I figured out after reading the docs
> <https://relishapp.com/rspec/rspec-core/v/3-7/docs/hooks/before-and-after-hooks>
> :
>
> Mocks are only supported in before(:example).
>
> So the only way to get it working is to use
> before(:example)
>
>   hook.
>
> Hope this helps.
>
> On Tuesday, 3 July 2018 15:53:41 UTC+2, belgoros wrote:
>>
>> If is not supported, what is the right way to mock an object once before
>> all the examples ?
>>
>>
>> Here is what I tried to do and failed:
>>
>> describe '#build_working_hour' do
>>
>>   context "for open status" do
>>       before(:all) do
>>         @schedule = double(MystoreMigration::StoreSchedule, am_start_time
>> : 900, pm_end_time: 2030)
>>         allow(@schedule).to receive(:has_divided_hours?).and_return(false
>> )
>>         allow(@schedule).to receive(:closed?).and_return(false)
>>         @working_hour = store_migrator.build_working_hour(schedule)
>>       end
>>
>>
>>       it 'should init working hour with open status' do
>>         expect(@working_hour.open?).to be_truthy
>>       end
>>
>>
>>       it 'should init working hour with open status times' do
>>         expect(@working_hour.opens).to eq(32_400_000)
>>         expect(@working_hour.closes).to eq(73_800_000)
>>         expect(@working_hour.divided_opens).to be nil
>>         expect(@working_hour.divided_closes).to be nil
>>       end
>>     end
>> end
>>
>>
>> What is wrong with the above approach ? I'd like to 1) check a status, 2)
>> the assigned values. Thank you!
>>
> --
> 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 post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rspec/88c810fd-bc60-46ba-8ff2-22ef1e16e08a%40googlegroups.com
> <https://groups.google.com/d/msgid/rspec/88c810fd-bc60-46ba-8ff2-22ef1e16e08a%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rspec/CADUxQmtz%3DJZBBsc_kxu_Yg64N1bJVLxp2XuQB1AU3HVrsDkxRw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to