spec/github/gists_spec.rb in github_api-0.4.11 vs spec/github/gists_spec.rb in github_api-0.5.0.rc1
- old
+ new
@@ -5,49 +5,47 @@
describe Github::Gists do
let(:github) { Github.new }
let(:user) { 'peter-murach' }
let(:gist_id) { '1' }
- after { github.user, github.repo, github.oauth_token = nil, nil, nil }
+ after { reset_authentication_for(github) }
- describe "#gists" do
- context 'check aliases' do
- it { github.gists.should respond_to :gists }
- it { github.gists.should respond_to :list_gists }
- end
+ describe "#list" do
+ it { github.gists.should respond_to :all }
context "- unauthenticated user" do
context "resource found" do
before do
stub_get("/users/#{user}/gists").
- to_return(:body => fixture('gists/gists.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
+ to_return(:body => fixture('gists/gists.json'), :status => 200,
+ :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should get the resources" do
- github.gists.gists user
+ github.gists.list user
a_get("/users/#{user}/gists").should have_been_made
end
it "should return array of resources" do
- gists = github.gists.gists user
+ gists = github.gists.list user
gists.should be_an Array
gists.should have(1).items
end
it "should be a mash type" do
- gists = github.gists.gists user
+ gists = github.gists.list user
gists.first.should be_a Hashie::Mash
end
it "should get gist information" do
- gists = github.gists.gists user
+ gists = github.gists.list user
gists.first.user.login.should == 'octocat'
end
it "should yield to a block" do
- github.gists.should_receive(:gists).with(user).and_yield('web')
- github.gists.gists(user) { |param| 'web' }
+ github.gists.should_receive(:list).with(user).and_yield('web')
+ github.gists.list(user) { |param| 'web' }
end
end
context "resource not found" do
before do
@@ -55,24 +53,25 @@
to_return(:body => "", :status => [404, "Not Found"])
end
it "should return 404 with a message 'Not Found'" do
expect {
- github.gists.gists user
+ github.gists.list user
}.to raise_error(Github::Error::NotFound)
end
end
end # unauthenticated user
context '- public' do
before do
stub_get("/gists/public").
- to_return(:body => fixture('gists/gists.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
+ to_return(:body => fixture('gists/gists.json'), :status => 200,
+ :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should get the resources" do
- github.gists.gists
+ github.gists.list
a_get("/gists/public").should have_been_made
end
end
context '- authenticated user' do
@@ -80,19 +79,19 @@
github.oauth_token = OAUTH_TOKEN
stub_get("/gists").
with(:query => {:access_token => OAUTH_TOKEN}).
to_return(:body => fixture('gists/gists.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
end
- after { github.oauth_token = nil }
+ # after { github.oauth_token = nil }
it "should get the resources" do
- github.gists.gists
+ github.gists.list
a_get("/gists").with(:query => {:access_token => OAUTH_TOKEN}).
should have_been_made
end
end
- end # gists
+ end # list
describe "#starred" do
context "resource found" do
before do
stub_get("/gists/starred").
@@ -138,39 +137,37 @@
}.to raise_error(Github::Error::NotFound)
end
end
end # starred
- describe "#gist" do
- context 'check aliases' do
- it { github.gists.should respond_to :gist }
- it { github.gists.should respond_to :get_gist }
- end
+ describe "#get" do
+ it { github.gists.should respond_to :find }
context "resource found" do
before do
stub_get("/gists/#{gist_id}").
- to_return(:body => fixture('gists/gist.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
+ to_return(:body => fixture('gists/gist.json'), :status => 200,
+ :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should fail to get resource without gist id" do
- expect { github.gists.gist(nil)}.to raise_error(ArgumentError)
+ expect { github.gists.get nil }.to raise_error(ArgumentError)
end
it "should get the resource" do
- github.gists.gist gist_id
+ github.gists.get gist_id
a_get("/gists/#{gist_id}").should have_been_made
end
it "should get gist information" do
- gist = github.gists.gist gist_id
+ gist = github.gists.get gist_id
gist.id.should eq gist_id
gist.user.login.should == 'octocat'
end
it "should return mash" do
- gist = github.gists.gist gist_id
+ gist = github.gists.get gist_id
gist.should be_a Hashie::Mash
end
end
context "resource not found" do
@@ -179,17 +176,17 @@
to_return(:body => fixture('gists/gist.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should fail to retrive resource" do
expect {
- github.gists.gist gist_id
+ github.gists.get gist_id
}.to raise_error(Github::Error::NotFound)
end
end
- end # gist
+ end # get
- describe "#create_gist" do
+ describe "#create" do
let(:inputs) {
{
"description" => "the description for this gist",
"public" => true,
"files" => {
@@ -209,39 +206,39 @@
:headers => {:content_type => "application/json; charset=utf-8"})
end
it "should fail to create resource if 'files' input is missing" do
expect {
- github.gists.create_gist inputs.except('files')
+ github.gists.create inputs.except('files')
}.to raise_error(Github::Error::RequiredParams)
end
it "should fail to create resource if 'content' input is missing" do
pending 'add validation for nested attributes'
expect {
- github.gists.create_gist inputs.except('content')
+ github.gists.create inputs.except('content')
}.to raise_error(Github::Error::RequiredParams)
end
it "should fail to create resource if 'public' input is missing" do
expect {
- github.gists.create_gist inputs.except('public')
+ github.gists.create inputs.except('public')
}.to raise_error(Github::Error::RequiredParams)
end
it "should create resource successfully" do
- github.gists.create_gist inputs
+ github.gists.create inputs
a_post("/gists").with(inputs).should have_been_made
end
it "should return the resource" do
- gist = github.gists.create_gist inputs
+ gist = github.gists.create inputs
gist.should be_a Hashie::Mash
end
it "should get the gist information" do
- gist = github.gists.create_gist inputs
+ gist = github.gists.create inputs
gist.user.login.should == 'octocat'
end
end
context "failed to create resource" do
@@ -252,17 +249,17 @@
:headers => {:content_type => "application/json; charset=utf-8"})
end
it "should faile to retrieve resource" do
expect {
- github.gists.create_gist inputs
+ github.gists.create inputs
}.to raise_error(Github::Error::NotFound)
end
end
- end # create_gist
+ end # create
- describe "#edit_gist" do
+ describe "#edit" do
let(:inputs) {
{
"description" => "the description for this gist",
"files" => {
"file1.txt" => {
@@ -288,21 +285,21 @@
:status => 200,
:headers => {:content_type => "application/json; charset=utf-8"})
end
it "should edit resource successfully" do
- github.gists.edit_gist gist_id, inputs
+ github.gists.edit gist_id, inputs
a_patch("/gists/#{gist_id}").with(inputs).should have_been_made
end
it "should return the resource" do
- gist = github.gists.edit_gist gist_id, inputs
+ gist = github.gists.edit gist_id, inputs
gist.should be_a Hashie::Mash
end
it "should get the gist information" do
- gist = github.gists.edit_gist gist_id, inputs
+ gist = github.gists.edit gist_id, inputs
gist.user.login.should == 'octocat'
end
end
context "failed to edit resource" do
@@ -313,15 +310,15 @@
:headers => {:content_type => "application/json; charset=utf-8"})
end
it "should fail to retrieve resource" do
expect {
- github.gists.edit_gist gist_id, inputs
+ github.gists.edit gist_id, inputs
}.to raise_error(Github::Error::NotFound)
end
end
- end # edit_gist
+ end # edit
context '#star' do
before do
stub_put("/gists/#{gist_id}/star").
to_return(:body => '',
@@ -334,11 +331,11 @@
github.gists.star nil
}.to raise_error(ArgumentError)
end
it 'successfully stars a gist' do
- github.gists.star(gist_id)
+ github.gists.star gist_id
a_put("/gists/#{gist_id}/star").should have_been_made
end
it "should return 204 with a message 'Not Found'" do
github.gists.star(gist_id).status.should be 204
@@ -358,11 +355,11 @@
github.gists.unstar nil
}.to raise_error(ArgumentError)
end
it 'successfully stars a gist' do
- github.gists.unstar(gist_id)
+ github.gists.unstar gist_id
a_delete("/gists/#{gist_id}/star").should have_been_made
end
it "should return 204 with a message 'Not Found'" do
github.gists.unstar(gist_id).status.should be 204
@@ -438,36 +435,36 @@
github.gists.fork gist_id
}.to raise_error(Github::Error::NotFound)
end
end # fork
- context "#delete_gist" do
+ context "#delete" do
before do
stub_delete("/gists/#{gist_id}").
to_return(:body => fixture('gists/gist.json'),
:status => 204,
:headers => {:content_type => "application/json; charset=utf-8"})
end
it 'should raise error if gist id not present' do
expect {
- github.gists.delete_gist nil
+ github.gists.delete nil
}.to raise_error(ArgumentError)
end
it "should remove resource successfully" do
- github.gists.delete_gist gist_id
+ github.gists.delete gist_id
a_delete("/gists/#{gist_id}").should have_been_made
end
it "fails to delete resource" do
stub_delete("/gists/#{gist_id}").
to_return(:body => '',
:status => 404,
:headers => {:content_type => "application/json; charset=utf-8"})
expect {
- github.gists.delete_gist gist_id
+ github.gists.delete gist_id
}.to raise_error(Github::Error::NotFound)
end
- end # delete_gist
+ end # delete
end # Github::Gists