serial-spec 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +10 -0
- data/README.md +22 -7
- data/lib/serial_spec/parsed_body.rb +63 -0
- data/lib/serial_spec/request_response.rb +76 -0
- data/lib/serial_spec/version.rb +3 -5
- data/lib/serial_spec.rb +34 -0
- data/serial-spec.gemspec +2 -7
- metadata +6 -60
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d9c458412bfc5b202178846361975ee2ca36196
|
4
|
+
data.tar.gz: 59dd3ffca3fae26727f6837b4d25bde4839f5c94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5b90548ffbf738176e7e978d08943dc7c97ee6ac27747cd2b8e1208be228cb71b51f96345753ca8205445bef259008888bf1a18017328d80c5ae7301c818206
|
7
|
+
data.tar.gz: 047f0f724a992e8e514845374e4529064344a7a190a63625d7721bb8dce60c66c5e5bcaf1dd665673a86416e480d9a381b7b474c9be370445c0f5c72d8e836ce
|
data/Gemfile
CHANGED
@@ -1,4 +1,14 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
+
group :development do
|
4
|
+
gem "bundler", "~> 1.8"
|
5
|
+
gem "byebug"
|
6
|
+
gem "rake", "~> 10.0"
|
7
|
+
end
|
8
|
+
|
9
|
+
group :test do
|
10
|
+
gem "rack-test", "~> 0.6.3"
|
11
|
+
gem "rspec", "~> 3.2"
|
12
|
+
|
3
13
|
# Specify your gem's dependencies in serial-spec.gemspec
|
4
14
|
gemspec
|
data/README.md
CHANGED
@@ -1,15 +1,30 @@
|
|
1
1
|
# SerialSpec
|
2
2
|
|
3
|
-
SerialSpec is designed provide some simple matchers and macros overlaying a simple `rack/test` setup for testing json apis more effectively.
|
4
|
-
|
5
|
-
* Rspec 3.x. This gem uses (or will use) several parts of rspecs syntax.
|
6
|
-
* Json api
|
7
|
-
* ActiveModelSerializers
|
8
|
-
* Single request testing pattern test architecture.
|
3
|
+
SerialSpec is designed provide some simple matchers and macros overlaying a simple `rack/test` setup for testing json apis more effectively.
|
9
4
|
|
10
5
|
## Usage
|
11
6
|
|
12
|
-
|
7
|
+
```ruby
|
8
|
+
require "spec_helper"
|
9
|
+
|
10
|
+
RSpec.describe "test" do
|
11
|
+
include SerialSpec
|
12
|
+
|
13
|
+
request_method "GET"
|
14
|
+
request_path "/"
|
15
|
+
|
16
|
+
it_expects(:content_encoding) { expect(status).to eq(200) }
|
17
|
+
it_expects(:content_type) { expect(status).to eq(200) }
|
18
|
+
end
|
19
|
+
```
|
20
|
+
|
21
|
+
## 0.2.0 - planned
|
22
|
+
|
23
|
+
- [x] `request_response`
|
24
|
+
- [x] `with_request`
|
25
|
+
- [x] `it_expects`
|
26
|
+
- [x] better response selector support
|
27
|
+
- [ ] provides_matcher
|
13
28
|
|
14
29
|
## Testing architecture
|
15
30
|
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require "json"
|
2
|
+
require "active_support/core_ext/hash/indifferent_access"
|
3
|
+
|
4
|
+
module SerialSpec
|
5
|
+
|
6
|
+
class ParsedBody
|
7
|
+
|
8
|
+
attr_reader :raw_body
|
9
|
+
attr_reader :selector
|
10
|
+
|
11
|
+
def initialize(body)
|
12
|
+
@selector = []
|
13
|
+
@raw_body = JSON.parse(body)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.add_selector(*methuds)
|
17
|
+
methuds.each do |methud|
|
18
|
+
class_eval <<-METHOD
|
19
|
+
def #{methud.to_s}(*args)
|
20
|
+
selector.push([#{methud.to_sym}, args])
|
21
|
+
self
|
22
|
+
end
|
23
|
+
METHOD
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
add_selector :first, :last, :[]
|
28
|
+
|
29
|
+
def [](*args)
|
30
|
+
selector.push([:[], *args])
|
31
|
+
self
|
32
|
+
end
|
33
|
+
|
34
|
+
def first(*args)
|
35
|
+
selector.push([:first])
|
36
|
+
self
|
37
|
+
end
|
38
|
+
|
39
|
+
def last(*args)
|
40
|
+
selector.push([:last])
|
41
|
+
self
|
42
|
+
end
|
43
|
+
|
44
|
+
def execute
|
45
|
+
copy = selector.clone
|
46
|
+
selector.clear
|
47
|
+
copy.inject(raw_body) do |remainder, method_and_args|
|
48
|
+
begin
|
49
|
+
methud, *args = method_and_args
|
50
|
+
if remainder.kind_of?(Hash)
|
51
|
+
remainder.with_indifferent_access.send methud, *args
|
52
|
+
else
|
53
|
+
remainder.send methud, *args
|
54
|
+
end
|
55
|
+
rescue NoMethodError => ex
|
56
|
+
raise ArgumentError, "could not find '#{methud.inspect}' \nfor:\n '#{remainder.inspect}' \nin\n #{raw_body}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require "rack/test"
|
2
|
+
require "inheritable_accessors/inheritable_hash_accessor"
|
3
|
+
|
4
|
+
module SerialSpec
|
5
|
+
module RequestResponse
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
include Rack::Test::Methods
|
8
|
+
include InheritableAccessors::InheritableHashAccessor
|
9
|
+
|
10
|
+
included do
|
11
|
+
include ::SerialSpec::RequestResponse::DSL
|
12
|
+
extend ::SerialSpec::RequestResponse::DSL
|
13
|
+
|
14
|
+
inheritable_hash_accessor :request_opts
|
15
|
+
inheritable_hash_accessor :request_params
|
16
|
+
inheritable_hash_accessor :request_envs
|
17
|
+
end
|
18
|
+
|
19
|
+
def perform_request!
|
20
|
+
env = request_envs.merge(:method => request_method, :params => request_params.to_hash)
|
21
|
+
env = current_session.send :env_for, request_path, env
|
22
|
+
|
23
|
+
current_session.send :process_request, request_path, env
|
24
|
+
end
|
25
|
+
|
26
|
+
module DSL
|
27
|
+
|
28
|
+
def request_path(new_path=nil)
|
29
|
+
if new_path
|
30
|
+
request_opts[:path] = new_path
|
31
|
+
else
|
32
|
+
path = request_opts[:path]
|
33
|
+
return path if path
|
34
|
+
raise "You must configure a path"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# GET, POST, PUT, DELETE, OPTIONS, HEAD
|
39
|
+
def request_method(new_method=nil)
|
40
|
+
if new_method
|
41
|
+
request_opts[:method] = new_method
|
42
|
+
else
|
43
|
+
methud = request_opts[:method]
|
44
|
+
return methud if methud
|
45
|
+
raise "You must configure a request method"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
module Helpers
|
53
|
+
extend ActiveSupport::Concern
|
54
|
+
|
55
|
+
def status
|
56
|
+
response.status
|
57
|
+
end
|
58
|
+
|
59
|
+
def headers
|
60
|
+
response.headers
|
61
|
+
end
|
62
|
+
|
63
|
+
def response
|
64
|
+
last_response
|
65
|
+
end
|
66
|
+
|
67
|
+
def body
|
68
|
+
@body ||= begin
|
69
|
+
JSON.parse(response.body)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
data/lib/serial_spec/version.rb
CHANGED
data/lib/serial_spec.rb
CHANGED
@@ -1,8 +1,42 @@
|
|
1
1
|
require "active_support/concern"
|
2
2
|
require "serial_spec/version"
|
3
3
|
require "serial_spec/it_expects"
|
4
|
+
require "serial_spec/parsed_body"
|
5
|
+
require "serial_spec/request_response"
|
4
6
|
require "inheritable_accessors"
|
5
7
|
|
6
8
|
module SerialSpec
|
7
9
|
extend ActiveSupport::Concern
|
10
|
+
include ItExpects
|
11
|
+
include RequestResponse
|
12
|
+
include RequestResponse::Helpers
|
13
|
+
SERIAL_VALID_VERBS = %w{GET POST PUT PATCH DELETE OPTIONS HEAD}
|
14
|
+
|
15
|
+
module ClassMethods
|
16
|
+
|
17
|
+
def with_request(request_str, params={}, envs={}, &block)
|
18
|
+
if request_str.split(/\s+/).count == 2
|
19
|
+
request_method_string, request_path_str = request_str.split(/\s+/)
|
20
|
+
end
|
21
|
+
|
22
|
+
context_klass = context "with request: '#{request_str}'" do
|
23
|
+
if request_str.split(/\s+/).count == 2
|
24
|
+
request_method_string, request_path_str = request_str.split(/\s+/)
|
25
|
+
if SERIAL_VALID_VERBS.include?(request_method_string)
|
26
|
+
request_method request_method_string
|
27
|
+
request_path request_path_str
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
instance_exec(&block) if block_given?
|
32
|
+
|
33
|
+
it "should match all examples: #{__inherited_expectations__.keys}" do
|
34
|
+
perform_request!
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
8
42
|
end
|
data/serial-spec.gemspec
CHANGED
@@ -5,7 +5,7 @@ require 'serial_spec/version'
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "serial-spec"
|
8
|
-
spec.version =
|
8
|
+
spec.version = SerialSpec::VERSION
|
9
9
|
spec.authors = ["Blake Chambers"]
|
10
10
|
spec.email = ["chambb1@gmail.com"]
|
11
11
|
spec.summary = %q{A better way to rspec api requests.}
|
@@ -18,11 +18,6 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.
|
22
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
-
spec.add_development_dependency "rspec", "~> 3.2"
|
24
|
-
spec.add_development_dependency "rack-test", "~> 0.6.3"
|
25
|
-
|
26
|
-
spec.add_runtime_dependency "inheritable_accessors", ">= 0.1.0"
|
21
|
+
spec.add_runtime_dependency "inheritable_accessors", ">= 0.1.1"
|
27
22
|
spec.add_runtime_dependency "activesupport", ">= 3.2.0"
|
28
23
|
end
|
metadata
CHANGED
@@ -1,85 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: serial-spec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Blake Chambers
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-15 00:00:00.000000000 Z
|
12
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.8'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.8'
|
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
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '3.2'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '3.2'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rack-test
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 0.6.3
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 0.6.3
|
69
13
|
- !ruby/object:Gem::Dependency
|
70
14
|
name: inheritable_accessors
|
71
15
|
requirement: !ruby/object:Gem::Requirement
|
72
16
|
requirements:
|
73
17
|
- - ">="
|
74
18
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.1.
|
19
|
+
version: 0.1.1
|
76
20
|
type: :runtime
|
77
21
|
prerelease: false
|
78
22
|
version_requirements: !ruby/object:Gem::Requirement
|
79
23
|
requirements:
|
80
24
|
- - ">="
|
81
25
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0.1.
|
26
|
+
version: 0.1.1
|
83
27
|
- !ruby/object:Gem::Dependency
|
84
28
|
name: activesupport
|
85
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -113,6 +57,8 @@ files:
|
|
113
57
|
- bin/setup
|
114
58
|
- lib/serial_spec.rb
|
115
59
|
- lib/serial_spec/it_expects.rb
|
60
|
+
- lib/serial_spec/parsed_body.rb
|
61
|
+
- lib/serial_spec/request_response.rb
|
116
62
|
- lib/serial_spec/version.rb
|
117
63
|
- serial-spec.gemspec
|
118
64
|
homepage: http://github.com/blakechambers/serial-spec
|