Weak problem formulation for PDE and boundary conditions Consider the following example:
$$
- \Delta u = f \mbox{ in } \Omega,
$$
$$
u = 0 \mbox{ on } \Gamma,
$$
Here $\Gamma$ is boundary of $\Omega$.
To produce weak formulation we multiply by arbitrary $v$ from $H^1(\Omega)$, integrate over $\Omega$ and apply integration by parts:
$$
\int_{\Omega} \nabla u \nabla v dx - \int_{\Gamma} \frac{\partial u}{\partial n}vds = \int_{\Omega} f v dx.
$$
Because we don't have information about $\partial u /\partial n$ on $\Gamma$ we restrict $v$ to lie in $V = \{ v \in H^1(\Omega): v|_\Gamma = 0 \}$. This new constructed space may not be a complete, so we need to complete it with respect to Sobolev norm (Otherwise we won't be able to apply Lax–Milgram theorem and prove existence of weak solution). But after this procedure we may have functions in $V$ which violate boundary conditions $v|_\Gamma = 0$. Why after completion of $V$ with respect to Sobolev norm we won't run into functions $v|_\Gamma \neq 0$?  All textbooks I've consulted skip this moment, probably because it is obvious. 

So first of all, $H^1$ does not really have a restriction map, even to interior points, much less boundary points (except in one dimension, where there is a continuous embedding into $C^0$). The better way of thinking about this is to start out with smooth test functions, then look at the equation that you get and identify the solution space and the test function space appropriately. The spaces that you get in these two cases are denoted by $H^1_0$. This is essentially what we mean by $\{ f \in H^1 : \left. f \right |_\Gamma = 0 \}$. More formally it can be identified as either the completion of $C^\infty_c$ in $H^1$ or as the kernel of the map $T : H^1(\Omega) \to L^2(\Gamma)$ which is the continuous extension of the restriction map. This map is called the trace, and its existence requires a little bit of regularity about the boundary $\Gamma$. (As I recall Lipschitz is enough, but references like Evans tend to assume $C^1$ or at least piecewise $C^1$ to simplify the proof.)
