Today I decided to experiment with skipping navbar rendering in our feature spec suite to reduce CI runtime. Our navbar is a 400-line template with dozens of permission checks, and even with the permissions all stubbed to true, it takes a moment just to produce the HTML. The navbar itself is rarely used - some specs assert that navbar has desired elements and navigation works, but generally we visit
straight to the desired page.
For our 20-minute CI run I expect a 2-4% reduction in runtime, that's 20-40s, every bit helps.
The setup is easy:
- Create an alternate navbar partial and put an
if ENV["SKIP_NAVBAR"] == "true"
thereabouts - Define a hook that disables navbar by default, but allows opting back into rendering as needed:
# This hook disables navbar rendering in feature specs by default.
# Set `skip_navbar: false` metadata to render where necessary.
RSpec.configure do |config|
config.before(:each, type: :feature) do |example|
ENV["SKIP_NAVBAR"] = "true" unless example.metadata[:skip_navbar] == false
end
config.after(:each, type: :feature) do
ENV["SKIP_NAVBAR"] = nil
end
end