Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adds tests for previously untested code

  • Loading branch information...
commit accc3235983756f9f815158987fe19ea79859661 1 parent 1207585
@vesan authored
Showing with 79 additions and 2 deletions.
  1. +50 −2 spec/kippt/client_spec.rb
  2. +29 −0 spec/spec_helper.rb
View
52 spec/kippt/client_spec.rb
@@ -4,11 +4,19 @@
describe Kippt::Client do
describe "#initialize" do
context "when there is no username" do
- it "raises error"
+ it "raises error" do
+ lambda {
+ Kippt::Client.new(password: "secret")
+ }.should raise_error(ArgumentError, "username is required")
+ end
end
context "when there is no password or token" do
- it "raises error"
+ it "raises error" do
+ lambda {
+ Kippt::Client.new(username: "vesan")
+ }.should raise_error(ArgumentError, "password or token is required")
+ end
end
end
@@ -22,8 +30,48 @@
subject.get("/foobar")
end
end
+
+ describe "error handling" do
+ context "when response status is 401" do
+ it "raises Kippt::APIError with message received from the server" do
+ stub_request(:get, "https://bob:secret@kippt.com/error_path").
+ to_return(:status => 401, :body => "{\"message\": \"Something horrible.\"}")
+
+ lambda {
+ subject.get("/error_path")
+ }.should raise_error(Kippt::APIError, "Something horrible.")
+ end
+ end
+ end
+ end
+
+ describe "#account" do
+ subject { Kippt::Client.new(:username => "bob", :password => "secret") }
+
+ it "returns a Kippt::Account instance" do
+ subject.should_receive(:get).with("account").and_return(
+ stub body: {}
+ )
+ account = subject.account
+ account.should be_a(Kippt::Account)
+ end
end
describe "#lists" do
+ subject { Kippt::Client.new(:username => "bob", :password => "secret") }
+
+ it "returns a Kippt::Lists instance" do
+ lists = subject.lists
+ lists.should be_a(Kippt::Lists)
+ end
+ end
+
+ describe "#clips" do
+ subject { Kippt::Client.new(:username => "bob", :password => "secret") }
+
+ it "returns a Kippt::Clips instance" do
+ clips = subject.clips
+ clips.should be_a(Kippt::Clips)
+ end
end
end
View
29 spec/spec_helper.rb
@@ -96,6 +96,28 @@ def fixture(file)
end
end
+ describe "#objects" do
+ it "returns the objects generated from the data" do
+ subject.objects.each do |object|
+ object.should be_a(subject.object_class)
+ end
+ end
+ end
+
+ describe "#[]" do
+ it "returns a object by index" do
+ subject[0].id.should eq data["objects"][0]["id"]
+ end
+ end
+
+ describe "#each" do
+ it "loops through the objects" do
+ ids = []
+ subject.each {|object| ids << object.id }
+ ids.should eq data["objects"].map { |node| node["id"] }
+ end
+ end
+
describe "#next_page?" do
context "there is a next page" do
it "returns url of the page" do
@@ -180,6 +202,13 @@ def fixture(file)
end
end
+ describe "#destroy" do
+ it "sends delete request to the server" do
+ collection_resource.should_receive(:destroy_resource).with(subject).and_return(true)
+ subject.destroy.should be_true
+ end
+ end
+
describe "#save" do
context "with valid parameters" do
it "sends POST request to server" do
Please sign in to comment.
Something went wrong with that request. Please try again.