lazy_spec 0.0.1
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 +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +91 -0
- data/Rakefile +2 -0
- data/lazy_spec.gemspec +24 -0
- data/lib/lazy_spec/helpers/json.rb +15 -0
- data/lib/lazy_spec/helpers.rb +6 -0
- data/lib/lazy_spec/matchers/responses/be_a_collection.rb +32 -0
- data/lib/lazy_spec/matchers/responses/have_attributes.rb +28 -0
- data/lib/lazy_spec/matchers/responses/have_charset.rb +17 -0
- data/lib/lazy_spec/matchers/responses/have_content_type.rb +17 -0
- data/lib/lazy_spec/matchers/responses/have_json_type.rb +17 -0
- data/lib/lazy_spec/matchers/responses.rb +8 -0
- data/lib/lazy_spec/matchers.rb +6 -0
- data/lib/lazy_spec/version.rb +3 -0
- data/lib/lazy_spec.rb +9 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0ddb1b3e59fd6dad8f32c0322fce4dd52a074d7d
|
4
|
+
data.tar.gz: 236fd346b0409a09bcf76b0c77b78226653cd02a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4023e9d8d11efa2464855634e6a7ba104cc25a27c5c66568856a416cceb9519613ba2147a5a0e96fbe1f74c29f55796a9b33679047a7608dd8fdc26084731427
|
7
|
+
data.tar.gz: 7a0a3e6dd45a3f03d5e36afc7bff879b26a9699ed96281fc2ddc37c17d819ad1731e46c438bb46dffc8baa206b859e3afe5b51ee7fd7bf6603f798fc7be75f5f
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Hoa Hoang
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
# Lazy Spec
|
2
|
+
|
3
|
+
Lazy Spec provides RSpec syntax that test common Rails functionality, like Should Matchers.
|
4
|
+
|
5
|
+
----
|
6
|
+
|
7
|
+
### Usage
|
8
|
+
|
9
|
+
```
|
10
|
+
# http://en.wikipedia.org/wiki/Internet_media_type
|
11
|
+
get '/api/v1/categories'
|
12
|
+
expect(response).to have_json_type
|
13
|
+
expect(response).to have_content_type('application/json')
|
14
|
+
# http://billpatrianakos.me/blog/2013/10/13/list-of-rails-status-code-symbols/
|
15
|
+
expect(response).to have_http_status(:error)
|
16
|
+
expect(response).to have_charset('utf-8')
|
17
|
+
expect(response).to be_a_collection
|
18
|
+
expect(response).to be_a_collection(length: 10)
|
19
|
+
expect(response['collection'][0]).to have_attributes(%w(id name))
|
20
|
+
```
|
21
|
+
|
22
|
+
## Installation
|
23
|
+
|
24
|
+
### RSpec
|
25
|
+
|
26
|
+
Include `lazy_spec` in your Gemfile:
|
27
|
+
|
28
|
+
ruby
|
29
|
+
group :test do
|
30
|
+
gem 'lazy_spec'
|
31
|
+
end
|
32
|
+
|
33
|
+
And then execute:
|
34
|
+
|
35
|
+
$ bundle
|
36
|
+
|
37
|
+
Or install it yourself as:
|
38
|
+
|
39
|
+
$ gem install lazy_spec
|
40
|
+
|
41
|
+
[Then, configure the gem to integrate with RSpec](#configuration).
|
42
|
+
|
43
|
+
Now you can use matchers in your tests. For instance a model test might look
|
44
|
+
like this:
|
45
|
+
|
46
|
+
``` ruby
|
47
|
+
describe 'UserApi' do
|
48
|
+
it 'response as JSON type' do
|
49
|
+
get '/api/v1/users'
|
50
|
+
expect(response).to have_json_type
|
51
|
+
end
|
52
|
+
end
|
53
|
+
```
|
54
|
+
|
55
|
+
### Configuration
|
56
|
+
|
57
|
+
Include it in spec/rails_helper.rb
|
58
|
+
|
59
|
+
```
|
60
|
+
require 'lazy_spec'
|
61
|
+
```
|
62
|
+
|
63
|
+
## Contributing
|
64
|
+
|
65
|
+
Lazy Spec is open source, and I am grateful for everyone who's contributed so far.
|
66
|
+
|
67
|
+
1. Fork it ( https://github.com/hoahm/lazy_spec.git )
|
68
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
69
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
70
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
71
|
+
5. Create a new Pull Request
|
72
|
+
|
73
|
+
## Versioning
|
74
|
+
|
75
|
+
Current version: __0.0.1__
|
76
|
+
|
77
|
+
## License
|
78
|
+
|
79
|
+
Lazy Spec is copyright © 2015 [Hoa Hoang]. It is free software,
|
80
|
+
and may be redistributed under the terms specified in the
|
81
|
+
[MIT-LICENSE](MIT-LICENSE) file.
|
82
|
+
|
83
|
+
## About author
|
84
|
+
|
85
|
+
Lazy Spec is maintained by Hoa Hoang, a young-passionate developer at [Silicon Straits Saigon](http://siliconstraits.vn).
|
86
|
+
|
87
|
+
If you want to know more about me, find me at:
|
88
|
+
|
89
|
+
See [Linkedin][http://vn.linkendin.vn/hoahoangminh].
|
90
|
+
|
91
|
+
-
|
data/Rakefile
ADDED
data/lazy_spec.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'lazy_spec/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'lazy_spec'
|
8
|
+
spec.version = LazySpec::VERSION
|
9
|
+
spec.authors = ['Hoa Hoang']
|
10
|
+
spec.email = ['nobi.hoa@gmail.com']
|
11
|
+
spec.summary = 'Making unit test more easier than ever.'
|
12
|
+
spec.description = 'Making unit test more easier than ever.'
|
13
|
+
spec.homepage = 'http://vn.linkedin.com/in/hoahoangminh'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
spec.add_development_dependency 'rspec-rails', '~> 3.1.0'
|
24
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module LazySpec
|
2
|
+
module Helpers
|
3
|
+
module Json
|
4
|
+
def json
|
5
|
+
@json ||= JSON.parse(response.body)
|
6
|
+
rescue JSON::ParserError, JSON::GeneratorError
|
7
|
+
nil
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.include LazySpec::Helpers::Json
|
15
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
RSpec::Matchers.define :be_a_collection do |options|
|
2
|
+
match do |response|
|
3
|
+
options ||= {}
|
4
|
+
array?(response) && collection_length?(response, options[:length])
|
5
|
+
end
|
6
|
+
|
7
|
+
failure_message do
|
8
|
+
"Expect #{response} to be a collection, #{@missing}"
|
9
|
+
end
|
10
|
+
|
11
|
+
failure_message_when_negated do
|
12
|
+
"Expect #{response.inspect} NOT to be a collection, #{@missing}"
|
13
|
+
end
|
14
|
+
|
15
|
+
description do
|
16
|
+
'test if response data is a collection'
|
17
|
+
end
|
18
|
+
|
19
|
+
protected
|
20
|
+
|
21
|
+
def array?(response)
|
22
|
+
response.is_a?(Array)
|
23
|
+
end
|
24
|
+
|
25
|
+
def collection_length?(response, length)
|
26
|
+
return true unless array?(response)
|
27
|
+
return true unless length
|
28
|
+
return true if response.length == length
|
29
|
+
@missing = "with length of #{length} but #{response.length}"
|
30
|
+
false
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
RSpec::Matchers.define :have_attributes do |attributes|
|
2
|
+
match do |response|
|
3
|
+
unless response.is_a?(Hash)
|
4
|
+
@missing = 'but data is not a Hash'
|
5
|
+
return false
|
6
|
+
end
|
7
|
+
|
8
|
+
unless attributes.is_a?(Array)
|
9
|
+
@missing = 'but attributes is not an Array'
|
10
|
+
return false
|
11
|
+
end
|
12
|
+
|
13
|
+
keys = response.keys
|
14
|
+
keys.to_set == attributes.to_set
|
15
|
+
end
|
16
|
+
|
17
|
+
failure_message do |response|
|
18
|
+
"Expect #{response.inspect} contains these attributes #{attributes}, #{@missing}"
|
19
|
+
end
|
20
|
+
|
21
|
+
failure_message_when_negated do |response|
|
22
|
+
"Expect #{response.inspect} NOT contains these attributes #{attributes}, #{@missing}"
|
23
|
+
end
|
24
|
+
|
25
|
+
description do
|
26
|
+
'test if response contains attributes'
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
RSpec::Matchers.define :have_charset do |charset|
|
2
|
+
match do |response|
|
3
|
+
response.header['Content-Type'].match(/#{charset.downcase}/i)
|
4
|
+
end
|
5
|
+
|
6
|
+
failure_message do |response|
|
7
|
+
"Expect Content-Type '#{response.header['Content-Type']}' header to have charset '#{charset}'"
|
8
|
+
end
|
9
|
+
|
10
|
+
failure_message_when_negated do |response|
|
11
|
+
"Expect Content-Type '#{response.header['Content-Type']}' header NOT to have charset '#{charset}'"
|
12
|
+
end
|
13
|
+
|
14
|
+
description do
|
15
|
+
"test if HTTP 'Content-Type' header is '#{charset}'"
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
RSpec::Matchers.define :have_content_type do |content_type|
|
2
|
+
match do |response|
|
3
|
+
response.header['Content-Type'].include?(content_type)
|
4
|
+
end
|
5
|
+
|
6
|
+
failure_message do
|
7
|
+
"Expect Content-Type '#{response.header['Content-Type']}' header to be '#{content_type}'"
|
8
|
+
end
|
9
|
+
|
10
|
+
failure_message_when_negated do
|
11
|
+
"Expect Content-Type '#{response.header['Content-Type']}' header NOT to be '#{content_type}'"
|
12
|
+
end
|
13
|
+
|
14
|
+
description do
|
15
|
+
"test if HTTP 'Content-Type' header is '#{content_type}'"
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
RSpec::Matchers.define :have_json_type do
|
2
|
+
match do |response|
|
3
|
+
response.header['Content-Type'].include?('application/json')
|
4
|
+
end
|
5
|
+
|
6
|
+
failure_message do
|
7
|
+
"Expect Content-Type '#{response.header['Content-Type']}' header to be 'application/json'"
|
8
|
+
end
|
9
|
+
|
10
|
+
failure_message_when_negated do
|
11
|
+
"Expect Content-Type '#{response.header['Content-Type']}' header NOT to be 'application/json'"
|
12
|
+
end
|
13
|
+
|
14
|
+
description do
|
15
|
+
"test if HTTP 'Content-Type' header is 'application/json'"
|
16
|
+
end
|
17
|
+
end
|
data/lib/lazy_spec.rb
ADDED
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lazy_spec
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hoa Hoang
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec-rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.1.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.1.0
|
55
|
+
description: Making unit test more easier than ever.
|
56
|
+
email:
|
57
|
+
- nobi.hoa@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lazy_spec.gemspec
|
68
|
+
- lib/lazy_spec.rb
|
69
|
+
- lib/lazy_spec/helpers.rb
|
70
|
+
- lib/lazy_spec/helpers/json.rb
|
71
|
+
- lib/lazy_spec/matchers.rb
|
72
|
+
- lib/lazy_spec/matchers/responses.rb
|
73
|
+
- lib/lazy_spec/matchers/responses/be_a_collection.rb
|
74
|
+
- lib/lazy_spec/matchers/responses/have_attributes.rb
|
75
|
+
- lib/lazy_spec/matchers/responses/have_charset.rb
|
76
|
+
- lib/lazy_spec/matchers/responses/have_content_type.rb
|
77
|
+
- lib/lazy_spec/matchers/responses/have_json_type.rb
|
78
|
+
- lib/lazy_spec/version.rb
|
79
|
+
homepage: http://vn.linkedin.com/in/hoahoangminh
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.4.5
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: Making unit test more easier than ever.
|
103
|
+
test_files: []
|