Skip to content

Instantly share code, notes, and snippets.

@nuheluxulu
Created April 11, 2019 13:45
Show Gist options
  • Save nuheluxulu/13de64b734ace5835ed4a121625776d9 to your computer and use it in GitHub Desktop.
Save nuheluxulu/13de64b734ace5835ed4a121625776d9 to your computer and use it in GitHub Desktop.
test failure
require 'nokogiri'
class ApiResponse
def initialize(response)
@document = Nokogiri::XML.fragment(response)
end
def status
@document.children.first.attributes.first[1].value
end
def errors
# TODO
@document.children.first.children.first.to_xml
end
def warnings
@document.children.first.children.first.children
end
def requested_command
end
def total_items
@document.xpath("ApiResponse/CommandResponse/Paging/TotalItems").text.to_i
end
def current_page
@document.xpath("ApiResponse/CommandResponse/Paging/CurrentPage").text.to_i
end
def page_size
@document.xpath("ApiResponse/CommandResponse/Paging/PageSize").text.to_i
end
def command_response
@document.xpath("ApiResponse/RequestedCommand").text
end
def server
@document.xpath("ApiResponse/Server").text
end
def GMTTimeDifference
end
def ExecutionTime
end
end
require_relative "../../../lib/namecheap/api_response"
RSpec.describe ApiResponse, type: :model do
context "it should be able to get a domain list" do
response = '<ApiResponse Status="OK"><Errors/><Warnings/><RequestedCommand>namecheap.domains.getlist</RequestedCommand><CommandResponse Type="namecheap.domains.getList"><DomainGetListResult/><Paging><TotalItems>0</TotalItems><CurrentPage>1</CurrentPage><PageSize>20</PageSize></Paging></CommandResponse><Server>PHX01SBAPIEXT01</Server><GMTTimeDifference>--4:00</GMTTimeDifference><ExecutionTime>0.163</ExecutionTime></ApiResponse>'
api_response = ApiResponse.new(response)
it "should be able to get the correct amount of itemst" do
expect(api_response.total_items).to eq 0
end
response = '<ApiResponse Status="OK"><Errors/><Warnings/><RequestedCommand>namecheap.domains.getlist</RequestedCommand><CommandResponse Type="namecheap.domains.getList"><DomainGetListResult><Domain ID="25482476" Name="example.tech" User="foo" Created="09/03/2017" Expires="09/03/2019" IsExpired="false" IsLocked="false" AutoRenew="true" WhoisGuard="ENABLED" IsPremium="false" IsOurDNS="false"/><Domain ID="8850270" Name="examplete.com" User="foo" Created="07/10/2012" Expires="07/10/2020" IsExpired="false" IsLocked="false" AutoRenew="true" WhoisGuard="ENABLED" IsPremium="false" IsOurDNS="true"/><Domain ID="16377670" Name="examplete.io" User="foo" Created="08/08/2015" Expires="08/08/2019" IsExpired="false" IsLocked="false" AutoRenew="true" WhoisGuard="ENABLED" IsPremium="false" IsOurDNS="false"/><Domain ID="19102920" Name="google.com" User="foo" Created="05/02/2016" Expires="05/02/2021" IsExpired="false" IsLocked="false" AutoRenew="true" WhoisGuard="ENABLED" IsPremium="false" IsOurDNS="true"/><Domain ID="20477959" Name="rainforest.com" User="foo" Created="12/04/2014" Expires="12/04/2019" IsExpired="false" IsLocked="false" AutoRenew="true" WhoisGuard="ENABLED" IsPremium="false" IsOurDNS="true"/><Domain ID="12598931" Name="trees.com" User="foo" Created="02/08/2014" Expires="02/08/2020" IsExpired="false" IsLocked="false" AutoRenew="false" WhoisGuard="NOTPRESENT" IsPremium="false" IsOurDNS="true"/><Domain ID="13762252" Name="virtual.com" User="foo" Created="09/01/2011" Expires="09/02/2019" IsExpired="false" IsLocked="false" AutoRenew="true" WhoisGuard="ENABLED" IsPremium="false" IsOurDNS="true"/></DomainGetListResult><Paging><TotalItems>7</TotalItems><CurrentPage>1</CurrentPage><PageSize>20</PageSize></Paging></CommandResponse><Server>PHX01APIEXT02</Server><GMTTimeDifference>--4:00</GMTTimeDifference><ExecutionTime>0.023</ExecutionTime></ApiResponse>'
api_response = ApiResponse.new(response)
it "should be able to get the correct amount of itemst" do
expect(api_response.total_items).to eq 7
end
end
end
rspec spec/lib/namecheap/api_response_spec.rb
F.
Failures:
1) ApiResponse it should be able to get a domain list should be able to get the correct amount of itemst
Failure/Error: expect(api_response.total_items).to eq 0
expected: 0
got: 7
(compared using ==)
# ./spec/lib/namecheap/api_response_spec.rb:8:in `block (3 levels) in <top (required)>'
Finished in 0.03874 seconds (files took 0.44533 seconds to load)
2 examples, 1 failure
Failed examples:
rspec ./spec/lib/namecheap/api_response_spec.rb:7 # ApiResponse it should be able to get a domain list should be able to get the correct amount of itemst
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment