kippt 3.0.1 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,7 +4,7 @@ require "kippt/comment"
4
4
  describe Kippt::Comment do
5
5
  subject { Kippt::Comment.new(data, clip, client) }
6
6
  let(:client) { Kippt::Client.new(valid_user_credentials) }
7
- let(:clip) { stub(:clip) }
7
+ let(:clip) { double(:clip) }
8
8
  let(:collection_resource_class) { Kippt::Comments }
9
9
 
10
10
  let(:data) { MultiJson.load(fixture("comment.json").read) }
@@ -19,7 +19,7 @@ describe Kippt::Comment do
19
19
 
20
20
  describe "#clip" do
21
21
  it "returns the clip passed to it" do
22
- subject.clip.should eq clip
22
+ expect(subject.clip).to eq clip
23
23
  end
24
24
  end
25
25
  end
@@ -3,7 +3,7 @@ require "kippt/comments"
3
3
 
4
4
  describe Kippt::Comments do
5
5
  let(:client) { Kippt::Client.new(valid_user_credentials) }
6
- let(:clip) { stub :clip, :id => 100, :all_comments_embedded? => false }
6
+ let(:clip) { double :clip, :id => 100, :all_comments_embedded? => false }
7
7
  subject { Kippt::Comments.new(client, clip) }
8
8
  let(:base_uri) { "clips/#{clip.id}/comments" }
9
9
  let(:singular_fixture) { "comment" }
@@ -18,11 +18,11 @@ describe Kippt::Comments do
18
18
 
19
19
  describe "#build" do
20
20
  it "returns new resource" do
21
- subject.build.should be_a(resource_class)
21
+ expect(subject.build).to be_a(resource_class)
22
22
  end
23
23
 
24
24
  it "accepts parameters" do
25
- subject.object_class.should_receive(:new).with({:an => "attribute"}, client, clip)
25
+ expect(subject.object_class).to receive(:new).with({:an => "attribute"}, client, clip)
26
26
  subject.build({:an => "attribute"})
27
27
  end
28
28
  end
@@ -43,22 +43,22 @@ describe Kippt::Comments do
43
43
  end
44
44
 
45
45
  context "when comments are embedded" do
46
- let(:clip) { stub :clip,
47
- id: 100,
48
- all_comments_embedded?: true,
49
- comments_data: [{body: "Embedded body"}] }
46
+ let(:clip) { double :clip,
47
+ id: 100,
48
+ all_comments_embedded?: true,
49
+ comments_data: [{body: "Embedded body"}] }
50
50
 
51
51
  it "uses the embedded data to create comments" do
52
52
  comments = subject.fetch
53
- comments.first.body.should eq "Embedded body"
53
+ expect(comments.first.body).to eq "Embedded body"
54
54
  end
55
55
  end
56
56
 
57
57
  context "when passed unrecognized arguments" do
58
58
  it "raises error" do
59
- lambda {
59
+ expect {
60
60
  subject.fetch(:foobar => true)
61
- }.should raise_error(
61
+ }.to raise_error(
62
62
  ArgumentError, "Unrecognized argument: foobar")
63
63
  end
64
64
  end
@@ -68,22 +68,22 @@ describe Kippt::Comments do
68
68
  it "fetches single resource" do
69
69
  stub_get("/#{base_uri}/10").
70
70
  to_return(:status => 200, :body => fixture("#{singular_fixture}.json"))
71
- subject[10].id.should eq 10
71
+ expect(subject[10].id).to eq 10
72
72
  end
73
73
 
74
74
  it "returns resource" do
75
75
  stub_get("/#{base_uri}/10").
76
76
  to_return(:status => 200, :body => fixture("#{singular_fixture}.json"))
77
- subject[10].should be_a(resource_class)
77
+ expect(subject[10]).to be_a(resource_class)
78
78
  end
79
79
 
80
80
  context "when resource is not found" do
81
81
  it "raises exception" do
82
82
  stub_get("/#{base_uri}/10").
83
- to_return(:status => 404, :body => {"message" => "Resource not found."})
84
- lambda {
83
+ to_return(:status => 404, :body => {"message" => "Resource not found."}.to_json)
84
+ expect {
85
85
  subject[10]
86
- }.should raise_error(
86
+ }.to raise_error(
87
87
  Kippt::APIError, "Resource could not be loaded: Resource not found.")
88
88
  end
89
89
  end
@@ -91,37 +91,17 @@ describe Kippt::Comments do
91
91
 
92
92
  describe "#find" do
93
93
  it "exists" do
94
- subject.respond_to?(:find).should be_true
95
- end
96
- end
97
-
98
- describe "#collection_from_url" do
99
- it "returns a new collection" do
100
- stub_get("/#{base_uri}/?limit=20&offset=20").
101
- to_return(:status => 200, :body => fixture("#{collection_fixture}.json"))
102
- collection = subject.collection_from_url("/api/#{base_uri}/?limit=20&offset=20")
103
- collection.should be_a(collection_class)
104
- end
105
-
106
- context "when passed URL is blank" do
107
- it "raises ArgumentError" do
108
- lambda {
109
- subject.collection_from_url("")
110
- }.should raise_error(ArgumentError, "The parameter URL can't be blank")
111
- lambda {
112
- subject.collection_from_url(nil)
113
- }.should raise_error(ArgumentError, "The parameter URL can't be blank")
114
- end
94
+ expect(subject.respond_to?(:find)).to be_truthy
115
95
  end
116
96
  end
117
97
 
118
98
  describe "#build" do
119
99
  it "returns new resource" do
120
- subject.build.should be_a(resource_class)
100
+ expect(subject.build).to be_a(resource_class)
121
101
  end
122
102
 
123
103
  it "accepts parameters" do
124
- subject.object_class.should_receive(:new).with({:an => "attribute"}, client, clip)
104
+ expect(subject.object_class).to receive(:new).with({:an => "attribute"}, client, clip)
125
105
  subject.build(:an => "attribute")
126
106
  end
127
107
  end
@@ -8,18 +8,18 @@ describe Kippt::Favorite do
8
8
  let(:favorite) { Kippt::Favorite.new(clip, client) }
9
9
 
10
10
  it "tells collection resource to save itself" do
11
- collection.should_receive(:save_resource).with(favorite).and_return({success: true})
12
- client.should_receive(:collection_resource_for).with(Kippt::Favorites, clip).and_return(collection)
11
+ expect(collection).to receive(:save_resource).with(favorite).and_return({success: true})
12
+ expect(client).to receive(:collection_resource_for).with(Kippt::Favorites, clip).and_return(collection)
13
13
 
14
- favorite.save.should be_true
14
+ expect(favorite.save).to be_truthy
15
15
  end
16
16
 
17
17
  it "sets errors if there is any" do
18
- collection.stub(:save_resource).and_return({success: false, error_message: "PROBLEM"})
19
- client.stub(:collection_resource_for).and_return(collection)
18
+ allow(collection).to receive(:save_resource).and_return({success: false, error_message: "PROBLEM"})
19
+ allow(client).to receive(:collection_resource_for).and_return(collection)
20
20
 
21
- favorite.save.should be_false
22
- favorite.errors.should eq ["PROBLEM"]
21
+ expect(favorite.save).to be_falsey
22
+ expect(favorite.errors).to eq ["PROBLEM"]
23
23
  end
24
24
  end
25
25
 
@@ -30,9 +30,9 @@ describe Kippt::Favorite do
30
30
  let(:favorite) { Kippt::Favorite.new(clip, client) }
31
31
 
32
32
  it "tells collection resource to destroy itself" do
33
- client.stub(:collection_resource_for).and_return(collection)
34
- collection.should_receive(:destroy_resource).with(favorite).and_return(true)
35
- favorite.destroy.should be_true
33
+ allow(client).to receive(:collection_resource_for).and_return(collection)
34
+ expect(collection).to receive(:destroy_resource).with(favorite).and_return(true)
35
+ expect(favorite.destroy).to be_truthy
36
36
  end
37
37
  end
38
38
  end
@@ -3,7 +3,7 @@ require "kippt/favorites"
3
3
 
4
4
  describe Kippt::Favorites do
5
5
  let(:client) { Kippt::Client.new(valid_user_credentials) }
6
- let(:clip) { stub :user, :id => 100, :all_favorites_embedded? => false }
6
+ let(:clip) { double :user, :id => 100, :all_favorites_embedded? => false }
7
7
  subject { Kippt::Favorites.new(client, clip) }
8
8
  let(:base_uri) { "clips/#{clip.id}/favorites" }
9
9
 
@@ -11,8 +11,8 @@ describe Kippt::Favorites do
11
11
  it "uses only the base_uri" do
12
12
  favorite = double :favorite
13
13
  response = double :response, success?: true
14
- client.should_receive(:delete).with("clips/100/favorites").and_return(response)
15
- subject.destroy_resource(favorite).should be_true
14
+ expect(client).to receive(:delete).with("clips/100/favorites").and_return(response)
15
+ expect(subject.destroy_resource(favorite)).to be_truthy
16
16
  end
17
17
  end
18
18
  end
@@ -3,20 +3,20 @@ require "kippt/follow_relationship"
3
3
 
4
4
  describe Kippt::FollowRelationship do
5
5
  let(:client) { Kippt::Client.new(valid_user_credentials) }
6
- let(:user) { stub :user, :id => 10 }
6
+ let(:user) { double :user, :id => 10 }
7
7
  subject { Kippt::FollowRelationship.new(client, user) }
8
8
 
9
9
  describe "#following?" do
10
10
  it "returns boolean" do
11
11
  stub_get("/users/10/relationship/").
12
12
  to_return(:status => 200, :body => '{"following": true}')
13
- subject.following?.should be_true
13
+ expect(subject.following?).to be_truthy
14
14
  end
15
15
 
16
16
  context "when request is not successful" do
17
17
  it "raises an exception" do
18
18
  fail_response = double :fail_response, success?: false, body: {"message" => "NOT FOUND"}
19
- client.stub(:get).and_return(fail_response)
19
+ allow(client).to receive(:get).and_return(fail_response)
20
20
  expect {
21
21
  subject.following?
22
22
  }.to raise_exception Kippt::APIError, "Resource could not be loaded: NOT FOUND"
@@ -29,13 +29,13 @@ describe Kippt::FollowRelationship do
29
29
  stub_post("/users/10/relationship/").
30
30
  with(:body => "{\"action\":\"follow\"}").
31
31
  to_return(:status => 200, :body => "", :headers => {})
32
- subject.follow.should be_true
32
+ expect(subject.follow).to be_truthy
33
33
  end
34
34
 
35
35
  context "when request is not successful" do
36
36
  it "raises an exception" do
37
37
  fail_response = double :fail_response, success?: false, body: {"message" => "NOT FOUND"}
38
- client.stub(:post).and_return(fail_response)
38
+ allow(client).to receive(:post).and_return(fail_response)
39
39
  expect {
40
40
  subject.follow
41
41
  }.to raise_exception Kippt::APIError, "Problem with following: NOT FOUND"
@@ -48,13 +48,13 @@ describe Kippt::FollowRelationship do
48
48
  stub_post("/users/10/relationship/").
49
49
  with(:body => "{\"action\":\"unfollow\"}").
50
50
  to_return(:status => 200, :body => "", :headers => {})
51
- subject.unfollow.should be_true
51
+ expect(subject.unfollow).to be_truthy
52
52
  end
53
53
 
54
54
  context "when request is not successful" do
55
55
  it "raises an exception" do
56
56
  fail_response = double :fail_response, success?: false, body: {"message" => "NOT FOUND"}
57
- client.stub(:post).and_return(fail_response)
57
+ allow(client).to receive(:post).and_return(fail_response)
58
58
  expect {
59
59
  subject.unfollow
60
60
  }.to raise_exception Kippt::APIError, "Problem with unfollowing: NOT FOUND"
@@ -8,18 +8,18 @@ describe Kippt::Like do
8
8
  let(:like) { Kippt::Like.new(clip, client) }
9
9
 
10
10
  it "tells collection resource to save itself" do
11
- collection.should_receive(:save_resource).with(like).and_return({success: true})
12
- client.should_receive(:collection_resource_for).with(Kippt::Likes, clip).and_return(collection)
11
+ expect(collection).to receive(:save_resource).with(like).and_return({success: true})
12
+ expect(client).to receive(:collection_resource_for).with(Kippt::Likes, clip).and_return(collection)
13
13
 
14
- like.save.should be_true
14
+ expect(like.save).to be_truthy
15
15
  end
16
16
 
17
17
  it "sets errors if there is any" do
18
- collection.stub(:save_resource).and_return({success: false, error_message: "PROBLEM"})
19
- client.stub(:collection_resource_for).and_return(collection)
18
+ allow(collection).to receive(:save_resource).and_return({success: false, error_message: "PROBLEM"})
19
+ allow(client).to receive(:collection_resource_for).and_return(collection)
20
20
 
21
- like.save.should be_false
22
- like.errors.should eq ["PROBLEM"]
21
+ expect(like.save).to be_falsey
22
+ expect(like.errors).to eq ["PROBLEM"]
23
23
  end
24
24
  end
25
25
 
@@ -30,9 +30,9 @@ describe Kippt::Like do
30
30
  let(:like) { Kippt::Like.new(clip, client) }
31
31
 
32
32
  it "tells collection resource to destroy itself" do
33
- client.stub(:collection_resource_for).and_return(collection)
34
- collection.should_receive(:destroy_resource).with(like).and_return(true)
35
- like.destroy.should be_true
33
+ allow(client).to receive(:collection_resource_for).and_return(collection)
34
+ expect(collection).to receive(:destroy_resource).with(like).and_return(true)
35
+ expect(like.destroy).to be_truthy
36
36
  end
37
37
  end
38
38
  end
@@ -3,7 +3,7 @@ require "kippt/likes"
3
3
 
4
4
  describe Kippt::Likes do
5
5
  let(:client) { Kippt::Client.new(valid_user_credentials) }
6
- let(:clip) { stub :user, :id => 100, :all_likes_embedded? => false }
6
+ let(:clip) { double :user, :id => 100, :all_likes_embedded? => false }
7
7
  subject { Kippt::Likes.new(client, clip) }
8
8
  let(:base_uri) { "clips/#{clip.id}/likes" }
9
9
  let(:singular_fixture) { "user" }
@@ -14,8 +14,8 @@ describe Kippt::Likes do
14
14
  it "uses only the base_uri" do
15
15
  like = double :like
16
16
  response = double :response, success?: true
17
- client.should_receive(:delete).with("clips/100/likes").and_return(response)
18
- subject.destroy_resource(like).should be_true
17
+ expect(client).to receive(:delete).with("clips/100/likes").and_return(response)
18
+ expect(subject.destroy_resource(like)).to be_truthy
19
19
  end
20
20
  end
21
21
  end
@@ -5,9 +5,10 @@ describe Kippt::ListCollection do
5
5
  let(:data_with_multiple_pages) {
6
6
  MultiJson.load(fixture("lists_with_multiple_pages.json").read)
7
7
  }
8
- let(:client) { stub }
8
+ let(:client) { double(:client) }
9
9
  subject { Kippt::ListCollection.new(data, client) }
10
10
  let(:subject_with_multiple_pages) { Kippt::ListCollection.new(data_with_multiple_pages, client) }
11
+ let(:collection_resource_class) { Kippt::Lists }
11
12
 
12
13
  it_behaves_like "collection"
13
14
  end
@@ -21,15 +21,15 @@ describe Kippt::List do
21
21
  describe "#private?" do
22
22
  it "gets data from is_private" do
23
23
  list = Kippt::List.new({"is_private" => true}, nil)
24
- list.private?.should be_true
24
+ expect(list.private?).to be_truthy
25
25
  end
26
26
  end
27
27
 
28
28
  describe "#collaborators" do
29
29
  it "returns the users generated from the data" do
30
30
  list = Kippt::List.new({"collaborators" => {"count" => 1, "data" => [json_fixture("user.json")]}}, nil)
31
- list.collaborators.size.should eq 1
32
- list.collaborators.first.should be_a Kippt::User
31
+ expect(list.collaborators.size).to eq 1
32
+ expect(list.collaborators.first).to be_a Kippt::User
33
33
  end
34
34
  end
35
35
 
@@ -39,8 +39,8 @@ describe Kippt::List do
39
39
  it "returns the clips for the list" do
40
40
  stub_get("/lists/10/clips").
41
41
  to_return(:status => 200, :body => fixture("clips.json"))
42
- subject.should be_a Kippt::Clips
43
- subject.base_uri.should eq "lists/10/clips"
42
+ expect(subject).to be_a Kippt::Clips
43
+ expect(subject.base_uri).to eq "lists/10/clips"
44
44
  end
45
45
  end
46
46
 
@@ -49,10 +49,10 @@ describe Kippt::List do
49
49
  let(:client) { Kippt::Client.new(valid_user_credentials) }
50
50
 
51
51
  it "returns value from the response" do
52
- response = stub(:success? => true, body: {"following" => false})
53
- client.should_receive(:get).with("/api/lists/10/relationship").and_return(response)
52
+ response = double(:response, :success? => true, body: {"following" => false})
53
+ expect(client).to receive(:get).with("/api/lists/10/relationship").and_return(response)
54
54
  list = Kippt::List.new(json_fixture("list.json"), client)
55
- list.following?.should be_false
55
+ expect(list.following?).to be_falsey
56
56
  end
57
57
 
58
58
  it "makes a request" do
@@ -65,8 +65,8 @@ describe Kippt::List do
65
65
 
66
66
  context "when request is unsuccessful" do
67
67
  it "raises an exception" do
68
- response = stub(:success? => false, :body => {"message" => "Weird issue going on."})
69
- client.should_receive(:get).with("/api/lists/10/relationship").and_return(response)
68
+ response = double(:response, :success? => false, :body => {"message" => "Weird issue going on."})
69
+ expect(client).to receive(:get).with("/api/lists/10/relationship").and_return(response)
70
70
  list = Kippt::List.new(json_fixture("list.json"), client)
71
71
 
72
72
  expect {
@@ -81,10 +81,10 @@ describe Kippt::List do
81
81
  let(:client) { Kippt::Client.new(valid_user_credentials) }
82
82
 
83
83
  it "returns true" do
84
- response = stub(:success? => true)
85
- client.should_receive(:post).with("/api/lists/10/relationship", :data => {:action => "follow"}).and_return(response)
84
+ response = double(:response, :success? => true)
85
+ expect(client).to receive(:post).with("/api/lists/10/relationship", :data => {:action => "follow"}).and_return(response)
86
86
  list = Kippt::List.new(json_fixture("list.json"), client)
87
- list.follow.should eq true
87
+ expect(list.follow).to eq true
88
88
  end
89
89
 
90
90
  it "makes a request" do
@@ -98,8 +98,8 @@ describe Kippt::List do
98
98
 
99
99
  context "when request is unsuccessful" do
100
100
  it "raises an exception" do
101
- response = stub(:success? => false, :body => {"message" => "Weird issue going on."})
102
- client.should_receive(:post).with("/api/lists/10/relationship", :data => {:action => "follow"}).and_return(response)
101
+ response = double(:response, :success? => false, :body => {"message" => "Weird issue going on."})
102
+ expect(client).to receive(:post).with("/api/lists/10/relationship", :data => {:action => "follow"}).and_return(response)
103
103
  list = Kippt::List.new(json_fixture("list.json"), client)
104
104
 
105
105
  expect {
@@ -114,10 +114,10 @@ describe Kippt::List do
114
114
  let(:client) { Kippt::Client.new(valid_user_credentials) }
115
115
 
116
116
  it "returns true" do
117
- response = stub(:success? => true)
118
- client.should_receive(:post).with("/api/lists/10/relationship", :data => {:action => "unfollow"}).and_return(response)
117
+ response = double(:response, :success? => true)
118
+ expect(client).to receive(:post).with("/api/lists/10/relationship", :data => {:action => "unfollow"}).and_return(response)
119
119
  list = Kippt::List.new(json_fixture("list.json"), client)
120
- list.unfollow.should eq true
120
+ expect(list.unfollow).to eq true
121
121
  end
122
122
 
123
123
  it "makes a request" do
@@ -131,8 +131,8 @@ describe Kippt::List do
131
131
 
132
132
  context "when request is unsuccessful" do
133
133
  it "raises an exception" do
134
- response = stub(:success? => false, :body => {"message" => "Weird issue going on."})
135
- client.should_receive(:post).with("/api/lists/10/relationship", :data => {:action => "unfollow"}).and_return(response)
134
+ response = double(:response, :success? => false, :body => {"message" => "Weird issue going on."})
135
+ expect(client).to receive(:post).with("/api/lists/10/relationship", :data => {:action => "unfollow"}).and_return(response)
136
136
  list = Kippt::List.new(json_fixture("list.json"), client)
137
137
 
138
138
  expect {
@@ -14,11 +14,11 @@ describe Kippt::Lists do
14
14
 
15
15
  describe "#build" do
16
16
  it "returns new resource" do
17
- subject.build.should be_a(resource_class)
17
+ expect(subject.build).to be_a(resource_class)
18
18
  end
19
19
 
20
20
  it "accepts parameters" do
21
- subject.object_class.should_receive(:new).with({:an => "attribute"}, client)
21
+ expect(subject.object_class).to receive(:new).with({:an => "attribute"}, client)
22
22
  subject.build(:an => "attribute")
23
23
  end
24
24
  end
@@ -3,7 +3,7 @@ require "kippt/saves"
3
3
 
4
4
  describe Kippt::Saves do
5
5
  let(:client) { Kippt::Client.new(valid_user_credentials) }
6
- let(:clip) { stub :clip, :saves_data => fixture("users.json") }
6
+ let(:clip) { double :clip, :saves_data => fixture("users.json") }
7
7
  subject { Kippt::Saves.new(client, clip) }
8
8
 
9
9
  describe "#fetch" do
@@ -13,7 +13,7 @@ describe Kippt::Saves do
13
13
  end
14
14
 
15
15
  it "uses the clip saves data" do
16
- Kippt::UserCollection.should_receive(:new).with({"objects" => clip.saves_data}, client)
16
+ expect(Kippt::UserCollection).to receive(:new).with({"objects" => clip.saves_data}, client)
17
17
  subject.fetch
18
18
  end
19
19
  end