spec/skles_spec.rb in skles-1.0.2 vs spec/skles_spec.rb in skles-1.0.3
- old
+ new
@@ -1,39 +1,33 @@
require 'spec_helper'
describe StrongKeyLite do
- before :each do
- @client = mock('Savon::Client', request: nil)
- Savon::Client.stub!(:new).and_return(@client)
- end
-
describe "#initialize" do
it "should accept a host for the WSDL" do
- Savon::Client.should_receive(:new).once.with("http://test.host/strongkeyliteWAR/EncryptionService?wsdl").and_return(@client)
- StrongKeyLite.new('http://test.host', 1)
+ StrongKeyLite.new('http://test.host', 1).instance_variable_get(:@client).wsdl.instance_variable_get(:@document).should eql("http://test.host/strongkeyliteWAR/EncryptionService?wsdl")
end
it "should set the domain ID" do
StrongKeyLite.new('http://test.host', 15).domain_id.should eql(15)
end
it "should accept and apply HTTP options" do
- http = mock('Net::HTTP')
- request = mock('Savon::Request', http: http)
- @client.stub!(:request).and_return(request)
-
- http.should_receive(:timeout=).once.with(60)
- StrongKeyLite.new('http://test.host', 1, http: { timeout: 60 })
+ StrongKeyLite.new('http://test.host', 1) { |http| http.read_timeout = 60 }.instance_variable_get(:@client).http.read_timeout.should eql(60)
end
it "should optionally accept a login and password" do
pending "Need a good way to test this"
end
end
describe "#call" do
before :each do
+ @client = mock('Savon::Client', request: nil)
+ Savon::Client.stub!(:new).and_return(@client)
+ end
+
+ before :each do
@client = mock('Savon::Client', request: nil, wsdl: mock('Savon::WSDL', soap_actions: [ :ping ]))
Savon::Client.stub!(:new).and_return(@client)
@skles = StrongKeyLite.new('http://test.host', 1)
@response = mock('Soap::Response', :soap_fault? => false, :http_error? => false, soap_fault: nil, http_error: nil, to_hash: {})
@@ -47,48 +41,48 @@
it "should invoke the proper action on the Savon client and use the appropriate user" do
@skles.add_user('login', 'password', :ping)
soap = mock('Savon::Request')
soap.should_receive(:body=).once.with({ did: 1, username: 'login', password: 'password' })
- @client.should_receive(:ping).once.and_yield(soap).and_return(@response)
+ @client.should_receive(:request).once.with(:wsdl, :ping).and_yield(soap).and_return(@response)
@skles.ping
end
it "should assign a user to all actions when given :all" do
@skles.add_user('all', 'password', :all)
soap = mock('Savon::Request')
soap.should_receive(:body=).once.with({ did: 1, username: 'all', password: 'password' })
- @client.should_receive(:ping).once.and_yield(soap).and_return(@response)
+ @client.should_receive(:request).once.with(:wsdl, :ping).and_yield(soap).and_return(@response)
@skles.ping
end
it "should replace an older user assigned to an action" do
@skles.add_user('all', 'password', :all)
@skles.add_user('ping', 'password', :ping)
soap = mock('Savon::Request')
soap.should_receive(:body=).once.with({ did: 1, username: 'ping', password: 'password' })
- @client.should_receive(:ping).once.and_yield(soap).and_return(@response)
+ @client.should_receive(:request).once.with(:wsdl, :ping).and_yield(soap).and_return(@response)
@skles.ping
end
it "should raise an HTTPError if an HTTP error occurs" do
@skles.add_user('all', 'password', :all)
soap = mock('Savon::Request')
soap.stub!(:body=)
- @client.stub!(:ping).and_yield(soap).and_return(@response)
+ @client.stub!(:request).and_yield(soap).and_return(@response)
@response.stub!(:http_error?).and_return(true)
@response.stub!(:http_error).and_return("404 Not Found")
-> { @skles.ping }.should raise_error(StrongKeyLite::HTTPError)
end
it "should raise a SOAPError if a SOAP fault occurs" do
@skles.add_user('all', 'password', :all)
soap = mock('Savon::Request')
soap.stub!(:body=)
- @client.stub!(:ping).and_yield(soap).and_return(@response)
+ @client.stub!(:request).and_yield(soap).and_return(@response)
@response.stub!(:soap_fault?).and_return(true)
@response.stub!(:soap_fault).and_return("Not enough XML")
-> { @skles.ping }.should raise_error(StrongKeyLite::SOAPError)
end