spec/client_spec.rb in pmp-0.4.0 vs spec/client_spec.rb in pmp-0.4.1
- old
+ new
@@ -2,13 +2,14 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe PMP::Client do
- before(:each) {
+ before do
@pmp = PMP::Client.new(oauth_token: 'thisisatestvalueonly')
- }
+ @root_doc = json_file(:collection_root)
+ end
it "make with options and pass along" do
pmp = PMP::Client.new(oauth_token: 'thisisatestvalueonly')
pmp.oauth_token.must_equal 'thisisatestvalueonly'
pmp.root.oauth_token.must_equal 'thisisatestvalueonly'
@@ -19,27 +20,17 @@
@pmp.root.wont_be :loaded?
@pmp.root.href.must_equal "https://api.pmp.io/"
end
it "root doc can be loaded" do
- root_doc = json_file(:collection_root)
-
- stub_request(:get, "https://api.pmp.io/").
- with(:headers => {'Accept'=>'application/vnd.collection.doc+json', 'Content-Type'=>'application/vnd.collection.doc+json', 'Host'=>'api.pmp.io:443'}).
- to_return(:status => 200, :body => root_doc, :headers => {})
-
+ stub_request(:get, 'https://api.pmp.io').to_return(:status => 200, :body => @root_doc)
@root = @pmp.root
@root.creator.first.must_be_instance_of PMP::Link
end
it "calls the root doc when client does not have method" do
- root_doc = json_file(:collection_root)
-
- stub_request(:get, "https://api.pmp.io/").
- with(:headers => {'Accept'=>'application/vnd.collection.doc+json', 'Content-Type'=>'application/vnd.collection.doc+json', 'Host'=>'api.pmp.io:443'}).
- to_return(:status => 200, :body => root_doc, :headers => {})
-
+ stub_request(:get, 'https://api.pmp.io').to_return(:status => 200, :body => @root_doc)
@pmp.creator.first.must_be_instance_of PMP::Link
end
it "gets a credentials object" do
@@ -56,13 +47,13 @@
token_expires_in: 24*60*60
}.to_json
stub_request(:post, "https://api.pmp.io/auth/access_token").
with(:body => {"grant_type"=>"client_credentials"},
- :headers => {'Accept'=>'application/json', 'Authorization'=>'Basic dGhpc2lzbm90YS1yZWFsLWNsaWVudC1pZC1zb3Zlcnlzb3JyeTp0aGlzaXNub3RhcmVhbHNlY3JldGVpdGhlcg==', 'Content-Type'=>'application/x-www-form-urlencoded', 'Host'=>'api.pmp.io:443'}).
+ :headers => {'Accept'=>'application/json', 'Authorization'=>'Basic dGhpc2lzbm90YS1yZWFsLWNsaWVudC1pZC1zb3Zlcnlzb3JyeTp0aGlzaXNub3RhcmVhbHNlY3JldGVpdGhlcg==', 'Content-Type'=>'application/x-www-form-urlencoded'}).
to_return(:status => 200, :body => response_body, :headers => {'Content-Type' => 'application/json; charset=utf-8'})
-
+ stub_request(:get, 'https://api.pmp.io').to_return(:status => 200, :body => @root_doc)
client_id = "thisisnota-real-client-id-soverysorry"
client_secret = "thisisnotarealsecreteither"
pmp = PMP::Client.new(client_id: client_id, client_secret: client_secret)