This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
moqueur_spec.rb
65 lines (55 loc) · 1.9 KB
/
moqueur_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
require 'spec_helper'
describe 'Main specs' do
it 'should mock an ajax request' do
@page.execute_js("jQuery.ajax({url: '/test'})").should eql('Hello World !')
end
it 'should execute the success request' do
@page.execute_js("jQuery.ajax({
url: '/test',
success: function() { return 'Executed Success method'; }
})").should eql('Executed Success method')
end
it 'should not mock requests by default' do
JSON.parse(@page.execute_js("JSON.stringify(jQuery.ajax({url: '/hello'}))"))['url'].should be_nil
end
describe 'with regex' do
it 'should mock an ajax with a regexp' do
@page.execute_js("jQuery.ajax({
url: '/regex/1234',
success: function() { return 'Executed Success method with regex'; }
})").should eql('Executed Success method with regex')
end
it 'should give the param in the content when regex' do
@page.execute_js("jQuery.ajax({
url: '/regex/1234'
})").should eql('Request with regex. Param: 1234')
end
end
describe 'with method specified' do
it 'should mock a get request' do
@page.execute_js("jQuery.ajax({
url: '/get_request',
type: 'GET'
})").should eql('Standard request available only in GET')
end
it 'should also take a type lower cased' do
@page.execute_js("jQuery.ajax({
url: '/get_request',
type: 'get'
})").should eql('Standard request available only in GET')
end
it 'should not mock it in post' do
@page.execute_js("jQuery.ajax({
url: '/get_request',
type: 'POST'
})").should_not eql('Standard request available only in GET')
end
it 'should mock by default whatever the type is' do
@page.execute_js("jQuery.ajax({
url: '/test',
type: 'POST',
success: function() { return 'Executed Success method'; }
})").should eql('Executed Success method')
end
end
end