Problems JQuery in jSpec

0 views
Skip to first unread message

Rune Madsen

unread,
Mar 16, 2010, 5:38:50 PM3/16/10
to jspec
Hey everyone

I'm trying to do a ajax call with JQuery in JSpec, and I get the
following error:

ActiveXObject is not defined, Line 1544 (of JSpec core)

This is the line:

1543 function object(str) {
1544 try { return new ActiveXObject(str) } catch(e) {}
1545 }
1546 return object('Msxml2.XMLHTTP.6.0') ||
1547 object('Msxml2.XMLHTTP.3.0') ||
1548 object('Msxml2.XMLHTTP') ||
1549 object('Microsoft.XMLHTTP')
1550 },

My test looks like this:

describe "Create"

it "creates a new child record in the database"

var request = {something:"here"}

$.ajax({
data: request,
type: "POST",
url: 'http://localhost:3000/somepath',
dataType: 'json',
success: function(response)
{
alert(response)
response.yeah.should.be "baby"
},
error: function(response)
{
alert(response)
}
})
end
end


and my dom.html should include the right files:

<script src="/Library/Ruby/Gems/1.8/gems/jspec-3.3.3/lib/jspec.js"></
script>
<script src="support/jquery.js"></script>
<script src="/Library/Ruby/Gems/1.8/gems/jspec-3.3.3/lib/
jspec.xhr.js"></script>
<script src="/Library/Ruby/Gems/1.8/gems/jspec-3.3.3/lib/
jspec.jquery.js"></script>

Anyone have any answer to this? Thanks...

vision media [ Tj Holowaychuk ]

unread,
Mar 16, 2010, 9:57:07 PM3/16/10
to js...@googlegroups.com
Hmm lol even if it is undefined it should not
get through that try/catch block... what browser(s) are you using?

Also you should include a script tag for jspec.jquery.js to make jQuery's 
requests sync and not async :) alternatively you could use jspec.xhr.js 
for mock requests


--
JSpec thanks you for your interest and support! To post simply reply
to this email.

documentation: http://jspec.info
unsubscribe: jspec+un...@googlegroups.com
group: http://groups.google.com/group/jspec



--
Tj Holowaychuk
Vision Media
President & Creative Lead

Rune Skjoldborg Madsen

unread,
Mar 16, 2010, 10:27:59 PM3/16/10
to js...@googlegroups.com
Thanks...

I'm using Firefox and get the error in Firebug. Without Firebug enabled, it seems to work though.

I have set async to false.

- Rune

Rune Madsen

unread,
Mar 16, 2010, 11:54:52 PM3/16/10
to jspec
Sorry for bumping the thread, but I'm having some really strange
issues regarding JSpec.

I have this code:

describe 'API Tests'

before_each
$.ajaxSetup({async:false})
end

it "creates a new child record in the database"

$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?
tags=cat&tagmode=any&format=json&jsoncallback=?",
function(data)
{
alert(data.items)

//data.foo.should.eql 'bar'
})
end

end

I load a json object from flickr and print out the object. Everything
works fine. But I says "0 passes 0 failures". Even though I put (as
you can see) a test that obviously should fail, it doesn't do
anything.

Everything is working if I do it with a mock json call.

Is there anything I need to know to make it work. Same doc.html
includes as the last post.

- Rune

On Mar 16, 10:27 pm, Rune Skjoldborg Madsen <r...@runemadsen.com>
wrote:


> Thanks...
>
> I'm using Firefox and get the error in Firebug. Without Firebug enabled,
> it seems to work though.
>
> I have set async to false.
>
> - Rune
>
> On 3/16/10 9:57 PM, vision media [ Tj Holowaychuk ] wrote:
>
>
>
> > Hmm lol even if it is undefined it should not
> > get through that try/catch block... what browser(s) are you using?
>
> > Also you should include a script tag for jspec.jquery.js to make jQuery's
> > requests sync and not async :) alternatively you could use jspec.xhr.js
> > for mock requests
>

> >     response.yeah.should.be <http://response.yeah.should.be> "baby"


> >                            },
> >                                    error: function(response)
> >                                    {
> >                                            alert(response)
> >                                    }
> >                    })
> >            end
> >     end
>
> >     and my dom.html should include the right files:
>
> >     <script src="/Library/Ruby/Gems/1.8/gems/jspec-3.3.3/lib/jspec.js"></
> >     script>
> >     <script src="support/jquery.js"></script>
> >     <script src="/Library/Ruby/Gems/1.8/gems/jspec-3.3.3/lib/
> >     jspec.xhr.js"></script>
> >     <script src="/Library/Ruby/Gems/1.8/gems/jspec-3.3.3/lib/
> >     jspec.jquery.js"></script>
>
> >     Anyone have any answer to this? Thanks...
>
> >     --
> >     JSpec thanks you for your interest and support! To post simply reply
> >     to this email.
>
> >     documentation:http://jspec.info
> >     unsubscribe: jspec+un...@googlegroups.com

> >     <mailto:jspec%2Bunsu...@googlegroups.com>

vision media [ Tj Holowaychuk ]

unread,
Mar 17, 2010, 10:51:09 AM3/17/10
to js...@googlegroups.com
If you assert in a callback you run the danger of having
it never being reached, hence the 0 0. I would recommend
something like:

var called = false

someRequest(function(){
  called = true
})

called.should.be_true

Rune Skjoldborg Madsen

unread,
Mar 17, 2010, 12:28:19 PM3/17/10
to js...@googlegroups.com
I see that, but I don't think that's the problem.

With this code:

var called = false
       
        $.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?tags=cat&tagmode=any&format=json&jsoncallback=?",
        function(data)
        {   
            alert(data.items)

           
            called = true
        })

        called.should.be_true


I get the alert and it has loaded the data I want. But called is still false. It actually looks like the JSpec validation is run before the ajax call comes in, because the alert comes 2 seconds after the validation message.

Am I doing anything wrong?

vision media [ Tj Holowaychuk ]

unread,
Mar 17, 2010, 12:39:51 PM3/17/10
to js...@googlegroups.com
Well as I mentioned it has to be synchronous,
so some how jQuery is still firing as async, otherwise
execution should be in order

Rune Skjoldborg Madsen

unread,
Mar 17, 2010, 1:11:14 PM3/17/10
to js...@googlegroups.com
That's just weird, because my code sets that before_each. Even doing this doesn't work:

var response = {}
       
            //mock_request().and_return('{ foo: "bar" }', 'application/json', 200, { Accept: 'foo' })
           
            $.ajaxSetup({async:false})

       
            $.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?tags=cat&tagmode=any&format=json&jsoncallback=?", function(data)
            {   
                alert("here")
               
                response = data
            })

            response.foo.should.eql "bar"

Have you any idea what I'm doing wrong?

- Rune

vision media [ Tj Holowaychuk ]

unread,
Mar 17, 2010, 1:35:13 PM3/17/10
to js...@googlegroups.com
I know someone else had a problem with JSONP as well,
but it was due to how they were using jQuery and not really JSpec at all.

That being said I would stick with including jspec.jquery.js after jquery.js
instead of manually doing $.ajaxSetup() but other than that I am not to sure
whats going on

Rune Skjoldborg Madsen

unread,
Mar 17, 2010, 8:10:54 PM3/17/10
to js...@googlegroups.com
Ok thanks... I looks really weird. Sometimes the validation will show up before the calls are completed, sometimes not. his changes depending on which domain I enter in the ajax request. Weird...

- Rune

vision media [ Tj Holowaychuk ]

unread,
Mar 18, 2010, 10:15:18 AM3/18/10
to js...@googlegroups.com
ya you have to be really careful when using real apis,
I try to mock everything possible

Rune Skjoldborg Madsen

unread,
Mar 18, 2010, 8:17:10 PM3/18/10
to js...@googlegroups.com
Thanks... There is some kind of "ActiveX" break on error in the Firebug javascript console in the JSpec js code. There's no problems when not running Firebug.

Anyone else having this error?

Running FireFox 3.6 and Firebug on OSX Snow Leopard.

- Rune
Reply all
Reply to author
Forward
0 new messages