spec/lib/xway/api/endpoints_spec.rb in xway-0.0.1.beta vs spec/lib/xway/api/endpoints_spec.rb in xway-0.0.2.beta

- old
+ new

@@ -1,89 +1,125 @@ require 'spec_helper' +require 'xway/error' require 'xway/api/endpoints' require 'xway/api/request' describe Xway::Api::Endpoints do subject('endpoints') { described_class.new } - describe 'list' do - subject { endpoints.list({}) } - its('method_name') { should eq 'get' } - its('path') { should eq '/applications' } - its('headers') { should eq('X-App' => 'appway') } - its('body') { should eq(nil) } + specify 'list doesnt require_options' do + expect{ subject.list }.not_to raise_error(Xway::MissingParameter) end - - describe 'create' do - let('manifest') { File.join(ASSETS_PATH, 'appway-example.json') } - subject { endpoints.create manifest: manifest } - its('method_name') { should eq 'post' } - its('path') { should eq '/applications' } - its('headers') { should eq('X-App' => 'appway', - 'Content-Type' => 'application/json') } - its('body') { should be_kind_of(Xway::Api::Request::Body) } + specify 'create doesnt require_options' do + expect{ subject.create }.not_to raise_error(Xway::MissingParameter) end - - describe 'find' do - subject { endpoints.find app: 'foo' } - its('method_name') { should eq 'get' } - its('path') { should eq '/applications/foo' } - its('headers') { should eq('X-App' => 'appway') } - its('body') { should eq(nil) } + specify 'find does require_options' do + expect{ subject.find }.to raise_error(Xway::MissingParameter) end - - describe 'update' do - subject { endpoints.update app: 'foo' } - its('method_name') { should eq 'put' } - its('path') { should eq '/applications/foo' } - its('headers') { should eq('X-App' => 'appway') } - its('body') { should eq(nil) } + specify 'update does require_options' do + expect{ subject.update }.to raise_error(Xway::MissingParameter) end - - describe 'delete' do - subject { endpoints.delete app: 'foo' } - its('method_name') { should eq 'delete' } - its('path') { should eq '/applications/foo' } - its('headers') { should eq('X-App' => 'appway') } - its('body') { should eq(nil) } + specify 'delete does require_options' do + expect{ subject.delete }.to raise_error(Xway::MissingParameter) end - - describe 'log' do - subject { endpoints.log app: 'foo' } - its('method_name') { should eq 'get' } - its('path') { should eq '/applications/foo/log' } - its('headers') { should eq('X-App' => 'appway') } - its('body') { should eq(nil) } + specify 'log does require_options' do + expect{ subject.log }.to raise_error(Xway::MissingParameter) end - - describe 'start' do - subject { endpoints.start app: 'foo' } - its('method_name') { should eq 'post' } - its('path') { should eq '/applications/foo/start' } - its('headers') { should eq('X-App' => 'appway') } - its('body') { should eq(nil) } + specify 'start does require_options' do + expect{ subject.start }.to raise_error(Xway::MissingParameter) end - - describe 'stop' do - subject { endpoints.stop app: 'foo' } - its('method_name') { should eq 'post' } - its('path') { should eq '/applications/foo/stop' } - its('headers') { should eq('X-App' => 'appway') } - its('body') { should eq(nil) } + specify 'stop does require_options' do + expect{ subject.stop }.to raise_error(Xway::MissingParameter) end - - describe 'restart' do - subject { endpoints.restart app: 'foo' } - its('method_name') { should eq 'post' } - its('path') { should eq '/applications/foo/restart' } - its('headers') { should eq('X-App' => 'appway') } - its('body') { should eq(nil) } + specify 'restart does require_options' do + expect{ subject.restart }.to raise_error(Xway::MissingParameter) end + specify 'redeploy does require_options' do + expect{ subject.redeploy }.to raise_error(Xway::MissingParameter) + end - describe 'redeploy' do - subject { endpoints.redeploy app: 'foo' } - its('method_name') { should eq 'post' } - its('path') { should eq '/applications/foo/redeploy' } - its('headers') { should eq('X-App' => 'appway') } - its('body') { should eq(nil) } + context 'mock require_options' do + before { endpoints.stub('require_options') } + + describe 'list' do + subject { endpoints.list({}) } + its('method_name') { should eq 'get' } + its('path') { should eq '/applications' } + its('headers') { should eq('X-App' => 'appway') } + its('body') { should eq(nil) } + end + + describe 'create' do + let('manifest') { File.join(ASSETS_PATH, 'appway-example.json') } + subject { endpoints.create manifest: manifest } + its('method_name') { should eq 'post' } + its('path') { should eq '/applications' } + its('headers') { should eq('X-App' => 'appway', + 'Content-Type' => 'application/json') } + its('body') { should be_kind_of(Xway::Api::Request::Body) } + end + + describe 'find' do + subject { endpoints.find name: 'foo' } + its('method_name') { should eq 'get' } + its('path') { should eq '/applications/foo' } + its('headers') { should eq('X-App' => 'appway') } + its('body') { should eq(nil) } + end + + describe 'update' do + subject { endpoints.update name: 'foo' } + its('method_name') { should eq 'put' } + its('path') { should eq '/applications/foo' } + its('headers') { should eq('X-App' => 'appway') } + its('body') { should eq(nil) } + end + + describe 'delete' do + subject { endpoints.delete name: 'foo' } + its('method_name') { should eq 'delete' } + its('path') { should eq '/applications/foo' } + its('headers') { should eq('X-App' => 'appway') } + its('body') { should eq(nil) } + end + + describe 'log' do + subject { endpoints.log name: 'foo' } + its('method_name') { should eq 'get' } + its('path') { should eq '/applications/foo/log' } + its('headers') { should eq('X-App' => 'appway') } + its('body') { should eq(nil) } + end + + describe 'start' do + subject { endpoints.start name: 'foo' } + its('method_name') { should eq 'post' } + its('path') { should eq '/applications/foo/start' } + its('headers') { should eq('X-App' => 'appway') } + its('body') { should eq(nil) } + end + + describe 'stop' do + subject { endpoints.stop name: 'foo' } + its('method_name') { should eq 'post' } + its('path') { should eq '/applications/foo/stop' } + its('headers') { should eq('X-App' => 'appway') } + its('body') { should eq(nil) } + end + + describe 'restart' do + subject { endpoints.restart name: 'foo' } + its('method_name') { should eq 'post' } + its('path') { should eq '/applications/foo/restart' } + its('headers') { should eq('X-App' => 'appway') } + its('body') { should eq(nil) } + end + + describe 'redeploy' do + subject { endpoints.redeploy name: 'foo' } + its('method_name') { should eq 'post' } + its('path') { should eq '/applications/foo/redeploy' } + its('headers') { should eq('X-App' => 'appway') } + its('body') { should eq(nil) } + end end end