/
agent_spec.rb
88 lines (73 loc) · 2.14 KB
/
agent_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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe YouGotListed::Agent do
before do
@ygl = new_ygl
@agent = YouGotListed::Agent.new(@ygl)
end
context "find_all" do
before do
VCR.use_cassette('agent.find_all') do
@response = @agent.find_all
end
end
it "should be a success" do
@response.success?.should be_true
end
it "should return an array of agents" do
@response.agents.agent.should_not be_nil
@response.agents.agent.should be_kind_of(Array)
end
end
context "successful find" do
before do
VCR.use_cassette('agent.find') do
@response = @agent.find('AG-001-046')
end
end
it "should be a success" do
@response.success?.should be_true
end
it "should return an array of agents" do
@response.agents.agent.should_not be_nil
@response.agents.agent.should be_kind_of(Hashie::Rash)
end
end
context "unsuccessful find" do
it "should raise an exception" do
lambda {
VCR.use_cassette('agent.find.error') do
@response = @agent.find('AG-001-04999')
end
}.should raise_exception(YouGotListed::Error, "YouGotListed Error: Invalid user id. (code: 301)")
end
end
context "successful find_by_id" do
before do
VCR.use_cassette('agent.find') do
@response = @agent.find_by_id('AG-001-046')
end
end
it "should be a success" do
@response.success?.should be_true
end
it "should return an array of agents" do
@response.agents.agent.should_not be_nil
@response.agents.agent.should be_kind_of(Hashie::Rash)
end
end
context "unsuccessful find_by_id" do
it "should raise an exception" do
lambda {
VCR.use_cassette('agent.find.error') do
@response = @agent.find_by_id('AG-001-04999')
end
}.should_not raise_exception
end
it "should not be a success" do
VCR.use_cassette('agent.find.error') do
@response = @agent.find_by_id('AG-001-04999')
end
@response.success?.should be_false
end
end
end