Flux tube simulations of plasma turbulence in stellarators and tokamaks
typically employ coordinates which are aligned with the magnetic field lines.
Anisotropic turbulent fluctuations can be represented in such field-aligned
coordinates very efficiently, but the resulting non-trivial boundary conditions
involve all three spatial directions, and must be handled with care. The
standard "twist-and-shift" formulation of the boundary conditions [Beer,
Cowley, Hammett \textit{Phys. Plasmas} \textbf{2}, 2687 (1995)] was derived
assuming axisymmetry and is widely used because it is efficient, as long as the
global magnetic shear is not too small. A generalization of this formulation is
presented, appropriate for studies of non-axisymmetric, stellarator-symmetric
configurations, as well as for axisymmetric configurations with small global
shear. The key idea is to replace the "twist" of the standard approach (which
accounts only for global shear) with the integrated local shear. This
generalization allows one significantly more freedom when choosing the extent
of the simulation domain in each direction, without losing the natural
efficiency of field-line-following coordinates. It also corrects errors
associated with naive application of axisymmetric boundary conditions to
non-axisymmetric configurations. Simulations of stellarator turbulence that
employ the generalized boundary conditions require much less resolution than
simulations that use the (incorrect, axisymmetric) boundary conditions. We also
demonstrate the surprising result that (at least in some cases) an easily
implemented but manifestly incorrect formulation of the boundary conditions
does {\it not} change important predicted quantities, such as the turbulent
heat flux