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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to