title: Casper JS waitForResource with a restful API
body: <p>We are having a little problem with a functional test with casper.js.</p>
  
  <p>We request the same resource twice, first with the GET and then with POST method.
  Now when waiting for the second resource (POST) it matches the first resource and directly goes to the "then" function. </p>
  
  <p>We would like to be able to check for the HTTP method in the "test" function, that way we can identify the resource properly. For now we use the status code (res.status), but that doesn't solve our problem fully, we really need the http method.</p>
  
  <pre><code>// create new email
  this.click(xPath('//div[@id="tab-content"]//a[@class="button create"]'));
  
  // GET
  this.waitForResource('/some/resource', 
      function then() {
          this.test.assertExists(xPath('//form[@id="email_edit_form"]'), 'Email edit form is there');
  
          this.fill('form#email_edit_form', {
              'email_entity[email]': 'test.bruce@im.com',
              'email_entity[isMain]': 1
          }, true);
  
          // POST
          this.waitForResource(
              function test(res) {
                  return res.url.search('/some/resource') !== -1 &amp;&amp; res.status === 201;
              },
              function then() {
                  this.test.assert(true, 'Email creation worked.');
              },
              function timeout() {
                  this.test.fail('Email creation did not work.');
              }
          );
      },
      function timeout() {
          this.test.fail('Email adress creation form has not been loaded');
      });
  </code></pre>
  
  <p>Or maybe there is a better way to test this scenario? Although since this is a functional test we need to keep all those steps in one test.</p>