ruby on rails - Rspec surrounding shared_example with timecop -
i trying wrap timecop around shared_example spec wrote
describe "timecop wrapping shared example" timecop.freeze(1.day.ago) it_behaves_like "a shared example test using timecop" end end shared_examples "a shared example test using timecop" before :all puts "the current time #{time.now}" end ... expect ... end but running spec still uses real time , not frozen one
can timecop work this?
how else can wrap large pieces of test file change time running
timecop needs execute within or before block.
the following change fix problem.
describe "timecop wrapping shared example" before { timecop.freeze(1.day.ago) } it_behaves_like "a shared example test using timecop" end
rspec reset environment(including timecop) after running each example.
a couple of tips i've found time travel in tests might useful:
Comments
Post a Comment