In quantum mechanics, the spin of a particle corresponds to a magnetic moment - and so a particle in a magnetic field gradient, e.g. a Stern-Gerlach experiment will have its spin measured by the magnetic field.
Furthermore, measurements in quantum mechanics collapse of the quantum state of the system, irrespective of whether a sentient being is there to watch it happen. So, if you have a box opaque to all EM radiation (so we cannot "see" inside) which contains a Young's Double slit experiment and a fully robotic sensor on one of the slits, you will not see an interference pattern when you check the results of the experiment after it is complete.
My question is the following:
Take a spin $\frac{1}{2}$ particle. We know from quantum mechanics, the possible values of its spin along any axis are $\hbar/2$ or $-\hbar/2$.
Can the spin of this particle be measured, and will the wavefunction collapse, due to an arbitrarily small $B$-field gradient? If so, then shouldn't the spin of every particle being measured always be due to the fact that $B$-fields extent to infinity, so the nearest bar magnet, MRI machine, star, etc. will always have an effect on a quantum system?
So often textbooks say something like "prepare a spin $\frac{1}{2}$ particle in a state $|\uparrow\rangle$ and shoot it through a Stern-Gerlach experiment" - but as soon as this state is prepared, its spin will be measured by countless external $B$-fields giving $\hbar/2$s or $-\hbar/2$s in a bunch of random directions and so your state is ruined.
My guess is that the examples given in an introductory QM course are, like a lot of things, a simplification. Any explanation would be appreciated though.