rack-rest-rspec 0.0.1a

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,60 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rubygems'
3
+ require 'rspec'
4
+ require 'rake'
5
+ require "rake/clean"
6
+ require "rubygems/package_task"
7
+ require "rdoc/task"
8
+ require 'code_statistics'
9
+ require 'rspec/core/rake_task'
10
+ require 'yard'
11
+ require 'yard/rake/yardoc_task.rb'
12
+ require "rake/tasklib"
13
+ require "roodi"
14
+ require "roodi_task"
15
+ require 'rake/version_task'
16
+
17
+ RoodiTask.new() do | t |
18
+ t.patterns = %w(lib/**/*.rb)
19
+ t.config = "ultragreen_roodi_coding_convention.yml"
20
+ end
21
+
22
+
23
+ CLEAN.include('*.tmp','*.old')
24
+ CLOBBER.include('*.tmp', 'build/*','#*#')
25
+
26
+
27
+ content = File::readlines(File.join(File.dirname(__FILE__), 'rack-rest-rspec.gemspec')).join
28
+ spec = eval(content)
29
+
30
+ RSpec::Core::RakeTask.new('spec')
31
+
32
+ YARD::Rake::YardocTask.new do |t|
33
+ t.files = [ 'lib/**/*.rb', '-', 'doc/**/*','spec/**/*_spec.rb']
34
+ t.options += ['--title', "Gem Documentation"]
35
+ t.options += ['-o', "yardoc"]
36
+ end
37
+ YARD::Config.load_plugin('yard-rspec')
38
+
39
+ namespace :yardoc do
40
+ task :clobber do
41
+ rm_r "yardoc" rescue nil
42
+ rm_r ".yardoc" rescue nil
43
+ end
44
+ end
45
+ task :clobber => "yardoc:clobber"
46
+
47
+
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
+ Rake::VersionTask.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1a
@@ -0,0 +1,14 @@
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
@@ -0,0 +1,2 @@
1
+ # encoding: UTF-8
2
+ Dir[File.dirname(__FILE__) + '/*.rb'].each {|file| require file unless File.basename(file) == 'init.rb'}
@@ -0,0 +1,45 @@
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
@@ -0,0 +1,14 @@
1
+ RSpec::Matchers.define :be_correctly_sent do
2
+ match do |actual|
3
+ actual.class == Rack::MockResponse
4
+ end
5
+ description do
6
+ "be a valid HTTP verb request with a valid response return"
7
+ end
8
+ failure_message do |actual|
9
+ "expected this HTTP verb request to return a valid response, \nneed : Rack::MockResponse \ngot : #{actual.class}"
10
+ end
11
+ failure_message_when_negated do |actual|
12
+ "expected this HTTP verb request to not return a valid response, \nneed : Rack::MockResponse \ngot : #{actual.class}"
13
+ end
14
+ end
@@ -0,0 +1,2 @@
1
+ # encoding: UTF-8
2
+ Dir[File.dirname(__FILE__) + '/*.rb'].each {|file| require file unless File.basename(file) == 'init.rb'}
@@ -0,0 +1,14 @@
1
+ RSpec::Matchers.define :respond_a_collection_of_record do
2
+ match do |actual|
3
+ JSON::parse(actual.browser.last_response.body).class == Array
4
+ end
5
+ description do
6
+ "respond with a record collection (Array)"
7
+ end
8
+ failure_message do |actual|
9
+ "expected #{actual} response body would be a collection \nneed : Array, \ngot : #{JSON::parse(actual.browser.last_response.body).class}"
10
+ end
11
+ failure_message_when_negated do |actual|
12
+ "expected #{actual} response body would not be a collection \nneed : Array, \ngot : #{JSON::parse(actual.browser.last_response.body).class}"
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ RSpec::Matchers.define :respond_a_record do
2
+ match do |actual|
3
+ JSON::parse(actual.browser.last_response.body).class == Hash
4
+ end
5
+ description do
6
+ "respond with a record (Hash)"
7
+ end
8
+ failure_message do |actual|
9
+ "expected #{actual} response body would be a record \nneed : Hash, \ngot : #{JSON::parse(actual.browser.last_response.body).class}"
10
+ end
11
+ failure_message_when_negated do |actual|
12
+ "expected #{actual} response body would not be a record \nneed : Hash, \ngot : #{JSON::parse(actual.browser.last_response.body).class}"
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ RSpec::Matchers.define :respond_with_collection_size do |expected|
2
+ match do |actual|
3
+ JSON::parse(actual.browser.last_response.body).size == expected
4
+ end
5
+ description do
6
+ "respond with a collection of record size of #{expected}"
7
+ end
8
+ failure_message do |actual|
9
+ "expected #{actual} response body collection would have a size of #{expected}, \ngot #{JSON::parse(actual.browser.last_response.body).size}"
10
+ end
11
+ failure_message_when_negated do |actual|
12
+ "expected #{actual} response body collection would not have a size of #{expected}, \ngot #{JSON::parse(actual.browser.last_response.body).size}"
13
+ end
14
+ end
@@ -0,0 +1,45 @@
1
+ def compare_array_of_hash expected, actual
2
+ if expected.size == actual.size then
3
+ res = true
4
+ actual.each_with_index do |item,index|
5
+ res = false unless item == expected[index]
6
+ end
7
+ return res
8
+ else
9
+ return false
10
+ end
11
+ end
12
+
13
+ def prepare_array data
14
+ data = (data.class == Hash)? [data] : data
15
+ data.each do |ahash|
16
+ ahash.symbolize!
17
+ end
18
+ return data
19
+ end
20
+
21
+
22
+ RSpec::Matchers.define :respond_with_data do |expected|
23
+ result = ""
24
+ match do |actual|
25
+ result = actual.browser.last_response.body
26
+ if result.empty? then
27
+ false
28
+ else
29
+ result = JSON::parse(result)
30
+ result = prepare_array result
31
+ expected = prepare_array expected
32
+ compare_array_of_hash expected,result
33
+ end
34
+ end
35
+ description do
36
+ "respond with corresponding data"
37
+ end
38
+ failure_message do |actual|
39
+ "expected #{actual} response body would be equal \nto : #{expected}, \ngot : #{result}"
40
+ end
41
+ failure_message_when_negated do |actual|
42
+ "expected #{actual} response body would not be equal \nto : #{expected}, \ngot : #{result}"
43
+ end
44
+ end
45
+
@@ -0,0 +1,14 @@
1
+ RSpec::Matchers.define :respond_with_status do |expected|
2
+ match do |actual|
3
+ actual.browser.last_response.status == expected
4
+ end
5
+ description do
6
+ "respond with status code equal to #{expected}"
7
+ end
8
+ failure_message do |actual|
9
+ "expected #{actual} response would be equal \nto : #{expected} \ngot : #{actual.browser.last_response.status}"
10
+ end
11
+ failure_message_when_negated do |actual|
12
+ "expected #{actual} response would not be equal \nto : #{expected} \ngot : #{actual.browser.last_response.status}"
13
+ end
14
+ end
@@ -0,0 +1,7 @@
1
+ require 'rspec'
2
+ require 'rack/test'
3
+ require 'rspec/expectations'
4
+
5
+ require_relative 'lib/restcrudservice.rb'
6
+ require_relative 'helpers/init.rb'
7
+ require_relative 'matchers/init.rb'
@@ -0,0 +1,4 @@
1
+ require 'version'
2
+ module RackRestRspec
3
+ is_versioned
4
+ end
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rack-rest-rspec/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rack-rest-rspec"
8
+ spec.version = RackRestRspec::VERSION
9
+ spec.authors = ["Romain GEORGES"]
10
+ spec.email = ["romain@ultragreen.net"]
11
+ spec.summary = %q{Rack-rest-rspec: RSpec Matchers for REST Rack webservice }
12
+ spec.description = %q{Rack-rest-rspec: RSpec Matchers for REST Rack webservice }
13
+ spec.homepage = "http://github.com/Ultragreen/rack-rest-rspec"
14
+ spec.license = "BSD-2"
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
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_development_dependency "version", "~> 1.0",'>= 1.0.0'
29
+ spec.add_runtime_dependency "rack-test", "~> 0.6", ">= 0.6.3"
30
+
31
+
32
+ end
@@ -0,0 +1,25 @@
1
+ AssignmentInConditionalCheck:
2
+ CaseMissingElseCheck:
3
+ ClassLineCountCheck:
4
+ line_count: 300
5
+ ClassNameCheck:
6
+ pattern: !ruby/regexp /^[A-Z][a-zA-Z0-9]*$/
7
+ #ClassVariableCheck:
8
+ CyclomaticComplexityBlockCheck:
9
+ complexity: 5
10
+ CyclomaticComplexityMethodCheck:
11
+ complexity: 10
12
+ EmptyRescueBodyCheck:
13
+ ForLoopCheck:
14
+ MethodLineCountCheck:
15
+ line_count: 30
16
+ MethodNameCheck:
17
+ pattern: !ruby/regexp /^[_a-z<>=\[|+-\/\*`]+[_a-z0-9_<>=~@\[\]]*[=!\?]?$/
18
+ # MissingForeignKeyIndexCheck:
19
+ ModuleLineCountCheck:
20
+ line_count: 500
21
+ ModuleNameCheck:
22
+ pattern: !ruby/regexp /^[A-Z][a-zA-Z0-9]*$/
23
+ ParameterNumberCheck:
24
+ parameter_count: 5
25
+
metadata ADDED
@@ -0,0 +1,265 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-rest-rspec
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1a
5
+ prerelease: 5
6
+ platform: ruby
7
+ authors:
8
+ - Romain GEORGES
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-11-02 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: '1.5'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.5'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '2.14'
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: 2.14.1
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ~>
63
+ - !ruby/object:Gem::Version
64
+ version: '2.14'
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: 2.14.1
68
+ - !ruby/object:Gem::Dependency
69
+ name: yard
70
+ requirement: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '0.8'
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: 0.8.7.2
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ~>
85
+ - !ruby/object:Gem::Version
86
+ version: '0.8'
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: 0.8.7.2
90
+ - !ruby/object:Gem::Dependency
91
+ name: rdoc
92
+ requirement: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ~>
96
+ - !ruby/object:Gem::Version
97
+ version: '4.0'
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: 4.0.1
101
+ type: :development
102
+ prerelease: false
103
+ version_requirements: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ~>
107
+ - !ruby/object:Gem::Version
108
+ version: '4.0'
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: 4.0.1
112
+ - !ruby/object:Gem::Dependency
113
+ name: roodi
114
+ requirement: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ~>
118
+ - !ruby/object:Gem::Version
119
+ version: '3.1'
120
+ - - ! '>='
121
+ - !ruby/object:Gem::Version
122
+ version: 3.1.1
123
+ type: :development
124
+ prerelease: false
125
+ version_requirements: !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ~>
129
+ - !ruby/object:Gem::Version
130
+ version: '3.1'
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: 3.1.1
134
+ - !ruby/object:Gem::Dependency
135
+ name: code_statistics
136
+ requirement: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ~>
140
+ - !ruby/object:Gem::Version
141
+ version: '0.2'
142
+ - - ! '>='
143
+ - !ruby/object:Gem::Version
144
+ version: 0.2.13
145
+ type: :development
146
+ prerelease: false
147
+ version_requirements: !ruby/object:Gem::Requirement
148
+ none: false
149
+ requirements:
150
+ - - ~>
151
+ - !ruby/object:Gem::Version
152
+ version: '0.2'
153
+ - - ! '>='
154
+ - !ruby/object:Gem::Version
155
+ version: 0.2.13
156
+ - !ruby/object:Gem::Dependency
157
+ name: yard-rspec
158
+ requirement: !ruby/object:Gem::Requirement
159
+ none: false
160
+ requirements:
161
+ - - ~>
162
+ - !ruby/object:Gem::Version
163
+ version: '0.1'
164
+ type: :development
165
+ prerelease: false
166
+ version_requirements: !ruby/object:Gem::Requirement
167
+ none: false
168
+ requirements:
169
+ - - ~>
170
+ - !ruby/object:Gem::Version
171
+ version: '0.1'
172
+ - !ruby/object:Gem::Dependency
173
+ name: version
174
+ requirement: !ruby/object:Gem::Requirement
175
+ none: false
176
+ requirements:
177
+ - - ~>
178
+ - !ruby/object:Gem::Version
179
+ version: '1.0'
180
+ - - ! '>='
181
+ - !ruby/object:Gem::Version
182
+ version: 1.0.0
183
+ type: :development
184
+ prerelease: false
185
+ version_requirements: !ruby/object:Gem::Requirement
186
+ none: false
187
+ requirements:
188
+ - - ~>
189
+ - !ruby/object:Gem::Version
190
+ version: '1.0'
191
+ - - ! '>='
192
+ - !ruby/object:Gem::Version
193
+ version: 1.0.0
194
+ - !ruby/object:Gem::Dependency
195
+ name: rack-test
196
+ requirement: !ruby/object:Gem::Requirement
197
+ none: false
198
+ requirements:
199
+ - - ~>
200
+ - !ruby/object:Gem::Version
201
+ version: '0.6'
202
+ - - ! '>='
203
+ - !ruby/object:Gem::Version
204
+ version: 0.6.3
205
+ type: :runtime
206
+ prerelease: false
207
+ version_requirements: !ruby/object:Gem::Requirement
208
+ none: false
209
+ requirements:
210
+ - - ~>
211
+ - !ruby/object:Gem::Version
212
+ version: '0.6'
213
+ - - ! '>='
214
+ - !ruby/object:Gem::Version
215
+ version: 0.6.3
216
+ description: ! 'Rack-rest-rspec: RSpec Matchers for REST Rack webservice '
217
+ email:
218
+ - romain@ultragreen.net
219
+ executables: []
220
+ extensions: []
221
+ extra_rdoc_files: []
222
+ files:
223
+ - Rakefile
224
+ - VERSION
225
+ - lib/rack-rest-rspec/helpers/hash.rb
226
+ - lib/rack-rest-rspec/helpers/init.rb
227
+ - lib/rack-rest-rspec/lib/restcrudservice.rb
228
+ - lib/rack-rest-rspec/matchers/be_correctly_sent.rb
229
+ - lib/rack-rest-rspec/matchers/init.rb
230
+ - lib/rack-rest-rspec/matchers/respond_a_collection_of_record.rb
231
+ - lib/rack-rest-rspec/matchers/respond_a_record.rb
232
+ - lib/rack-rest-rspec/matchers/respond_with_collection_size.rb
233
+ - lib/rack-rest-rspec/matchers/respond_with_data.rb
234
+ - lib/rack-rest-rspec/matchers/respond_with_status.rb
235
+ - lib/rack-rest-rspec/prepare.rb
236
+ - lib/rack-rest-rspec/version.rb
237
+ - rack-rest-rspec.gemspec
238
+ - ultragreen_roodi_coding_convention.yml
239
+ homepage: http://github.com/Ultragreen/rack-rest-rspec
240
+ licenses:
241
+ - BSD-2
242
+ post_install_message:
243
+ rdoc_options: []
244
+ require_paths:
245
+ - lib
246
+ required_ruby_version: !ruby/object:Gem::Requirement
247
+ none: false
248
+ requirements:
249
+ - - ! '>='
250
+ - !ruby/object:Gem::Version
251
+ version: '0'
252
+ required_rubygems_version: !ruby/object:Gem::Requirement
253
+ none: false
254
+ requirements:
255
+ - - ! '>'
256
+ - !ruby/object:Gem::Version
257
+ version: 1.3.1
258
+ requirements: []
259
+ rubyforge_project:
260
+ rubygems_version: 1.8.23
261
+ signing_key:
262
+ specification_version: 3
263
+ summary: ! 'Rack-rest-rspec: RSpec Matchers for REST Rack webservice'
264
+ test_files: []
265
+ has_rdoc: