kippt 3.0.1 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,11 +14,11 @@ describe Kippt::UserClips 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
@@ -27,7 +27,7 @@ describe Kippt::UserClips do
27
27
  it "returns ClipCollection" do
28
28
  stub_get("/#{base_uri}/favorites").
29
29
  to_return(:status => 200, :body => fixture("clips.json"))
30
- subject.favorites.should be_a Kippt::Clips
30
+ expect(subject.favorites).to be_a Kippt::Clips
31
31
  end
32
32
  end
33
33
 
@@ -35,7 +35,7 @@ describe Kippt::UserClips do
35
35
  it "returns ClipCollection" do
36
36
  stub_get("/#{base_uri}/likes").
37
37
  to_return(:status => 200, :body => fixture("clips.json"))
38
- subject.likes.should be_a Kippt::Clips
38
+ expect(subject.likes).to be_a Kippt::Clips
39
39
  end
40
40
  end
41
41
  end
@@ -6,9 +6,10 @@ describe Kippt::UserCollection do
6
6
  let(:data_with_multiple_pages) {
7
7
  MultiJson.load(fixture("users_with_multiple_pages.json").read)
8
8
  }
9
- let(:client) { stub }
9
+ let(:client) { double(:client) }
10
10
  subject { Kippt::UserCollection.new(data, client) }
11
11
  let(:subject_with_multiple_pages) { Kippt::UserCollection.new(data_with_multiple_pages, client) }
12
+ let(:collection_resource_class) { Kippt::Users }
12
13
 
13
14
  it_behaves_like "collection"
14
15
  end
@@ -14,11 +14,11 @@ describe Kippt::UserLists 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
@@ -21,7 +21,7 @@ describe Kippt::User do
21
21
  describe "#pro?" do
22
22
  it "gets data from is_pro" do
23
23
  user = Kippt::User.new({:is_pro => true}, nil)
24
- user.pro?.should be_true
24
+ expect(user.pro?).to be_truthy
25
25
  end
26
26
  end
27
27
 
@@ -31,52 +31,52 @@ describe Kippt::User do
31
31
  user = Kippt::User.new(nil, client)
32
32
 
33
33
  likes = user.likes
34
- likes.should be_a(Kippt::UserLikes)
35
- likes.user.should eq user
34
+ expect(likes).to be_a(Kippt::UserLikes)
35
+ expect(likes.user).to eq user
36
36
  end
37
37
  end
38
38
 
39
39
  describe "#following?" do
40
40
  it "uses Kippt::FollowRelationship to get the information" do
41
- follow_relationship = mock(:follow_relationship,
41
+ follow_relationship = double(:follow_relationship,
42
42
  :following? => true)
43
- Kippt::FollowRelationship.stub(:new).and_return(follow_relationship)
43
+ allow(Kippt::FollowRelationship).to receive(:new).and_return(follow_relationship)
44
44
  user = Kippt::User.new({:is_pro => true}, nil)
45
- user.following?.should be_true
45
+ expect(user.following?).to be_truthy
46
46
  end
47
47
  end
48
48
 
49
49
  describe "#follower_count" do
50
50
  it "returns the count from the fetched data" do
51
51
  user = Kippt::User.new({:counts => {"follows" => 11}})
52
- user.follower_count.should eq 11
52
+ expect(user.follower_count).to eq 11
53
53
  end
54
54
  end
55
55
 
56
56
  describe "#following_count" do
57
57
  it "returns the count from the fetched data" do
58
58
  user = Kippt::User.new({:counts => {"followed_by" => 111}})
59
- user.following_count.should eq 111
59
+ expect(user.following_count).to eq 111
60
60
  end
61
61
  end
62
62
 
63
63
  describe "#follow" do
64
64
  it "sets up a Kippt::FollowRelationship and calls it" do
65
- follow_relationship = mock(:follow_relationship,
65
+ follow_relationship = double(:follow_relationship,
66
66
  :follow => true)
67
- Kippt::FollowRelationship.stub(:new).and_return(follow_relationship)
67
+ allow(Kippt::FollowRelationship).to receive(:new).and_return(follow_relationship)
68
68
  user = Kippt::User.new
69
- user.follow.should be_true
69
+ expect(user.follow).to be_truthy
70
70
  end
71
71
  end
72
72
 
73
73
  describe "#unfollow" do
74
74
  it "sets up a Kippt::FollowRelationship and calls it" do
75
- follow_relationship = mock(:follow_relationship,
75
+ follow_relationship = double(:follow_relationship,
76
76
  :unfollow => true)
77
- Kippt::FollowRelationship.stub(:new).and_return(follow_relationship)
77
+ allow(Kippt::FollowRelationship).to receive(:new).and_return(follow_relationship)
78
78
  user = Kippt::User.new
79
- user.unfollow.should be_true
79
+ expect(user.unfollow).to be_truthy
80
80
  end
81
81
  end
82
82
  end
@@ -35,9 +35,9 @@ describe Kippt::Users do
35
35
 
36
36
  context "with invalid keys" do
37
37
  it "raises ArgumentError" do
38
- lambda {
38
+ expect {
39
39
  subject.search(:q => "bunny", :stuff => true)
40
- }.should raise_error(ArgumentError, "'stuff' is not a valid search parameter")
40
+ }.to raise_error(ArgumentError, "'stuff' is not a valid search parameter")
41
41
  end
42
42
  end
43
43
  end
@@ -47,13 +47,13 @@ describe Kippt::Users do
47
47
  stub_get("/users/search?q=bunny").
48
48
  to_return(:status => 200, :body => fixture("users_with_multiple_pages.json"))
49
49
  users = subject.search("bunny")
50
- users.should be_a Kippt::UserCollection
50
+ expect(users).to be_a Kippt::UserCollection
51
51
  end
52
52
 
53
53
  it "sets UserCollection client" do
54
54
  stub_get("/users/search?q=bunny").
55
55
  to_return(:status => 200, :body => fixture("users_with_multiple_pages.json"))
56
- Kippt::UserCollection.should_receive(:new).with(kind_of(Hash), kind_of(Kippt::Client))
56
+ expect(Kippt::UserCollection).to receive(:new).with(kind_of(Hash), kind_of(Kippt::Client))
57
57
  users = subject.search("bunny")
58
58
  end
59
59
  end
@@ -1,31 +1,31 @@
1
1
  shared_examples_for "collection" do
2
2
  it "is Enumberable" do
3
- subject.should be_a(Enumerable)
3
+ expect(subject).to be_a(Enumerable)
4
4
  end
5
5
 
6
6
  describe "#offset" do
7
7
  it "returns offset of the results" do
8
- subject.offset.should eq 0
8
+ expect(subject.offset).to eq 0
9
9
  end
10
10
  end
11
11
 
12
12
  describe "#limit" do
13
13
  it "returns limit of the results" do
14
- subject.limit.should eq 20
14
+ expect(subject.limit).to eq 20
15
15
  end
16
16
  end
17
17
 
18
18
  describe "#objects" do
19
19
  it "returns the objects generated from the data" do
20
20
  subject.objects.each do |object|
21
- object.should be_a(subject.object_class)
21
+ expect(object).to be_a(subject.object_class)
22
22
  end
23
23
  end
24
24
  end
25
25
 
26
26
  describe "#[]" do
27
27
  it "returns a object by index" do
28
- subject[0].id.should eq data["objects"][0]["id"]
28
+ expect(subject[0].id).to eq data["objects"][0]["id"]
29
29
  end
30
30
  end
31
31
 
@@ -33,45 +33,44 @@ shared_examples_for "collection" do
33
33
  it "loops through the objects" do
34
34
  ids = []
35
35
  subject.each {|object| ids << object.id }
36
- ids.should eq data["objects"].map { |node| node["id"] }
36
+ expect(ids).to eq data["objects"].map { |node| node["id"] }
37
37
  end
38
38
  end
39
39
 
40
40
  describe "#next_page?" do
41
41
  context "there is a next page" do
42
42
  it "returns url of the page" do
43
- subject_with_multiple_pages.next_page?.should eq data_with_multiple_pages["meta"]["next"]
43
+ expect(subject_with_multiple_pages.next_page?).to eq data_with_multiple_pages["meta"]["next"]
44
44
  end
45
45
  end
46
46
 
47
47
  context "there is no next page" do
48
48
  it "returns nil" do
49
- subject.next_page?.should eq nil
49
+ expect(subject.next_page?).to eq nil
50
50
  end
51
51
  end
52
52
  end
53
53
 
54
54
  describe "#next_page" do
55
55
  context "if there is a next page" do
56
- let(:collection_resource) { stub }
56
+ let(:collection_resource) { double(:collection_resource) }
57
57
 
58
58
  it "gets the next page of results from the collection resource" do
59
- client.stub(:collection_resource_for).and_return(collection_resource)
59
+ expect(client).to receive(:collection_resource_for).with(collection_resource_class, data_with_multiple_pages["meta"]["next"]).and_return(collection_resource)
60
60
 
61
- results = stub
62
- collection_resource.should_receive(:collection_from_url).
63
- with(data_with_multiple_pages["meta"]["next"]).
61
+ results = double :results
62
+ expect(collection_resource).to receive(:fetch).
64
63
  and_return(results)
65
64
 
66
- subject_with_multiple_pages.next_page.should eq results
65
+ expect(subject_with_multiple_pages.next_page).to eq results
67
66
  end
68
67
  end
69
68
 
70
69
  context "if there is no next page" do
71
70
  it "raises an error" do
72
- lambda {
71
+ expect {
73
72
  subject.next_page
74
- }.should raise_error(Kippt::APIError, "There is no next page")
73
+ }.to raise_error(Kippt::APIError, "There is no next page")
75
74
  end
76
75
  end
77
76
  end
@@ -79,38 +78,39 @@ shared_examples_for "collection" do
79
78
  describe "#previous_page?" do
80
79
  context "there is a previous page" do
81
80
  it "returns url of the page" do
82
- subject_with_multiple_pages.previous_page?.should eq data_with_multiple_pages["meta"]["previous"]
81
+ expect(subject_with_multiple_pages.previous_page?).to eq data_with_multiple_pages["meta"]["previous"]
83
82
  end
84
83
  end
85
84
 
86
85
  context "there is no previous page" do
87
86
  it "returns nil" do
88
- subject.previous_page?.should be_nil
87
+ expect(subject.previous_page?).to be_nil
89
88
  end
90
89
  end
91
90
  end
92
91
 
93
92
  describe "#previous_page" do
94
93
  context "if there is a previous page" do
95
- let(:collection_resource) { stub }
94
+ let(:collection_resource) { double(:collection_resource) }
96
95
 
97
96
  it "gets the previous page of results from the collection resource" do
98
- client.stub(:collection_resource_for).and_return(collection_resource)
97
+ expect(client).to receive(:collection_resource_for)
98
+ .with(collection_resource_class, data_with_multiple_pages["meta"]["previous"])
99
+ .and_return(collection_resource)
99
100
 
100
- results = stub
101
- collection_resource.should_receive(:collection_from_url).
102
- with(data_with_multiple_pages["meta"]["previous"]).
101
+ results = double :results
102
+ expect(collection_resource).to receive(:fetch).
103
103
  and_return(results)
104
104
 
105
- subject_with_multiple_pages.previous_page.should eq results
105
+ expect(subject_with_multiple_pages.previous_page).to eq results
106
106
  end
107
107
  end
108
108
 
109
109
  context "if there is no previous page" do
110
110
  it "raises an error" do
111
- lambda {
111
+ expect {
112
112
  subject.previous_page
113
- }.should raise_error(Kippt::APIError, "There is no previous page")
113
+ }.to raise_error(Kippt::APIError, "There is no previous page")
114
114
  end
115
115
  end
116
116
  end
@@ -5,8 +5,8 @@ shared_examples_for "collection resource" do
5
5
  let(:resource) { double :resource }
6
6
 
7
7
  it "builds and saves a resource" do
8
- resource.should_receive :save
9
- subject.should_receive(:build).with(:an => "attribute").and_return(resource)
8
+ expect(resource).to receive :save
9
+ expect(subject).to receive(:build).with(:an => "attribute").and_return(resource)
10
10
  subject.create(:an => "attribute")
11
11
  end
12
12
  end
@@ -16,9 +16,9 @@ shared_examples_for "read collection resource" do
16
16
 
17
17
  context "when passed unrecognized arguments" do
18
18
  it "raises error" do
19
- lambda {
19
+ expect {
20
20
  subject.fetch(:foobar => true)
21
- }.should raise_error(
21
+ }.to raise_error(
22
22
  ArgumentError, "Unrecognized argument: foobar")
23
23
  end
24
24
  end
@@ -28,22 +28,22 @@ shared_examples_for "read collection resource" do
28
28
  it "fetches single resource" do
29
29
  stub_get("/#{base_uri}/10").
30
30
  to_return(:status => 200, :body => fixture("#{singular_fixture}.json"))
31
- subject[10].id.should eq 10
31
+ expect(subject[10].id).to eq 10
32
32
  end
33
33
 
34
34
  it "returns resource" do
35
35
  stub_get("/#{base_uri}/10").
36
36
  to_return(:status => 200, :body => fixture("#{singular_fixture}.json"))
37
- subject[10].should be_a(resource_class)
37
+ expect(subject[10]).to be_a(resource_class)
38
38
  end
39
39
 
40
40
  context "when resource is not found" do
41
41
  it "raises exception" do
42
42
  stub_get("/#{base_uri}/10").
43
- to_return(:status => 404, :body => {"message" => "Resource not found."})
44
- lambda {
43
+ to_return(:status => 404, :body => {"message" => "Resource not found."}.to_json)
44
+ expect {
45
45
  subject[10]
46
- }.should raise_error(
46
+ }.to raise_error(
47
47
  Kippt::APIError, "Resource could not be loaded: Resource not found.")
48
48
  end
49
49
  end
@@ -51,27 +51,7 @@ shared_examples_for "read collection resource" do
51
51
 
52
52
  describe "#find" do
53
53
  it "exists" do
54
- subject.respond_to?(:find).should be_true
55
- end
56
- end
57
-
58
- describe "#collection_from_url" do
59
- it "returns a new collection" do
60
- stub_get("/#{base_uri}/?limit=20&offset=20").
61
- to_return(:status => 200, :body => fixture("#{collection_fixture}.json"))
62
- collection = subject.collection_from_url("/api/#{base_uri}/?limit=20&offset=20")
63
- collection.should be_a(collection_class)
64
- end
65
-
66
- context "when passed URL is blank" do
67
- it "raises ArgumentError" do
68
- lambda {
69
- subject.collection_from_url("")
70
- }.should raise_error(ArgumentError, "The parameter URL can't be blank")
71
- lambda {
72
- subject.collection_from_url(nil)
73
- }.should raise_error(ArgumentError, "The parameter URL can't be blank")
74
- end
54
+ expect(subject.respond_to?(:find)).to be_truthy
75
55
  end
76
56
  end
77
57
  end
@@ -2,7 +2,7 @@ shared_examples_for "resource" do
2
2
  describe "attribute accessors" do
3
3
  it "delegates to attributes" do
4
4
  attributes.each do |attribute_name|
5
- subject.send(attribute_name).should eq data[attribute_name.to_s]
5
+ expect(subject.send(attribute_name)).to eq data[attribute_name.to_s]
6
6
  end
7
7
  end
8
8
  end
@@ -10,70 +10,70 @@ shared_examples_for "resource" do
10
10
  describe "mapped attribute accessors" do
11
11
  it "delegates to attributes and wraps with to a object" do
12
12
  mapped_attributes.each do |attribute_name, attribute_class|
13
- subject.send(attribute_name).class.to_s.should eq attribute_class
13
+ expect(subject.send(attribute_name).class.to_s).to eq attribute_class
14
14
  end
15
15
  end
16
16
  end
17
17
 
18
18
  describe "#destroy" do
19
- let(:collection_resource) { stub }
19
+ let(:collection_resource) { double(:collection_resource) }
20
20
 
21
21
  it "sends delete request to the server" do
22
- client.stub(:collection_resource_for).and_return(collection_resource)
23
- collection_resource.should_receive(:destroy_resource).with(subject).and_return(true)
24
- subject.destroy.should be_true
22
+ allow(client).to receive(:collection_resource_for).and_return(collection_resource)
23
+ expect(collection_resource).to receive(:destroy_resource).with(subject).and_return(true)
24
+ expect(subject.destroy).to be_truthy
25
25
  end
26
26
  end
27
27
 
28
28
  describe "#save" do
29
29
  context "with valid parameters" do
30
- let(:collection_resource) { stub }
30
+ let(:collection_resource) { double(:collection_resource) }
31
31
 
32
32
  before do
33
- client.stub(:collection_resource_for).and_return(collection_resource)
33
+ allow(client).to receive(:collection_resource_for).and_return(collection_resource)
34
34
  end
35
35
 
36
36
  it "sends POST request to server" do
37
- collection_resource.should_receive(:save_resource).with(subject).and_return({})
37
+ expect(collection_resource).to receive(:save_resource).with(subject).and_return({})
38
38
  subject.save
39
39
  end
40
40
 
41
41
  it "returns true" do
42
- collection_resource.stub(:save_resource).and_return(
42
+ allow(collection_resource).to receive(:save_resource).and_return(
43
43
  {:success => true})
44
- subject.save.should be_true
44
+ expect(subject.save).to be_truthy
45
45
  end
46
46
 
47
47
  it "sets the updated attributes received from the server" do
48
- collection_resource.stub(:save_resource).and_return(
48
+ allow(collection_resource).to receive(:save_resource).and_return(
49
49
  {:success => true, :resource => {:id => 9999}})
50
50
  subject.save
51
- subject.id.should eq 9999
51
+ expect(subject.id).to eq 9999
52
52
  end
53
53
  end
54
54
 
55
55
  context "with invalid parameters" do
56
- let(:collection_resource) { stub }
56
+ let(:collection_resource) { double(:collection_resource) }
57
57
 
58
58
  before do
59
- client.stub(:collection_resource_for).and_return(collection_resource)
60
- collection_resource.stub(:save_resource).and_return({:success => false, :error_message => "No url."})
59
+ allow(client).to receive(:collection_resource_for).and_return(collection_resource)
60
+ allow(collection_resource).to receive(:save_resource).and_return({:success => false, :error_message => "No url."})
61
61
  end
62
62
 
63
63
  it "sets an error messages" do
64
64
  subject.save
65
- subject.errors.should eq ["No url."]
65
+ expect(subject.errors).to eq ["No url."]
66
66
  end
67
67
 
68
68
  it "returns false" do
69
- subject.save.should be_false
69
+ expect(subject.save).to be_falsey
70
70
  end
71
71
 
72
72
  it "clears previous errors" do
73
73
  subject.save
74
- subject.errors.should eq ["No url."]
74
+ expect(subject.errors).to eq ["No url."]
75
75
  subject.save
76
- subject.errors.should eq ["No url."]
76
+ expect(subject.errors).to eq ["No url."]
77
77
  end
78
78
  end
79
79
  end