rapidash 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
- ---
2
- SHA512:
3
- data.tar.gz: b62fefb161e5c2171a36bdac90549d2cf41c33cb19b0d76f2738876a27370a91ee9fc5fd76d3df47c18b0c92cb1ccfa8bc3fc3813df78dbbb0a347ed8c784fe5
4
- metadata.gz: 0f553c52c3d89edc685e192726661b10116898ae01b2735172116f8e4144a2d35c8c501eb68af322da925abf10f8578b61aa205e9b9b61c7fba9582f21bc3872
5
- SHA1:
6
- data.tar.gz: ec0208f74c6ac0a9d02691baf5727dc1d4d2330d
7
- metadata.gz: a6adad2e79593a67d205b702b2e05e489a37d9cc
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9a7084f2f5d2446b0e2de5aa33217e617df67a8a
4
+ data.tar.gz: c9010836f7f1e8da5846ba6fb3aad103a5b8d1c4
5
+ SHA512:
6
+ metadata.gz: e2fca5a4cae9cd85ef8910e6a814e8e5d8a79ca57c9f77c5fedf8823ef996df5fa1606aba6a5a03306d633c435540ffe7be2bb14c4491267d2317a28fccd672d
7
+ data.tar.gz: 7fb3cdde9f95808b38dcd54033beac4979e325626b100dee1644a531764cc510b753385b12a9b218bf4170d102b204c50ad7bfb7064b7cfc3e959bc9cfd4bd16
@@ -1,8 +1,9 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.8.7
4
- - 1.9.2
5
3
  - 1.9.3
6
- - 2.0.0
7
- - jruby-18mode
4
+ - 2.0
5
+ - 2.1
6
+ - 2.2
8
7
  - jruby-19mode
8
+ - jruby-20mode
9
+ - jruby-21mode
@@ -4,11 +4,15 @@ require 'faraday_middleware/multi_json'
4
4
 
5
5
  module Rapidash
6
6
  module HTTPClient
7
- attr_accessor :login, :password
7
+ attr_accessor :login, :password, :request_default_options
8
8
  attr_writer :connection
9
9
 
10
+ # Provide login and password fields for basic HTTP authentication
11
+ # Provide request_default_options field for default options to be provided on each http request
12
+ # To set a default User-agent which identifies your application, provide
13
+ # { request_default_options: { header: { user_agent: 'My great new App V.0.1 Contact: me@me.com'} } }
10
14
  def initialize(options = {})
11
- [:login, :password].each do |key|
15
+ [:login, :password, :request_default_options].each do |key|
12
16
  self.send("#{key.to_s}=".to_sym, options[key])
13
17
  end
14
18
  end
@@ -26,6 +30,7 @@ module Rapidash
26
30
  end
27
31
 
28
32
  def request(verb, url, options = {})
33
+ options.merge!(self.request_default_options) if self.request_default_options
29
34
  url = connection.build_url(normalize_url(url), options[:params]).to_s
30
35
  response = connection.run_request(verb, url, options[:body], options[:header])
31
36
 
@@ -1,3 +1,3 @@
1
1
  module Rapidash
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -18,22 +18,17 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- if RUBY_VERSION < "1.9.3"
22
- spec.add_dependency "activesupport", "~> 3.0"
23
- spec.add_dependency "mime-types", "~> 1.25.0"
24
- else
25
- spec.add_dependency "activesupport", ">= 3.0.0"
26
- end
21
+ spec.add_dependency "activesupport", ">= 3.0.0"
27
22
  spec.add_development_dependency "bundler", "~> 1.0"
28
23
  spec.add_development_dependency "rake"
29
- spec.add_development_dependency "rspec", "~> 2.8"
30
- spec.add_development_dependency "simplecov", "~> 0.7"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ spec.add_development_dependency "simplecov"
31
26
  spec.add_development_dependency "json"
32
27
  spec.add_development_dependency "coveralls"
33
28
 
34
29
  spec.add_dependency "faraday", "~> 0.8"
35
30
  spec.add_dependency "faraday_middleware", "~> 0.9"
36
31
  spec.add_dependency "faraday_middleware-multi_json", "~> 0.0"
37
- spec.add_dependency "oauth2", "~>0.6"
38
- spec.add_dependency "hashie", "~>1.2"
32
+ spec.add_dependency "oauth2", ">= 0.6", "< 2.0"
33
+ spec.add_dependency "hashie", ">1.2", "< 4.0"
39
34
  end
@@ -7,7 +7,7 @@ describe Faraday::Response::RaiseRapidashError do
7
7
  it "should not raise an exception" do
8
8
  expect {
9
9
  subject.on_complete(env)
10
- }.to_not raise_exception(Rapidash::ResponseError)
10
+ }.to_not raise_exception
11
11
  end
12
12
  end
13
13
 
@@ -26,15 +26,15 @@ describe Rapidash::Base do
26
26
  describe ".initialize" do
27
27
 
28
28
  it "should assume a default based on the class name" do
29
- Base.new.instance_variable_get(:@url).should eql("bases")
29
+ expect(Base.new.instance_variable_get(:@url)).to eql("bases")
30
30
  end
31
31
 
32
32
  it "should ignore any modules when infering the URL" do
33
- Rapidash::Resource.new.instance_variable_get(:@url).should eql("resources")
33
+ expect(Rapidash::Resource.new.instance_variable_get(:@url)).to eql("resources")
34
34
  end
35
35
 
36
36
  it "should override the URL if set" do
37
- BaseTester.new.instance_variable_get(:@url).should eql("tester")
37
+ expect(BaseTester.new.instance_variable_get(:@url)).to eql("tester")
38
38
  end
39
39
  end
40
40
 
@@ -56,9 +56,9 @@ describe Rapidash::Base do
56
56
 
57
57
  describe ".create!" do
58
58
  it "should set the method to post and set the body" do
59
- subject.should_receive(:call!)
59
+ allow(subject).to receive(:call!)
60
60
  subject.create!(post)
61
- subject.instance_variable_get(:@options).should eql({
61
+ expect(subject.instance_variable_get(:@options)).to eql({
62
62
  :method => :post,
63
63
  :body => post
64
64
  })
@@ -66,9 +66,9 @@ describe Rapidash::Base do
66
66
 
67
67
  it "should use the root element if one is defined" do
68
68
  subject = RootTester.new
69
- subject.should_receive(:call!)
69
+ allow(subject).to receive(:call!)
70
70
  subject.create!(no_root)
71
- subject.instance_variable_get(:@options).should eql({
71
+ expect(subject.instance_variable_get(:@options)).to eql({
72
72
  :method => :post,
73
73
  :body => post
74
74
  })
@@ -77,9 +77,9 @@ describe Rapidash::Base do
77
77
 
78
78
  describe ".update!" do
79
79
  it "should set the method to put and set the body" do
80
- subject.should_receive(:call!)
80
+ allow(subject).to receive(:call!)
81
81
  subject.update!(post)
82
- subject.instance_variable_get(:@options).should eql({
82
+ expect(subject.instance_variable_get(:@options)).to eql({
83
83
  :method => :put,
84
84
  :body => post
85
85
  })
@@ -87,9 +87,9 @@ describe Rapidash::Base do
87
87
 
88
88
  it "should use the patch verb if set on the client" do
89
89
  client.class.patch = true
90
- subject.should_receive(:call!)
90
+ allow(subject).to receive(:call!)
91
91
  subject.update!(post)
92
- subject.instance_variable_get(:@options).should eql({
92
+ expect(subject.instance_variable_get(:@options)).to eql({
93
93
  :method => :patch,
94
94
  :body => post
95
95
  })
@@ -97,9 +97,9 @@ describe Rapidash::Base do
97
97
 
98
98
  it "should use the root element if one is defined" do
99
99
  subject = RootTester.new(client)
100
- subject.should_receive(:call!)
100
+ allow(subject).to receive(:call!)
101
101
  subject.update!(no_root)
102
- subject.instance_variable_get(:@options).should eql({
102
+ expect(subject.instance_variable_get(:@options)).to eql({
103
103
  :method => :patch,
104
104
  :body => post
105
105
  })
@@ -108,9 +108,9 @@ describe Rapidash::Base do
108
108
 
109
109
  describe ".delete!" do
110
110
  it "should set the method to delete" do
111
- subject.should_receive(:call!)
111
+ allow(subject).to receive(:call!)
112
112
  subject.delete!
113
- subject.instance_variable_get(:@options).should eql({:method => :delete})
113
+ expect(subject.instance_variable_get(:@options)).to eql({:method => :delete})
114
114
  end
115
115
 
116
116
  end
@@ -118,13 +118,20 @@ describe Rapidash::Base do
118
118
  describe ".call!" do
119
119
  it "should call get on the client" do
120
120
  subject.url = "tester/1"
121
- client.should_receive(:get).with("tester/1", {:headers => headers})
121
+ allow(client).to receive(:get).with("tester/1", {:headers => headers})
122
122
  subject.call!
123
123
  end
124
124
 
125
+ it "should set extra headers on the client" do
126
+ user_agent_header = {header: { user_agent: 'My own Faraday version'}}
127
+ subject = BaseTester.new(client,user_agent_header)
128
+ subject.url = "tester/1"
129
+ allow(client).to receive(:get).with("tester/1", {:headers => headers}.merge(user_agent_header) )
130
+ subject.call!
131
+ end
125
132
 
126
133
  it "should call a post on the client if set" do
127
- client.should_receive(:post).with("tester", {:headers => headers})
134
+ allow(client).to receive(:post).with("tester", {:headers => headers})
128
135
  subject.options = {:method => :post}
129
136
  subject.url = "tester"
130
137
  subject.call!
@@ -133,23 +140,23 @@ describe Rapidash::Base do
133
140
 
134
141
  describe ".base_url" do
135
142
  it "should return an empty string if no previous url is set" do
136
- subject.send(:base_url).should eql("")
143
+ expect(subject.send(:base_url)).to eql("")
137
144
  end
138
145
 
139
146
  it "should return the previous url if set" do
140
147
  subject.options = {:previous_url => "users/Gazler"}
141
- subject.send(:base_url).should eql("users/Gazler/")
148
+ expect(subject.send(:base_url)).to eql("users/Gazler/")
142
149
  end
143
150
  end
144
151
 
145
152
  describe ".resource_url" do
146
153
  it "should return the class name as a url if none is specified" do
147
- subject.send(:resource_url).should eql("basetesters")
154
+ expect(subject.send(:resource_url)).to eql("basetesters")
148
155
  end
149
156
 
150
157
  it "should return the previous url if set" do
151
158
  subject.options = {:url => "people"}
152
- subject.send(:resource_url).should eql("people")
159
+ expect(subject.send(:resource_url)).to eql("people")
153
160
  end
154
161
  end
155
162
 
@@ -31,16 +31,16 @@ describe Rapidash::Client do
31
31
  describe "#method" do
32
32
  it "should include the HTTPClient" do
33
33
  client = HTTPClientTester.new
34
- client.class.ancestors.should include(Rapidash::HTTPClient)
34
+ expect(client.class.ancestors).to include(Rapidash::HTTPClient)
35
35
  end
36
36
 
37
37
  it "should include the OAuthClient" do
38
38
  client = OAuthClientTester.new({:uid => "foo", :secret => "bar", :site => "baz"})
39
- client.class.ancestors.should include(Rapidash::OAuthClient)
39
+ expect(client.class.ancestors).to include(Rapidash::OAuthClient)
40
40
  end
41
41
 
42
42
  it "should include the OAuthClient" do
43
- test_client.class.ancestors.should include(Rapidash::TestClient)
43
+ expect(test_client.class.ancestors).to include(Rapidash::TestClient)
44
44
  end
45
45
 
46
46
  it "should raise an error on anything else" do
@@ -54,19 +54,19 @@ describe Rapidash::Client do
54
54
 
55
55
  describe "#use_patch" do
56
56
  it "should set the patch variable to true" do
57
- HTTPClientPatchTester.new.class.instance_variable_get(:@patch).should eql(true)
57
+ expect(HTTPClientPatchTester.new.class.instance_variable_get(:@patch)).to eql(true)
58
58
  end
59
59
  end
60
60
 
61
61
  describe "#extension" do
62
62
  it "should set the url_extension variable" do
63
- HTTPClientExtensionTester.new.class.instance_variable_get(:@extension).should eql(:js)
63
+ expect(HTTPClientExtensionTester.new.class.instance_variable_get(:@extension)).to eql(:js)
64
64
  end
65
65
  end
66
66
 
67
67
  describe "#raise_errors" do
68
68
  it "should set the raise_error variable" do
69
- HTTPClientErrorTester.new.class.instance_variable_get(:@raise_error).should eql(true)
69
+ expect(HTTPClientErrorTester.new.class.instance_variable_get(:@raise_error)).to eql(true)
70
70
  end
71
71
  end
72
72
 
@@ -79,18 +79,18 @@ describe Rapidash::Client do
79
79
 
80
80
  describe ".site=" do
81
81
  it "should clear the connection variable after set new site" do
82
- test_client.instance_variable_get(:@connection).should eql(nil)
82
+ expect(test_client.instance_variable_get(:@connection)).to eql(nil)
83
83
  test_client.site = "foo"
84
84
  test_client.instance_variable_set(:@connection, "Not nil")
85
85
 
86
86
  test_client.site = "bar"
87
- test_client.instance_variable_get(:@connection).should eql(nil)
87
+ expect(test_client.instance_variable_get(:@connection)).to eql(nil)
88
88
  end
89
89
 
90
90
  it "should set the site variable" do
91
- test_client.instance_variable_get(:@site).should eql(nil)
91
+ expect(test_client.instance_variable_get(:@site)).to eql(nil)
92
92
  test_client.site = "foo"
93
- test_client.instance_variable_get(:@site).should eql("foo")
93
+ expect(test_client.instance_variable_get(:@site)).to eql("foo")
94
94
  end
95
95
  end
96
96
 
@@ -111,35 +111,35 @@ describe Rapidash::Client do
111
111
 
112
112
  describe ".get" do
113
113
  it "should call request" do
114
- test_client.should_receive(:request).with(:get, "foo", {})
114
+ allow(test_client).to receive(:request).with(:get, "foo", {})
115
115
  test_client.get("foo")
116
116
  end
117
117
  end
118
118
 
119
119
  describe ".post" do
120
120
  it "should call request" do
121
- test_client.should_receive(:request).with(:post, "foo", {})
121
+ allow(test_client).to receive(:request).with(:post, "foo", {})
122
122
  test_client.post("foo")
123
123
  end
124
124
  end
125
125
 
126
126
  describe ".put" do
127
127
  it "should call request" do
128
- test_client.should_receive(:request).with(:put, "foo", {})
128
+ allow(test_client).to receive(:request).with(:put, "foo", {})
129
129
  test_client.put("foo")
130
130
  end
131
131
  end
132
132
 
133
133
  describe ".patch" do
134
134
  it "should call request" do
135
- test_client.should_receive(:request).with(:patch, "foo", {})
135
+ allow(test_client).to receive(:request).with(:patch, "foo", {})
136
136
  test_client.patch("foo")
137
137
  end
138
138
  end
139
139
 
140
140
  describe ".delete" do
141
141
  it "should call request" do
142
- test_client.should_receive(:request).with(:delete, "foo", {})
142
+ allow(test_client).to receive(:request).with(:delete, "foo", {})
143
143
  test_client.delete("foo")
144
144
  end
145
145
  end
@@ -147,15 +147,15 @@ describe Rapidash::Client do
147
147
  describe ".normalize_url" do
148
148
  it "should use the instance extension if set" do
149
149
  test_client.extension = :json
150
- test_client.normalize_url("users").should eql("users.json")
150
+ expect(test_client.normalize_url("users")).to eql("users.json")
151
151
  end
152
152
 
153
153
  it "should use the class extension if set" do
154
- HTTPClientExtensionTester.new.normalize_url("users").should eql("users.js")
154
+ expect(HTTPClientExtensionTester.new.normalize_url("users")).to eql("users.js")
155
155
  end
156
156
 
157
157
  it "should return the url if no extension if set" do
158
- test_client.normalize_url("users").should eql("users")
158
+ expect(test_client.normalize_url("users")).to eql("users")
159
159
  end
160
160
  end
161
161
  end
@@ -23,7 +23,7 @@ describe Rapidash::HTTPClient do
23
23
  describe ".connection" do
24
24
  it "should create a Faraday object" do
25
25
  subject.site = "http://example.com/"
26
- subject.connection.class.should eql(Faraday::Connection)
26
+ expect(subject.connection.class).to eql(Faraday::Connection)
27
27
  end
28
28
 
29
29
  it "should raise Configuration error if site nil" do
@@ -33,7 +33,7 @@ describe Rapidash::HTTPClient do
33
33
  end
34
34
 
35
35
  it "should use the site variable if set" do
36
- Faraday.should_receive(:new).with("http://example.com/")
36
+ allow(Faraday).to receive(:new).with("http://example.com/")
37
37
  subject.site = "http://example.com/"
38
38
  subject.connection
39
39
  end
@@ -63,8 +63,19 @@ describe Rapidash::HTTPClient do
63
63
 
64
64
  it "should call response" do
65
65
  response = double(:body => "response")
66
- subject.connection.should_receive(:run_request).with(:get, "http://example.com/foo", nil, nil).and_return(response)
66
+ allow(subject.connection).to receive(:run_request).with(:get, "http://example.com/foo", nil, nil).and_return(response)
67
67
  subject.request(:get, "foo")
68
68
  end
69
+
70
+ describe "default options" do
71
+ let!(:subject) { HTTPTester.new(request_default_options: { header: { user_agent: 'New app v1.0'} } ) }
72
+
73
+ it "should provide default headers in the request" do
74
+ response = double(:body => "response")
75
+ allow(subject.connection).to receive(:run_request).with(:get, "http://example.com/foo", nil, {:user_agent=>"New app v1.0"}).and_return(response)
76
+ subject.request(:get, "foo")
77
+ end
78
+ end
79
+
69
80
  end
70
81
  end
@@ -26,10 +26,10 @@ describe "An actual Rapidash Client" do
26
26
  let(:client) { Integration::Client.new(responses, :json => true) }
27
27
 
28
28
  it "should get the user from the API" do
29
- client.users!("Gazler").name.should eql("Gary Rennie")
29
+ expect(client.users!("Gazler").name).to eql("Gary Rennie")
30
30
  end
31
31
 
32
32
  it "should get the repos from A user" do
33
- client.users("Gazler").repos![0].name.should eql("Githug")
33
+ expect(client.users("Gazler").repos![0].name).to eql("Githug")
34
34
  end
35
35
  end
@@ -27,7 +27,7 @@ describe Rapidash::OAuthClient do
27
27
  it "should not raise an error with the correct options" do
28
28
  expect {
29
29
  OAuthTester.new(options)
30
- }.to_not raise_error(Rapidash::ConfigurationError)
30
+ }.to_not raise_error
31
31
  end
32
32
 
33
33
  it "should raise an error if the correct options are not set" do
@@ -40,39 +40,39 @@ describe Rapidash::OAuthClient do
40
40
 
41
41
  describe ".access_token_from_code" do
42
42
  it "should call localhost for the access token" do
43
- auth_code = mock
44
- client = mock
45
- subject.stub(:client).and_return(client)
46
- client.should_receive(:auth_code).and_return(auth_code)
47
- auth_code.should_receive(:get_token).with("123", :redirect_uri => "http://localhost").and_return(OpenStruct.new(:token => "token"))
48
- subject.access_token_from_code("123", "http://localhost").should eql("token")
43
+ auth_code = double
44
+ client = double
45
+ allow(subject).to receive(:client).and_return(client)
46
+ expect(client).to receive(:auth_code).and_return(auth_code)
47
+ expect(auth_code).to receive(:get_token).with("123", :redirect_uri => "http://localhost").and_return(OpenStruct.new(:token => "token"))
48
+ expect(subject.access_token_from_code("123", "http://localhost")).to eql("token")
49
49
  end
50
50
  end
51
51
 
52
52
  describe ".client" do
53
53
  it "should be an OAuth2::Client" do
54
- subject.send(:client).class.should eql(OAuth2::Client)
54
+ expect(subject.send(:client).class).to eql(OAuth2::Client)
55
55
  end
56
56
  end
57
57
 
58
58
  describe ".oauth_access_token" do
59
59
  it "should be an OAuth2::AccessToken" do
60
- subject.send(:oauth_access_token).class.should eql(OAuth2::AccessToken)
60
+ expect(subject.send(:oauth_access_token).class).to eql(OAuth2::AccessToken)
61
61
  end
62
62
  end
63
63
 
64
64
  describe ".request" do
65
- let(:request) { mock(:body => 'data') }
65
+ let(:request) { double(:body => 'data') }
66
66
 
67
67
  describe "object returned from API call" do
68
68
  before(:each) do
69
- subject.stub(:oauth_access_token).and_return(request)
70
- subject.stub(:normalize_url).with("me").and_return("me")
71
- request.stub(:get) { request }
69
+ allow(subject).to receive(:oauth_access_token).and_return(request)
70
+ allow(subject).to receive(:normalize_url).with("me").and_return("me")
71
+ allow(request).to receive(:get) { request }
72
72
  end
73
73
 
74
74
  it "should return a Hashie::Mash" do
75
- subject.request(:get, "me").should eq 'data'
75
+ expect(subject.request(:get, "me")).to eq 'data'
76
76
  end
77
77
  end
78
78
  end
@@ -28,7 +28,7 @@ describe Rapidash::Client do
28
28
  end
29
29
 
30
30
  it "should call with the updated URL" do
31
- client.should_receive(:get).with('users/active', { :headers => { "content-type" => "application/json" }})
31
+ expect(client).to receive(:get).with('users/active', { :headers => { "content-type" => "application/json" }})
32
32
  resource.active!
33
33
  end
34
34
 
@@ -46,7 +46,7 @@ describe Rapidash::Client do
46
46
  end
47
47
 
48
48
  it "should call with the updated URL" do
49
- client.should_receive(:post).with('people/deactivate', { :headers => { "content-type" => "application/json" }})
49
+ expect(client).to receive(:post).with('people/deactivate', { :headers => { "content-type" => "application/json" }})
50
50
  resource.suspend_all!
51
51
  end
52
52
 
@@ -53,7 +53,7 @@ describe Rapidash::Resourceable do
53
53
 
54
54
  describe "#included" do
55
55
  it "should include the resource method" do
56
- Rapidash::ClientTester.methods.map { |m| m.to_sym }.should include(:resource)
56
+ expect(Rapidash::ClientTester.methods.map { |m| m.to_sym }).to include(:resource)
57
57
  end
58
58
  end
59
59
 
@@ -62,17 +62,17 @@ describe Rapidash::Resourceable do
62
62
 
63
63
  describe ".resource" do
64
64
  it "should create a Rapidash::Base" do
65
- client.resource(:users, 1).class.should eql(Rapidash::Base)
65
+ expect(client.resource(:users, 1).class).to eql(Rapidash::Base)
66
66
  end
67
67
 
68
68
  it "should set the url to the resource name" do
69
69
  resource = client.resource(:users)
70
- resource.url.should eql("users")
70
+ expect(resource.url).to eql("users")
71
71
  end
72
72
 
73
73
  it "should pass the id through if specified" do
74
74
  resource = client.resource(:users, 1)
75
- resource.url.should eql("users/1")
75
+ expect(resource.url).to eql("users/1")
76
76
  end
77
77
 
78
78
  it "should pass the previous url through" do
@@ -80,31 +80,31 @@ describe Rapidash::Resourceable do
80
80
  "base"
81
81
  end
82
82
  resource = client.resource(:users, 1)
83
- resource.url.should eql("base/users/1")
83
+ expect(resource.url).to eql("base/users/1")
84
84
  end
85
85
 
86
86
  it "should pass the client through" do
87
87
  resource = client.resource(:users, 1)
88
- resource.client.should eql(client)
88
+ expect(resource.client).to eql(client)
89
89
  end
90
90
 
91
91
  it "should allow an explicit url to be sent" do
92
92
  resource = client.resource(:users, 1, :url => "people")
93
- resource.url.should eql("people/1")
93
+ expect(resource.url).to eql("people/1")
94
94
  end
95
95
 
96
96
  it "should be chainable" do
97
97
  resource = client.resource(:users, 1).resource(:comments, 2)
98
- resource.url.should eql("users/1/comments/2")
99
- resource.client.should eql(client)
98
+ expect(resource.url).to eql("users/1/comments/2")
99
+ expect(resource.client).to eql(client)
100
100
  end
101
101
  end
102
102
 
103
103
  describe ".resource!" do
104
104
  it "should call the call! method on a resource" do
105
- resource = mock
106
- Rapidash::Base.stub(:new).and_return(resource)
107
- resource.should_receive(:call!)
105
+ resource = double
106
+ allow(Rapidash::Base).to receive(:new).and_return(resource)
107
+ expect(resource).to receive(:call!)
108
108
  client.resource!(:users, 1)
109
109
  end
110
110
  end
@@ -112,7 +112,7 @@ describe Rapidash::Resourceable do
112
112
 
113
113
  describe "#resource" do
114
114
  it "should add a method with the name of the argument" do
115
- Rapidash::ClientTester.new.methods.map { |m| m.to_sym }.should include(:users)
115
+ expect(Rapidash::ClientTester.new.methods.map { |m| m.to_sym }).to include(:users)
116
116
  end
117
117
 
118
118
  it "should not fail when presented with a multi-word resource" do
@@ -120,71 +120,71 @@ describe Rapidash::Resourceable do
120
120
  class ClientTester
121
121
  resource :admin_users
122
122
  end
123
- }.to_not raise_error(NameError)
123
+ }.to_not raise_error
124
124
  end
125
125
 
126
126
  it "should load the plural class with a warning if the singular is not defined" do
127
- Kernel.should_receive(:warn).with("[DEPRECATED] - RAPIDASH WARNING using CoreMembers instead of CoreMember - please either use `CoreMember` or set the class name with `resource core_members, :class_name => CoreMembers` implicit plural naming will be deprecated in Rapidash 1.0")
127
+ expect(Kernel).to receive(:warn).with("[DEPRECATED] - RAPIDASH WARNING using CoreMembers instead of CoreMember - please either use `CoreMember` or set the class name with `resource core_members, :class_name => CoreMembers` implicit plural naming will be deprecated in Rapidash 1.0")
128
128
  class ClientTester
129
129
  resource :core_members
130
130
  end
131
131
  end
132
132
 
133
133
  it "should add a bang method with the name of the argument" do
134
- Rapidash::ClientTester.new.methods.map { |m| m.to_sym }.should include(:users!)
134
+ expect(Rapidash::ClientTester.new.methods.map { |m| m.to_sym }).to include(:users!)
135
135
  end
136
136
 
137
137
  it "should add a method for each resource is an array is passed" do
138
138
  methods = Rapidash::MultiResourceTester.new.methods.map { |m| m.to_sym }
139
- (methods & [:users, :users!, :repos, :repos!]).length.should eql(4)
139
+ expect((methods & [:users, :users!, :repos, :repos!]).length).to eql(4)
140
140
  end
141
141
  end
142
142
 
143
143
  describe ".users" do
144
144
  it "should return an instance of the resource" do
145
- Rapidash::ClientTester.new.users.class.should eql(Rapidash::User)
145
+ expect(Rapidash::ClientTester.new.users.class).to eql(Rapidash::User)
146
146
  end
147
147
 
148
148
  it "should not use a namespace if not in a module" do
149
- ClientTester.new.users.class.should eql(User)
149
+ expect(ClientTester.new.users.class).to eql(User)
150
150
  end
151
151
  end
152
152
 
153
153
  describe ".tickets!" do
154
154
  it "should return an instance of the resource and call it" do
155
- users = mock
156
- Rapidash::User.should_receive(:new).and_return(users)
157
- users.should_receive(:call!)
155
+ users = double
156
+ expect(Rapidash::User).to receive(:new).and_return(users)
157
+ expect(users).to receive(:call!)
158
158
  Rapidash::ClientTester.new.users!
159
159
  end
160
160
  end
161
161
 
162
162
  describe "chaining resources" do
163
163
  it "should allow resources to be nested" do
164
- client = mock
164
+ client = double
165
165
  users = Rapidash::User.new(client)
166
- users.methods.map { |m| m.to_sym }.should include(:repos)
167
- users.methods.map { |m| m.to_sym }.should include(:repos!)
166
+ expect(users.methods.map { |m| m.to_sym }).to include(:repos)
167
+ expect(users.methods.map { |m| m.to_sym }).to include(:repos!)
168
168
  end
169
169
 
170
170
  it "should maintain the client across resources " do
171
- client = mock
171
+ client = double
172
172
  users = Rapidash::User.new(client)
173
- users.repos.instance_variable_get(:@client).should eql(client)
173
+ expect(users.repos.instance_variable_get(:@client)).to eql(client)
174
174
  end
175
175
 
176
176
  it "should maintain the URL when chaining" do
177
- client = mock
177
+ client = double
178
178
  users = Rapidash::User.new(client)
179
- users.repos.instance_variable_get(:@args)[0].keys.should include(:previous_url)
179
+ expect(users.repos.instance_variable_get(:@args)[0].keys).to include(:previous_url)
180
180
  end
181
181
 
182
182
  it "should maintain the URL as well as the options when chaining" do
183
- client = mock
183
+ client = double
184
184
  users = Rapidash::User.new(client)
185
185
  repos = users.repos(:params => {:foo => :bar})
186
- repos.instance_variable_get(:@args)[0].should include(:params)
187
- repos.instance_variable_get(:@args)[0].should include(:previous_url)
186
+ expect(repos.instance_variable_get(:@args)[0]).to include(:params)
187
+ expect(repos.instance_variable_get(:@args)[0]).to include(:previous_url)
188
188
  end
189
189
  end
190
190
 
@@ -224,19 +224,19 @@ describe Rapidash::Resourceable do
224
224
  end
225
225
 
226
226
  it "should find user in another module" do
227
- ModuleTester.new.users.class.should eql(Facebook::User)
227
+ expect(ModuleTester.new.users.class).to eql(Facebook::User)
228
228
  end
229
229
 
230
230
  it "should allow a plural class name" do
231
- ModuleTester.new.posts.class.should eql(Facebook::Posts)
231
+ expect(ModuleTester.new.posts.class).to eql(Facebook::Posts)
232
232
  end
233
233
 
234
234
  it "should find deep_users in a nested module" do
235
- ModuleTester.new.deep_users.class.should eql(SomeModule::SomeSubModule::User)
235
+ expect(ModuleTester.new.deep_users.class).to eql(SomeModule::SomeSubModule::User)
236
236
  end
237
237
 
238
238
  it "should find deep_posts in a nested class name" do
239
- ModuleTester.new.deep_posts.class.should eql(SomeModule::SomeSubModule::Post)
239
+ expect(ModuleTester.new.deep_posts.class).to eql(SomeModule::SomeSubModule::Post)
240
240
  end
241
241
 
242
242
  it "should not raise a wrong constant NameError" do
@@ -248,7 +248,7 @@ describe Rapidash::Resourceable do
248
248
  end
249
249
  end
250
250
  end
251
- }.to_not raise_error(NameError)
251
+ }.to_not raise_error
252
252
  end
253
253
 
254
254
  end
@@ -42,7 +42,7 @@ describe Rapidash::ResponseError do
42
42
  let(:env) { { :status => '404', :method => 'post', :url => 'http://acme.com/api/posts', :body => ['name cannot be blank', 'content cannot be blank'] } }
43
43
 
44
44
  it "should call #errors" do
45
- response.should_receive(:errors)
45
+ expect(response).to receive(:errors)
46
46
  response.send(:message)
47
47
  end
48
48
 
@@ -18,35 +18,42 @@ end
18
18
 
19
19
  describe Rapidash::Urlable do
20
20
 
21
- let!(:client) { mock }
21
+ let!(:client) { double }
22
+ let(:custom_header) { { :header => { user_agent: 'Experimentation v3.14'} } }
22
23
 
23
24
  describe "#included" do
24
25
  it "should add the url method" do
25
- ApiTester.methods.map { |m| m.to_sym}.should include(:url)
26
+ expect(ApiTester.methods.map { |m| m.to_sym}).to include(:url)
26
27
  end
27
28
  end
28
29
 
29
30
  describe "#url" do
30
31
  it "should override the initialize to set a url" do
31
- ApiTesterNoUrl.new.instance_variable_get(:@url).should eql("apitesternourls")
32
- ApiTester.new.instance_variable_get(:@url).should eql("foo")
32
+ expect(ApiTesterNoUrl.new.instance_variable_get(:@url)).to eql("apitesternourls")
33
+ expect(ApiTester.new.instance_variable_get(:@url)).to eql("foo")
33
34
  end
34
35
 
35
36
  it "should set options on the class" do
36
37
  api = ApiTester.new(client, :option1 => "foo")
37
- api.instance_variable_get(:@options).should eql({:option1 => "foo"})
38
- api.instance_variable_get(:@url).should eql("foo")
38
+ expect(api.instance_variable_get(:@options)).to eql({:option1 => "foo"})
39
+ expect(api.instance_variable_get(:@url)).to eql("foo")
40
+ end
41
+
42
+ it "should allow custom headers" do
43
+ api = ApiTester.new(client,custom_header)
44
+ expect(api.instance_variable_get(:@options)).to eql(custom_header)
45
+ expect(api.instance_variable_get(:@url)).to eql("foo")
39
46
  end
40
47
 
41
48
  it "should let an id be set on initialization" do
42
49
  api = ApiTester.new(client, 1, :option1 => "foo")
43
- api.instance_variable_get(:@options).should eql({:option1 => "foo"})
44
- api.instance_variable_get(:@url).should eql("foo/1")
50
+ expect(api.instance_variable_get(:@options)).to eql({:option1 => "foo"})
51
+ expect(api.instance_variable_get(:@url)).to eql("foo/1")
45
52
  end
46
53
 
47
54
  it "should call base_url on when constructing the url" do
48
55
  api = BaseUrlTester.new(client, 1)
49
- api.instance_variable_get(:@url).should eql("BASE_URL/foo/1")
56
+ expect(api.instance_variable_get(:@url)).to eql("BASE_URL/foo/1")
50
57
  end
51
58
  end
52
59
 
metadata CHANGED
@@ -1,153 +1,202 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rapidash
3
- version: !ruby/object:Gem::Version
4
- version: 0.3.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - Gary 'Gazler' Rennie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
-
12
- date: 2014-05-30 00:00:00 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
11
+ date: 2015-07-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
15
14
  name: activesupport
16
- prerelease: false
17
- requirement: &id001 !ruby/object:Gem::Requirement
18
- requirements:
19
- - - ~>
20
- - !ruby/object:Gem::Version
21
- version: "3.0"
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 3.0.0
22
20
  type: :runtime
23
- version_requirements: *id001
24
- - !ruby/object:Gem::Dependency
25
- name: mime-types
26
21
  prerelease: false
27
- requirement: &id002 !ruby/object:Gem::Requirement
28
- requirements:
29
- - - ~>
30
- - !ruby/object:Gem::Version
31
- version: 1.25.0
32
- type: :runtime
33
- version_requirements: *id002
34
- - !ruby/object:Gem::Dependency
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.0
27
+ - !ruby/object:Gem::Dependency
35
28
  name: bundler
36
- prerelease: false
37
- requirement: &id003 !ruby/object:Gem::Requirement
38
- requirements:
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
39
31
  - - ~>
40
- - !ruby/object:Gem::Version
41
- version: "1.0"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
42
34
  type: :development
43
- version_requirements: *id003
44
- - !ruby/object:Gem::Dependency
45
- name: rake
46
35
  prerelease: false
47
- requirement: &id004 !ruby/object:Gem::Requirement
48
- requirements:
49
- - &id007
50
- - ">="
51
- - !ruby/object:Gem::Version
52
- version: "0"
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
53
48
  type: :development
54
- version_requirements: *id004
55
- - !ruby/object:Gem::Dependency
56
- name: rspec
57
49
  prerelease: false
58
- requirement: &id005 !ruby/object:Gem::Requirement
59
- requirements:
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
60
59
  - - ~>
61
- - !ruby/object:Gem::Version
62
- version: "2.8"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
63
62
  type: :development
64
- version_requirements: *id005
65
- - !ruby/object:Gem::Dependency
66
- name: simplecov
67
63
  prerelease: false
68
- requirement: &id006 !ruby/object:Gem::Requirement
69
- requirements:
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
70
66
  - - ~>
71
- - !ruby/object:Gem::Version
72
- version: "0.7"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
73
76
  type: :development
74
- version_requirements: *id006
75
- - !ruby/object:Gem::Dependency
76
- name: json
77
77
  prerelease: false
78
- requirement: &id008 !ruby/object:Gem::Requirement
79
- requirements:
80
- - *id007
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: json
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
81
90
  type: :development
82
- version_requirements: *id008
83
- - !ruby/object:Gem::Dependency
84
- name: coveralls
85
91
  prerelease: false
86
- requirement: &id009 !ruby/object:Gem::Requirement
87
- requirements:
88
- - *id007
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: coveralls
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
89
104
  type: :development
90
- version_requirements: *id009
91
- - !ruby/object:Gem::Dependency
92
- name: faraday
93
105
  prerelease: false
94
- requirement: &id010 !ruby/object:Gem::Requirement
95
- requirements:
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: faraday
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
96
115
  - - ~>
97
- - !ruby/object:Gem::Version
98
- version: "0.8"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.8'
99
118
  type: :runtime
100
- version_requirements: *id010
101
- - !ruby/object:Gem::Dependency
102
- name: faraday_middleware
103
119
  prerelease: false
104
- requirement: &id011 !ruby/object:Gem::Requirement
105
- requirements:
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
106
122
  - - ~>
107
- - !ruby/object:Gem::Version
108
- version: "0.9"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.8'
125
+ - !ruby/object:Gem::Dependency
126
+ name: faraday_middleware
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ~>
130
+ - !ruby/object:Gem::Version
131
+ version: '0.9'
109
132
  type: :runtime
110
- version_requirements: *id011
111
- - !ruby/object:Gem::Dependency
112
- name: faraday_middleware-multi_json
113
133
  prerelease: false
114
- requirement: &id012 !ruby/object:Gem::Requirement
115
- requirements:
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
116
136
  - - ~>
117
- - !ruby/object:Gem::Version
118
- version: "0.0"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.9'
139
+ - !ruby/object:Gem::Dependency
140
+ name: faraday_middleware-multi_json
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ~>
144
+ - !ruby/object:Gem::Version
145
+ version: '0.0'
119
146
  type: :runtime
120
- version_requirements: *id012
121
- - !ruby/object:Gem::Dependency
122
- name: oauth2
123
147
  prerelease: false
124
- requirement: &id013 !ruby/object:Gem::Requirement
125
- requirements:
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
126
150
  - - ~>
127
- - !ruby/object:Gem::Version
128
- version: "0.6"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: oauth2
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0.6'
160
+ - - <
161
+ - !ruby/object:Gem::Version
162
+ version: '2.0'
129
163
  type: :runtime
130
- version_requirements: *id013
131
- - !ruby/object:Gem::Dependency
132
- name: hashie
133
164
  prerelease: false
134
- requirement: &id014 !ruby/object:Gem::Requirement
135
- requirements:
136
- - - ~>
137
- - !ruby/object:Gem::Version
138
- version: "1.2"
165
+ version_requirements: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - '>='
168
+ - !ruby/object:Gem::Version
169
+ version: '0.6'
170
+ - - <
171
+ - !ruby/object:Gem::Version
172
+ version: '2.0'
173
+ - !ruby/object:Gem::Dependency
174
+ name: hashie
175
+ requirement: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - '>'
178
+ - !ruby/object:Gem::Version
179
+ version: '1.2'
180
+ - - <
181
+ - !ruby/object:Gem::Version
182
+ version: '4.0'
139
183
  type: :runtime
140
- version_requirements: *id014
184
+ prerelease: false
185
+ version_requirements: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - '>'
188
+ - !ruby/object:Gem::Version
189
+ version: '1.2'
190
+ - - <
191
+ - !ruby/object:Gem::Version
192
+ version: '4.0'
141
193
  description: Evolve your API
142
- email:
194
+ email:
143
195
  - gazler@gmail.com
144
196
  executables: []
145
-
146
197
  extensions: []
147
-
148
198
  extra_rdoc_files: []
149
-
150
- files:
199
+ files:
151
200
  - .gitignore
152
201
  - .rspec
153
202
  - .travis.yml
@@ -181,29 +230,30 @@ files:
181
230
  - spec/rapidash/urlable_spec.rb
182
231
  - spec/spec_helper.rb
183
232
  homepage: http://github.com/Gazler/rapidash
184
- licenses:
233
+ licenses:
185
234
  - MIT
186
235
  metadata: {}
187
-
188
236
  post_install_message:
189
237
  rdoc_options: []
190
-
191
- require_paths:
238
+ require_paths:
192
239
  - lib
193
- required_ruby_version: !ruby/object:Gem::Requirement
194
- requirements:
195
- - *id007
196
- required_rubygems_version: !ruby/object:Gem::Requirement
197
- requirements:
198
- - *id007
240
+ required_ruby_version: !ruby/object:Gem::Requirement
241
+ requirements:
242
+ - - '>='
243
+ - !ruby/object:Gem::Version
244
+ version: '0'
245
+ required_rubygems_version: !ruby/object:Gem::Requirement
246
+ requirements:
247
+ - - '>='
248
+ - !ruby/object:Gem::Version
249
+ version: '0'
199
250
  requirements: []
200
-
201
251
  rubyforge_project:
202
- rubygems_version: 2.1.11
252
+ rubygems_version: 2.2.2
203
253
  signing_key:
204
254
  specification_version: 4
205
255
  summary: An opinionated core for creating clients for RESTful APIs quickly
206
- test_files:
256
+ test_files:
207
257
  - spec/faraday/raise_rapidash_error_spec.rb
208
258
  - spec/rapidash/base_spec.rb
209
259
  - spec/rapidash/client_spec.rb