Skip to content

Commit 615fd99

Browse files
committed
fix(test): wrap flaky homepage tests in travel_to blocks
Fix time-dependent flaky tests by wrapping scenarios in travel_to blocks. The issue was that fabricator timestamps are evaluated at file load time, while the upcoming scope compares against Time.zone.now at query time. When time passes between fixture creation and page visit, events may be filtered out incorrectly. This follows the same pattern as commit 3f44835 which fixed similar flaky tests in other files.
1 parent 3b7170e commit 615fd99

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

spec/features/visiting_homepage_spec.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
let!(:next_workshop) { Fabricate(:workshop) }
33
let!(:events) { Fabricate.times(3, :event) }
44

5-
before(:each) do
5+
before do
66
visit root_path
77
end
88

@@ -11,11 +11,15 @@
1111
end
1212

1313
scenario 'i can view the next workshop' do
14-
expect(page).to have_content "Workshop at #{next_workshop.host.name}"
14+
travel_to(Time.current) do
15+
expect(page).to have_content "Workshop at #{next_workshop.host.name}"
16+
end
1517
end
1618

1719
scenario 'i can view the next 5 upcoming events' do
18-
events.take(5).each { |event| expect(page).to have_content "#{event.name} at #{event.venue.name}" }
20+
travel_to(Time.current) do
21+
events.take(5).each { |event| expect(page).to have_content "#{event.name} at #{event.venue.name}" }
22+
end
1923
end
2024

2125
scenario 'i can access the code of conduct' do
@@ -37,7 +41,7 @@
3741
end
3842

3943
inactive_chapters.each do |chapter|
40-
expect(page).to_not have_content(chapter.name)
44+
expect(page).not_to have_content(chapter.name)
4145
end
4246
end
4347

0 commit comments

Comments
 (0)