spec/http_spec.rb in opal-jquery-0.2.0 vs spec/http_spec.rb in opal-jquery-0.3.0.beta1
- old
+ new
@@ -1,29 +1,56 @@
require "spec_helper"
describe HTTP do
- describe '#body' do
- async 'returns the response body as a string' do
- HTTP.get('spec/fixtures/simple.txt') do |response|
- run_async { response.body.should == "hey" }
- end
+ describe ".setup" do
+ it 'presents the $.ajaxSetup() object as a Hash' do
+ HTTP.setup.should be_a Hash
end
end
- describe '#callback' do
- async 'can add a success callback after the request is sent' do
- http = HTTP.get('spec/fixtures/simple.txt')
- http.callback do |response|
- run_async { response.should be_ok }
+ describe ".get" do
+ context "with a block" do
+ it "returns the http object instance" do
+ HTTP.get('/spec/fixtures/simple.txt') do
+ end.should be_a HTTP
end
+
+ async "block gets called on success" do
+ HTTP.get('spec/fixtures/simple.txt') do |response|
+ run_async { response.should be_ok }
+ end
+ end
+
+ async "block gets called on failure" do
+ HTTP.get('/spec/does/not/exist.txt') do |response|
+ run_async { response.should_not be_ok }
+ end
+ end
end
+
+ context "without a block" do
+ it "returns a promise" do
+ HTTP.get('/spec/fixtures/simple.txt').should be_a Promise
+ end
+
+ async "returns a promise which accepts a then-block for successful response" do
+ HTTP.get('spec/fixtures/simple.txt').then do |response|
+ run_async { response.should be_ok }
+ end
+ end
+
+ async "returns a promise which accepts a fail-block for failing response" do
+ HTTP.get('spec/does/not/exist.txt').fail do |response|
+ run_async { response.should_not be_ok }
+ end
+ end
+ end
end
- describe '#callback' do
- async 'can add a failure callback after the request is sent' do
- http = HTTP.get('spec/fixtures/bad_url.txt')
- http.errback do |response|
- run_async { response.should_not be_ok }
+ describe '#body' do
+ async 'returns the response body as a string' do
+ HTTP.get('spec/fixtures/simple.txt') do |response|
+ run_async { response.body.should == "hey" }
end
end
end
describe '#json' do