rspec_api_test 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,54 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://localhost:9292/nodes/users
6
+ body:
7
+ encoding: UTF-8
8
+ string: ! '{"test":"user"}'
9
+ headers:
10
+ Accept:
11
+ - ! '*/*; q=0.5, application/xml'
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ Content-Type:
15
+ - application/json
16
+ Content-Length:
17
+ - '15'
18
+ User-Agent:
19
+ - Ruby
20
+ response:
21
+ status:
22
+ code: 201
23
+ message: ! 'Created '
24
+ headers:
25
+ X-Frame-Options:
26
+ - sameorigin
27
+ X-Xss-Protection:
28
+ - 1; mode=block
29
+ Content-Type:
30
+ - application/json;charset=utf-8
31
+ Content-Length:
32
+ - '101'
33
+ Cache-Control:
34
+ - no-cache
35
+ Access-Control-Allow-Origin:
36
+ - ! '*'
37
+ Access-Control-Allow-Methods:
38
+ - GET, POST, OPTIONS, PUT
39
+ Access-Control-Allow-Headers:
40
+ - Content-Type
41
+ Access-Control-Max-Age:
42
+ - '86400'
43
+ Server:
44
+ - WEBrick/1.3.1 (Ruby/1.9.2/2012-02-22)
45
+ Date:
46
+ - Mon, 18 Feb 2013 16:16:18 GMT
47
+ Connection:
48
+ - Keep-Alive
49
+ body:
50
+ encoding: US-ASCII
51
+ string: ! '{"id":816651,"type":"User","created_at":1361204178,"updated_at":1361204178,"payload":{"test":"user"}}'
52
+ http_version:
53
+ recorded_at: Mon, 18 Feb 2013 16:16:18 GMT
54
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,90 @@
1
+ describe RSpecAPITest::HTTPHelpers do
2
+
3
+ describe "HTTP requests" do
4
+ it "set the base url for the tests" do
5
+ defaults = {
6
+ base_url: 'http://localhost:9292',
7
+ defaults: { content_type: 'application/json' }
8
+ }
9
+ expect{
10
+ RSpecAPITest.config = defaults
11
+ }.to change(RSpecAPITest, :config).to(defaults)
12
+ end
13
+
14
+ it "return a json hash" do
15
+ VCR.use_cassette('json hash') do
16
+ res = post("/nodes/users", {test: :user}.to_json)
17
+ res.code.should == 201
18
+ res[:payload][:test].should == 'user'
19
+ end
20
+ end
21
+
22
+ it "return a json array" do
23
+ VCR.use_cassette('json array') do
24
+ res = get("/nodes/199337/neighbours/likes")
25
+ res.code.should == 200
26
+ res.should have(356).items
27
+ end
28
+ end
29
+
30
+ it "return a 400" do
31
+ VCR.use_cassette('400') do
32
+ res = get("/nodes/0")
33
+ res.code.should == 400
34
+ end
35
+ end
36
+
37
+ it "return a 404" do
38
+ VCR.use_cassette('404') do
39
+ res = get("/nodes/999999999")
40
+ res.code.should == 404
41
+ end
42
+ end
43
+
44
+ it "access the headers" do
45
+ VCR.use_cassette('404') do
46
+ res = get("/nodes/999999999")
47
+ res.headers[:cache_control].should == "no-cache"
48
+ end
49
+ end
50
+ end
51
+
52
+ describe "RestClient" do
53
+ before(:all) do
54
+ RSpecAPITest.config = {
55
+ base_url: 'http://myspace.com:81',
56
+ defaults: { content_type: 'application/soap+xml' }
57
+ }
58
+ end
59
+
60
+ let(:response){ mock(response:'{"success": "true"}', code: 123) }
61
+
62
+ it "call without body and without options" do
63
+ RestClient.should_receive(:get).
64
+ with("http://myspace.com:81/foo", content_type: 'application/soap+xml').
65
+ and_return(response)
66
+ get("/foo")
67
+ end
68
+
69
+ it "call with body but without options" do
70
+ RestClient.should_receive(:post).
71
+ with("http://myspace.com:81/bar", "body", content_type: 'application/soap+xml').
72
+ and_return(response)
73
+ post("/bar", "body")
74
+ end
75
+
76
+ it "call without body but with options" do
77
+ RestClient.should_receive(:get).
78
+ with("http://myspace.com:81/foo", something: :extra, content_type: 'application/json').
79
+ and_return(response)
80
+ get("/foo", something: :extra, content_type: 'application/json')
81
+ end
82
+
83
+ it "call with body and options" do
84
+ RestClient.should_receive(:post).
85
+ with("http://myspace.com:81/bax", "body", something: :extra, content_type: 'application/json').
86
+ and_return(response)
87
+ post("/bax", "body", something: :extra, content_type: 'application/json')
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,24 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'bundler'
4
+ Bundler.require
5
+ require 'vcr_setup'
6
+
7
+ require File.expand_path("../../lib/rspec_api_test/http_helpers", __FILE__)
8
+
9
+ # Requires supporting files with custom matchers and macros, etc,
10
+ # in ./support/ and its subdirectories.
11
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
12
+
13
+ RSpec.configure do |config|
14
+
15
+ # We're doing what the gem is doing to a user's rspec here
16
+ # and then we test that the helpers are there in rspec. Tehehe
17
+ config.include(RSpecAPITest::HTTPHelpers)
18
+
19
+ config.before(:suite) do
20
+ RSpecAPITest.config = nil
21
+ end
22
+ end
23
+
24
+
data/spec/vcr_setup.rb ADDED
@@ -0,0 +1,17 @@
1
+ # VCR Config
2
+ require 'webmock/rspec'
3
+ require 'vcr'
4
+ FileUtils.mkdir("log") rescue nil
5
+ VCR.configure do |c|
6
+ dir = File.expand_path("../../spec/fixtures", __FILE__)
7
+ c.cassette_library_dir = dir
8
+ c.hook_into :webmock
9
+ c.ignore_localhost = false
10
+ c.default_cassette_options = {
11
+ record: :new_episodes,
12
+ match_requests_on: [:method, :body, :uri]
13
+ }
14
+ c.allow_http_connections_when_no_cassette = false
15
+ c.debug_logger = File.open(File.expand_path("../../log/vcr.log", __FILE__), "w")
16
+ end
17
+
metadata ADDED
@@ -0,0 +1,263 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec_api_test
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jannis Hermanns
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 2.0.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 2.0.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: rest-client
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: activesupport
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: jeweler
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: webmock
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: vcr
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: guard
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ - !ruby/object:Gem::Dependency
143
+ name: guard-rspec
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ - !ruby/object:Gem::Dependency
159
+ name: guard-bundler
160
+ requirement: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ - !ruby/object:Gem::Dependency
175
+ name: terminal-notifier
176
+ requirement: !ruby/object:Gem::Requirement
177
+ none: false
178
+ requirements:
179
+ - - ! '>='
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ type: :development
183
+ prerelease: false
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ! '>='
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ - !ruby/object:Gem::Dependency
191
+ name: rb-fsevent
192
+ requirement: !ruby/object:Gem::Requirement
193
+ none: false
194
+ requirements:
195
+ - - ! '>='
196
+ - !ruby/object:Gem::Version
197
+ version: '0'
198
+ type: :development
199
+ prerelease: false
200
+ version_requirements: !ruby/object:Gem::Requirement
201
+ none: false
202
+ requirements:
203
+ - - ! '>='
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
206
+ description: Test a JSON-API using rspec and simple get/put/post/delete helpers
207
+ email: jannis@moviepilot.com
208
+ executables: []
209
+ extensions: []
210
+ extra_rdoc_files:
211
+ - LICENSE.txt
212
+ - README.markdown
213
+ files:
214
+ - .document
215
+ - .rspec
216
+ - .rvmrc
217
+ - .travis.yml
218
+ - Gemfile
219
+ - Gemfile.lock
220
+ - Guardfile
221
+ - LICENSE.txt
222
+ - README.markdown
223
+ - Rakefile
224
+ - VERSION
225
+ - lib/rspec_api_test.rb
226
+ - lib/rspec_api_test/http_helpers.rb
227
+ - rspec_api_test.gemspec
228
+ - spec/fixtures/400.yml
229
+ - spec/fixtures/404.yml
230
+ - spec/fixtures/json_array.yml
231
+ - spec/fixtures/json_hash.yml
232
+ - spec/lib/rspec_api_test/http_helpers_spec.rb
233
+ - spec/spec_helper.rb
234
+ - spec/vcr_setup.rb
235
+ homepage: http://github.com/jayniz/rspec-api-test
236
+ licenses:
237
+ - MIT
238
+ post_install_message:
239
+ rdoc_options: []
240
+ require_paths:
241
+ - lib
242
+ required_ruby_version: !ruby/object:Gem::Requirement
243
+ none: false
244
+ requirements:
245
+ - - ! '>='
246
+ - !ruby/object:Gem::Version
247
+ version: '0'
248
+ segments:
249
+ - 0
250
+ hash: 2428912611001349189
251
+ required_rubygems_version: !ruby/object:Gem::Requirement
252
+ none: false
253
+ requirements:
254
+ - - ! '>='
255
+ - !ruby/object:Gem::Version
256
+ version: '0'
257
+ requirements: []
258
+ rubyforge_project:
259
+ rubygems_version: 1.8.24
260
+ signing_key:
261
+ specification_version: 3
262
+ summary: Makes JSON-API integration testing easier with rspec
263
+ test_files: []