rack-rest-rspec 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/rack-rest-rspec/helpers/memorizer.rb +17 -0
- data/lib/rack-rest-rspec/helpers/yml.rb +5 -0
- data/lib/rack-rest-rspec/lib/rest_service.rb +25 -0
- data/lib/rack-rest-rspec/prepare.rb +1 -1
- metadata +4 -3
- data/lib/rack-rest-rspec/helpers/hash.rb +0 -14
- data/lib/rack-rest-rspec/lib/restcrudservice.rb +0 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 991c3ce92453468607c170e5546f355d3ce1cec02c970651906599af34e3ec0e
|
4
|
+
data.tar.gz: 77955b805aed17ad1639496176821b9203dde097228b5aebaf237db9727c8947
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ba8ada8c6a9d413484b75b71fa368e9e9b59a09f1e903e1d8728a3a49a59f516054937e316b0f6d5948c155ef0cf4b304f55eeace61c479757a15c32497c880
|
7
|
+
data.tar.gz: b8ce3dad6fcac708eac0b5f0d50fc140dd5f6e98a4455c5b0e275a9d5a307740ec9f934f0da98297e80baf5f652a98abe8b6f52514e92741a1f07fe4826351a2
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
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,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
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-rest-rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Romain GEORGES
|
@@ -119,9 +119,10 @@ files:
|
|
119
119
|
- README.md
|
120
120
|
- Rakefile
|
121
121
|
- VERSION
|
122
|
-
- lib/rack-rest-rspec/helpers/hash.rb
|
123
122
|
- lib/rack-rest-rspec/helpers/init.rb
|
124
|
-
- lib/rack-rest-rspec/
|
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
|
125
126
|
- lib/rack-rest-rspec/matchers/be_correctly_sent.rb
|
126
127
|
- lib/rack-rest-rspec/matchers/init.rb
|
127
128
|
- lib/rack-rest-rspec/matchers/respond_a_collection_of_record.rb
|
@@ -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
|