title: assigns() method vs Binding - Rails
body: <p>I'm new to Ruby on Rails world.</p>
  
  <p>I noticed there is at least one way to access controller instance variables from a test case.</p>
  
  <p>Indeed, suppose this test method: </p>
  
  <pre><code>test "should get index" do
      get :index
      assert_response :success
      assert_not_nil assigns(:products)
  end
  </code></pre>
  
  <p><code>products</code> is an instance variable contained within concerned controller. And for sure, test case has reference to this controller. So <code>assigns()</code> method uses it to inspect a hash of controller's instance variables and thus allows to access any precised object from any other files that previously called an action to this controller.</p>
  
  <p>So I wonder two questions:</p>
  
  <p><strong>Why do not create a 'Binding' to controller instead of using <code>assigns()</code> method?</strong></p>
  
  <p>I imagine a version where it is possible to do: </p>
  
  <pre><code>test "should get index" do
          get :index
          assert_response :success
          assert_not_nil @products
  end
  </code></pre>
  
  <p>Wouldn't it be shorter and cleaner?</p>
  
  <p>Binding is the mechanism that allows ERB file to access controller instance variables, as shows this links:</p>
  
  <p><a href="http://rrn.dk/rubys-erb-templating-system" rel="nofollow">http://rrn.dk/rubys-erb-templating-system</a></p>
  
  <p>What isn't this mechanism applicable to Test case ? Is <code>assigns()</code> method essential ?</p>