[rspec-users] what would be the best way to stub out an XHR request's response?

Ervin Weber webervin at gmail.com
Thu Sep 27 08:16:17 UTC 2012

On Wed, Sep 26, 2012 at 9:34 PM, Adam Sroka <adam.sroka at gmail.com> wrote:
> On Wed, Sep 26, 2012 at 11:26 AM, Patrick J. Collins
> <patrick at collinatorstudios.com> wrote:
>>> I would just wrap the method that makes the ajax call and spec it from
>>> Jasmine. Then you can just stub the wrapper to return the data you
>>> want and expect the right thing to happen in the callback method (or
>>> however the data gets stored/displayed.)
>> Sorry, I am not sure if I am understanding you correctly...  Are you
>> saying, in the test environment, load jasmine via <script> tags, and use
>> it to stub out the method that call that does the ajax call?
> That could work. What I would actually do is call jamine-node from a
> rake task, because I'm hoping I don't really need the full stack to
> spec this behavior. Using rspec to test that a callback happens in a
> page sounds like it would be slower than I'd like.
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

Actually I assumed rspec integration tests, say using selenium or something.
In such case you could use something similar to the way we stub confirm method:
page.evaluate_script('window.confirm = function() { return true; }')
to simply override some functions before ajax is sent out.

More information about the rspec-users mailing list