Ok, I have solved the issue and would like to share the solution with
you.
My problem was that even by creating a proxy call to the jQuery "post"
method, the original method is being executed at the end for result
comparison with the jspec ".receive" syntax. As I have not configured
to proxy an AJAX request, the AJAX call being executed is returning an
error. As I have a hook at jQuery (using $.ajaxSetup method) that
specifies that every AJAX error should create a modal with a
notification (using $.modal jquery plugin), I got the error presented
above (TypeError: $.modal is undefined).
To solve the issue, I have wrote the following:
it 'should save module information to server side'
var module = new Module('10','TestTitle')
jQuery.should.receive('post', 'once').with_args('/ews_widgets/
set_data', { widgetId :
module.id(), widgetTitle: module.title(),
widgetCollapsed: module.collapsed(), widgetColorClass:
module.colorClass() })
mock_request().and_return('{}', 'application/json')
module.save()
end
It was not clear for me that Proxy Assertions indeed executes the
requested method... I thought it needs to behave as a Mock. So a final
question: If a need a Mock behavior with JSpec, what do you
recommend ? Using an external library or using JSpec's Method Stubbing
(although I understand stubbing is not mocking)) ?
Thanks,
Alan