rack-rest-rspec 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4eb2d19e331be1cd12bce9ce623ed1844c181c7fcacb8960acb2c4e973dd2bd4
4
- data.tar.gz: 3b508c8c0b42e6bf2e6f2f9d475fc97b0fd7209270d445ba7fb8ae7e53dcbfd4
3
+ metadata.gz: 991c3ce92453468607c170e5546f355d3ce1cec02c970651906599af34e3ec0e
4
+ data.tar.gz: 77955b805aed17ad1639496176821b9203dde097228b5aebaf237db9727c8947
5
5
  SHA512:
6
- metadata.gz: 77d1fcb75c1082c6805bbb7b0d2985b5ffbb68d487af73014b75aad83feead049acf6e2bfe683f6c4ba5a1d63d90dfee0f66a81d345d59db0bb2b43ac13a280c
7
- data.tar.gz: 94caf0509356b636482b841aca8e9b5a4ef1a06438480d6498b8feeeedc935880ecb7d79ab4f74484922edbd702c2b67b5aafb38993f267dfceabca947890fa7
6
+ metadata.gz: 5ba8ada8c6a9d413484b75b71fa368e9e9b59a09f1e903e1d8728a3a49a59f516054937e316b0f6d5948c155ef0cf4b304f55eeace61c479757a15c32497c880
7
+ data.tar.gz: b8ce3dad6fcac708eac0b5f0d50fc140dd5f6e98a4455c5b0e275a9d5a307740ec9f934f0da98297e80baf5f652a98abe8b6f52514e92741a1f07fe4826351a2
data/Gemfile ADDED
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ group :test, :development do
8
+ gem "roodi", "~> 5.0"
9
+ gem "rake", "~> 13.0"
10
+ gem "code_statistics", "~> 0.2.13"
11
+ gem "rspec", "~> 3.11"
12
+ gem "yard", "~> 0.9.28"
13
+ gem "yard-rspec", "~> 0.1"
14
+ end
15
+
16
+ gem "rack-test", "~> 2.0"
17
+
18
+
19
+
20
+ gem "version", "~> 1.1"
data/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # Rack REST RSpec
2
+
3
+ RSpec Matchers for REST Rack webservice
4
+
5
+
6
+ Install it yourself as:
7
+
8
+ $ gem install rack-rest-rspec
9
+
10
+ or
11
+
12
+ $ bundle add 'rack-rest-rspec'
13
+
14
+ ## Usage
15
+
16
+ ### Basic usage : install in your spec/spec_helper.rb or spec/prepare.rb
17
+
18
+ require 'rack-rest-rspec/prepare'
19
+
20
+ ### Basic usage : sample of spec matchers usage
21
+
22
+ describe 'Posts REST API' do
23
+ before :all do
24
+ $service = RestService::new :service => MYRack::ModularApp
25
+ end
26
+
27
+ subject { $service }
28
+ context "GET /api/v1/posts : test for a collections of Post (empty)" do
29
+ it { expect(subject.get('/api/v1/posts')).to be_correctly_sent }
30
+ it { expect(subject).to respond_with_status 200 }
31
+ it { expect(subject).to respond_a_collection_of_record }
32
+ it { expect(subject).to respond_with_collection_size 0 }
33
+ end
34
+
35
+ context "POST /api/v1/post : create a new record" do
36
+ it { expect(subject.post('/api/v1/post',{id: 1, title: "test", body: "content"}.to_json)).to be_correctly_sent }
37
+ it { expect(subject).to respond_with_status 201 }
38
+ end
39
+
40
+ context "GET /api/v1/posts : test for a collections of Post" do
41
+ it { expect(subject.get('/api/v1/posts')).to be_correctly_sent }
42
+ it { expect(subject).to respond_with_status 200 }
43
+ it { expect(subject).to respond_a_collection_of_record }
44
+ it { expect(subject).to respond_with_collection_size 1 }
45
+ end
46
+
47
+ context "GET /api/v1/post/:id : get a record by code" do
48
+ it { expect(subject.get("/api/v1/post/1")).to be_correctly_sent }
49
+ it { expect(subject).to respond_with_status 200 }
50
+ it { expect(subject).to respond_a_record }
51
+ it { expect(subject).to respond_with_data({id: 1, title: "test", body: "content"}) }
52
+ end
53
+
54
+ context "DELETE /api/v1/post/:id : delete a pots by id" do
55
+ it{ expect(subject.delete("/api/v1/post/1")).to be_correctly_sent }
56
+ it { expect(subject).to respond_with_status 204 }
57
+ end
58
+
59
+
60
+
61
+ end
62
+
63
+
64
+ ## Available matchers :
65
+
66
+ * be_correctly_send : check if return is HTTP valid
67
+ * respond_with_a_collection_of_record : check if the return is a JSON Array
68
+ * respond_a_record : check if the return is a JSON Hash
69
+ * respond_with_collection_size <Integer> : check if the collection have the good size
70
+ * respond_with_data <Object> : check if the return match the given object
71
+ * respond_with_status <Integer> : check if the HTTP response code is the good.
72
+
73
+
74
+
75
+
76
+
77
+
78
+
data/Rakefile CHANGED
@@ -1,5 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
2
  require 'rubygems'
3
+ require 'version'
4
+ require 'rake/version_task'
3
5
  require 'rspec'
4
6
  require 'rake'
5
7
  require "rake/clean"
@@ -14,6 +16,10 @@ require "roodi"
14
16
  require "roodi_task"
15
17
 
16
18
 
19
+ task default: :spec
20
+
21
+ Rake::VersionTask.new
22
+
17
23
  RoodiTask.new() do | t |
18
24
  t.patterns = %w(lib/**/*.rb)
19
25
  t.config = "ultragreen_roodi_coding_convention.yml"
@@ -45,16 +51,4 @@ end
45
51
  task :clobber => "yardoc:clobber"
46
52
 
47
53
 
48
- Gem::PackageTask.new(spec) do |pkg|
49
- pkg.need_tar = true
50
- pkg.need_zip = true
51
- end
52
-
53
- Rake::RDocTask.new('rdoc') do |d|
54
- d.rdoc_files.include('doc/**/*','bin/*')
55
- d.title = 'Dorsal : Yard'
56
- d.options << '--line-numbers' << '--diagram' << '-SHN'
57
- end
58
-
59
- task :default => [:gem]
60
54
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1a
1
+ 0.0.3
@@ -0,0 +1,17 @@
1
+ require 'pstore'
2
+
3
+ def memorize(options)
4
+
5
+ $store = PStore.new("/tmp/data.pstore")
6
+ $store.transaction do
7
+ options.each do |key,val|
8
+ $store[key] = val
9
+ end
10
+ $store.commit
11
+ end
12
+ end
13
+
14
+ def retrieve(key)
15
+ $store = PStore.new("/tmp/data.pstore")
16
+ return $store.transaction { $store[key] }
17
+ end
@@ -0,0 +1,5 @@
1
+ require 'yaml'
2
+
3
+ def get_file(file)
4
+ return YAML.load(File::readlines(file).join)
5
+ end
@@ -0,0 +1,25 @@
1
+ require 'forwardable'
2
+
3
+
4
+ class RestService
5
+ extend Forwardable
6
+
7
+
8
+ attr_reader :path
9
+ attr_reader :service
10
+ attr_reader :browser
11
+
12
+ def initialize(params = {})
13
+ defaults = {
14
+ :service => Sinatra::Base,
15
+ :path => '/'
16
+ }
17
+ defaults.merge! params
18
+ @service = defaults[:service]
19
+ @path = defaults[:path]
20
+ @browser = Rack::Test::Session.new(Rack::MockSession.new(@service))
21
+ end
22
+
23
+ def_delegators :@browser, :get, :post, :put, :delete
24
+
25
+ end
@@ -2,6 +2,6 @@ require 'rspec'
2
2
  require 'rack/test'
3
3
  require 'rspec/expectations'
4
4
 
5
- require_relative 'lib/restcrudservice.rb'
5
+ require_relative 'lib/rest_service.rb'
6
6
  require_relative 'helpers/init.rb'
7
7
  require_relative 'matchers/init.rb'
@@ -5,27 +5,27 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "rack-rest-rspec"
8
- spec.version = "0.0.1"
8
+ spec.version = `cat VERSION`
9
9
  spec.authors = ["Romain GEORGES"]
10
10
  spec.email = ["romain@ultragreen.net"]
11
11
  spec.summary = %q{Rack-rest-rspec: RSpec Matchers for REST Rack webservice }
12
12
  spec.description = %q{Rack-rest-rspec: RSpec Matchers for REST Rack webservice }
13
13
  spec.homepage = "http://github.com/Ultragreen/rack-rest-rspec"
14
14
  spec.license = "BSD-2"
15
+
15
16
  spec.files = `git ls-files -z`.split("\x0")
16
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
19
  spec.require_paths = ["lib"]
19
20
 
20
- spec.add_development_dependency "bundler", "~> 1.5"
21
- spec.add_development_dependency "rake"
22
- spec.add_development_dependency 'rspec', '~> 2.14', '>= 2.14.1'
23
- spec.add_development_dependency 'yard', '~> 0.8', '>= 0.8.7.2'
24
- spec.add_development_dependency 'rdoc', '~> 4.0', '>= 4.0.1'
25
- spec.add_development_dependency 'roodi', '~> 3.1', '>= 3.1.1'
26
- spec.add_development_dependency 'code_statistics', '~> 0.2', '>= 0.2.13'
27
- spec.add_development_dependency 'yard-rspec', '~> 0.1'
28
- spec.add_runtime_dependency "rack-test", "~> 0.6", ">= 0.6.3"
21
+ spec.add_development_dependency "roodi", "~> 5.0"
22
+ spec.add_development_dependency "rake", "~> 13.0"
23
+ spec.add_development_dependency "code_statistics", "~> 0.2.13"
24
+ spec.add_development_dependency "rspec", "~> 3.11"
25
+ spec.add_development_dependency "yard", "~> 0.9.28"
26
+ spec.add_development_dependency "yard-rspec", "~> 0.1"
27
+
28
+ spec.add_runtime_dependency "rack-test", "~> 2.0"
29
29
 
30
30
 
31
31
  end
metadata CHANGED
@@ -1,143 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-rest-rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Romain GEORGES
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-09 00:00:00.000000000 Z
11
+ date: 2022-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: roodi
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.5'
19
+ version: '5.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.5'
26
+ version: '5.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: rspec
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '2.14'
48
- - - ">="
49
- - !ruby/object:Gem::Version
50
- version: 2.14.1
51
- type: :development
52
- prerelease: false
53
- version_requirements: !ruby/object:Gem::Requirement
54
- requirements:
55
- - - "~>"
56
- - !ruby/object:Gem::Version
57
- version: '2.14'
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- version: 2.14.1
61
- - !ruby/object:Gem::Dependency
62
- name: yard
63
29
  requirement: !ruby/object:Gem::Requirement
64
30
  requirements:
65
31
  - - "~>"
66
32
  - !ruby/object:Gem::Version
67
- version: '0.8'
68
- - - ">="
69
- - !ruby/object:Gem::Version
70
- version: 0.8.7.2
33
+ version: '13.0'
71
34
  type: :development
72
35
  prerelease: false
73
36
  version_requirements: !ruby/object:Gem::Requirement
74
37
  requirements:
75
38
  - - "~>"
76
39
  - !ruby/object:Gem::Version
77
- version: '0.8'
78
- - - ">="
79
- - !ruby/object:Gem::Version
80
- version: 0.8.7.2
40
+ version: '13.0'
81
41
  - !ruby/object:Gem::Dependency
82
- name: rdoc
42
+ name: code_statistics
83
43
  requirement: !ruby/object:Gem::Requirement
84
44
  requirements:
85
45
  - - "~>"
86
46
  - !ruby/object:Gem::Version
87
- version: '4.0'
88
- - - ">="
89
- - !ruby/object:Gem::Version
90
- version: 4.0.1
47
+ version: 0.2.13
91
48
  type: :development
92
49
  prerelease: false
93
50
  version_requirements: !ruby/object:Gem::Requirement
94
51
  requirements:
95
52
  - - "~>"
96
53
  - !ruby/object:Gem::Version
97
- version: '4.0'
98
- - - ">="
99
- - !ruby/object:Gem::Version
100
- version: 4.0.1
54
+ version: 0.2.13
101
55
  - !ruby/object:Gem::Dependency
102
- name: roodi
56
+ name: rspec
103
57
  requirement: !ruby/object:Gem::Requirement
104
58
  requirements:
105
59
  - - "~>"
106
60
  - !ruby/object:Gem::Version
107
- version: '3.1'
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: 3.1.1
61
+ version: '3.11'
111
62
  type: :development
112
63
  prerelease: false
113
64
  version_requirements: !ruby/object:Gem::Requirement
114
65
  requirements:
115
66
  - - "~>"
116
67
  - !ruby/object:Gem::Version
117
- version: '3.1'
118
- - - ">="
119
- - !ruby/object:Gem::Version
120
- version: 3.1.1
68
+ version: '3.11'
121
69
  - !ruby/object:Gem::Dependency
122
- name: code_statistics
70
+ name: yard
123
71
  requirement: !ruby/object:Gem::Requirement
124
72
  requirements:
125
73
  - - "~>"
126
74
  - !ruby/object:Gem::Version
127
- version: '0.2'
128
- - - ">="
129
- - !ruby/object:Gem::Version
130
- version: 0.2.13
75
+ version: 0.9.28
131
76
  type: :development
132
77
  prerelease: false
133
78
  version_requirements: !ruby/object:Gem::Requirement
134
79
  requirements:
135
80
  - - "~>"
136
81
  - !ruby/object:Gem::Version
137
- version: '0.2'
138
- - - ">="
139
- - !ruby/object:Gem::Version
140
- version: 0.2.13
82
+ version: 0.9.28
141
83
  - !ruby/object:Gem::Dependency
142
84
  name: yard-rspec
143
85
  requirement: !ruby/object:Gem::Requirement
@@ -158,20 +100,14 @@ dependencies:
158
100
  requirements:
159
101
  - - "~>"
160
102
  - !ruby/object:Gem::Version
161
- version: '0.6'
162
- - - ">="
163
- - !ruby/object:Gem::Version
164
- version: 0.6.3
103
+ version: '2.0'
165
104
  type: :runtime
166
105
  prerelease: false
167
106
  version_requirements: !ruby/object:Gem::Requirement
168
107
  requirements:
169
108
  - - "~>"
170
109
  - !ruby/object:Gem::Version
171
- version: '0.6'
172
- - - ">="
173
- - !ruby/object:Gem::Version
174
- version: 0.6.3
110
+ version: '2.0'
175
111
  description: 'Rack-rest-rspec: RSpec Matchers for REST Rack webservice '
176
112
  email:
177
113
  - romain@ultragreen.net
@@ -179,11 +115,14 @@ executables: []
179
115
  extensions: []
180
116
  extra_rdoc_files: []
181
117
  files:
118
+ - Gemfile
119
+ - README.md
182
120
  - Rakefile
183
121
  - VERSION
184
- - lib/rack-rest-rspec/helpers/hash.rb
185
122
  - lib/rack-rest-rspec/helpers/init.rb
186
- - lib/rack-rest-rspec/lib/restcrudservice.rb
123
+ - lib/rack-rest-rspec/helpers/memorizer.rb
124
+ - lib/rack-rest-rspec/helpers/yml.rb
125
+ - lib/rack-rest-rspec/lib/rest_service.rb
187
126
  - lib/rack-rest-rspec/matchers/be_correctly_sent.rb
188
127
  - lib/rack-rest-rspec/matchers/init.rb
189
128
  - lib/rack-rest-rspec/matchers/respond_a_collection_of_record.rb
@@ -199,7 +138,7 @@ homepage: http://github.com/Ultragreen/rack-rest-rspec
199
138
  licenses:
200
139
  - BSD-2
201
140
  metadata: {}
202
- post_install_message:
141
+ post_install_message:
203
142
  rdoc_options: []
204
143
  require_paths:
205
144
  - lib
@@ -214,8 +153,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
214
153
  - !ruby/object:Gem::Version
215
154
  version: '0'
216
155
  requirements: []
217
- rubygems_version: 3.2.3
218
- signing_key:
156
+ rubygems_version: 3.1.2
157
+ signing_key:
219
158
  specification_version: 4
220
159
  summary: 'Rack-rest-rspec: RSpec Matchers for REST Rack webservice'
221
160
  test_files: []
@@ -1,14 +0,0 @@
1
- class Hash
2
- def symbolize!
3
- self.keys.each do |key|
4
- self[key.to_sym] = self.delete(key)
5
- end
6
- end
7
-
8
- def stringify!
9
- self.keys.each do |key|
10
- self[key.to_s] = self.delete(key)
11
- end
12
- return ahash
13
- end
14
- end
@@ -1,45 +0,0 @@
1
- class RestCRUDService
2
-
3
- attr_reader :path
4
- attr_reader :object
5
- attr_reader :browser
6
-
7
- def initialize(params = {})
8
- defaults = {
9
- :path => '/api/',
10
- :object => '',
11
- :browser => Rack::Test::Session.new(Rack::MockSession.new(Sinatra::Application))
12
- }
13
- defaults.merge! params
14
- @path = defaults[:path]
15
- @object = defaults[:object]
16
- @browser = defaults[:browser]
17
- end
18
-
19
- def url
20
- return "#{@path}/#{@object}"
21
- end
22
-
23
- def create_record _data
24
- return @browser.post self.url, _data
25
- end
26
-
27
- def retrieve_all_records
28
- return @browser.get self.url
29
- end
30
-
31
- def retrieve_record _nb
32
- return @browser.get "#{self.url}/#{_nb}"
33
- end
34
-
35
-
36
- def update_record _nb,_data
37
- return @browser.put "#{self.url}/#{_nb}", _data
38
- end
39
-
40
-
41
- def destroy_record _nb
42
- return @browser.delete "#{self.url}/#{_nb}"
43
- end
44
-
45
- end