rspec_request_helpers 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +23 -5
- data/lib/rspec_request_helpers/helpers.rb +25 -6
- data/lib/rspec_request_helpers/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 91adebd9c1dabd6ddca1e5cfcbdb89e99fb2206cda1ca33ab3d668394a196e45
|
4
|
+
data.tar.gz: f66ddb343374709b07238a35307d678b8db57c085ca7692e35ea5534c5230418
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a345f449c50de4de835926f81aa00b595a57c36f585b8673f4ad2c5f6cfa52824fc725f7c378c0b11d0925b0474b426c09e27242b2a1b4eb98c6b47d05a14aa8
|
7
|
+
data.tar.gz: 6be451b2491f92893dd08d8a94df520a84f6272602d719991cb54f099e91793bb3d92f60c263b582dbd6564dea197d6ad71213ae2bac0d4db3bdc0abcc742592
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
# Rspec Request Helpers
|
2
2
|
|
3
3
|
This gem provides few tools to make testing of API endpoint in your Rails application more effective.
|
4
|
+
|
5
|
+
[![RSpec flow part 1](http://img.youtube.com/vi/YkZYNlUHHOg/1.jpg)](http://www.youtube.com/watch?v=YkZYNlUHHOg) [![RSpec flow part 2](http://img.youtube.com/vi/CB60JdImYC4/2.jpg)](http://www.youtube.com/watch?v=CB60JdImYC4)
|
6
|
+
|
4
7
|
This rules were influenced by real projects experience so
|
5
8
|
In order to use it in your `rspec/requests` specs you need to follow one rule:
|
6
9
|
|
7
|
-
For every test example you need to define
|
10
|
+
For every test example you need to define path, headers, params, and expected_response.
|
8
11
|
|
9
12
|
NOTE: version 0.1.1 introduced the helpers which ensure naming conventions. They have identical names and in fact are
|
10
13
|
wrappers around RSpec `let` functionality.
|
@@ -36,6 +39,18 @@ database do
|
|
36
39
|
end
|
37
40
|
```
|
38
41
|
|
42
|
+
Since version 0.2.1 there is an ability to define regular variables which text example depends on in separate block with handy syntax support
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
vars do
|
46
|
+
variant_id { variant.id }
|
47
|
+
issue_id { issue.id }
|
48
|
+
issue_message { 'Packed 5 instead of 3 items' }
|
49
|
+
item_id { item.id }
|
50
|
+
mispick_report { MispickReport.last }
|
51
|
+
end
|
52
|
+
```
|
53
|
+
|
39
54
|
## Installation
|
40
55
|
|
41
56
|
Add this line to your application's Gemfile:
|
@@ -56,7 +71,7 @@ In project directory run
|
|
56
71
|
|
57
72
|
$ rails g rspec_request_helpers:install
|
58
73
|
|
59
|
-
##
|
74
|
+
## Configuration
|
60
75
|
|
61
76
|
Include helpers into RSpec
|
62
77
|
|
@@ -73,8 +88,6 @@ RSpec.configure do |config|
|
|
73
88
|
end
|
74
89
|
```
|
75
90
|
|
76
|
-
## Configuration
|
77
|
-
|
78
91
|
Create file `config/initializers/rspec_request_helpers.rb`
|
79
92
|
|
80
93
|
```ruby
|
@@ -86,8 +99,13 @@ RspecRequestHelpers.configure do |config|
|
|
86
99
|
config.status_codes = [404, 401, 422, 200, 201]
|
87
100
|
end
|
88
101
|
```
|
102
|
+
## Usage
|
103
|
+
|
104
|
+
### Generate new rspec file for API endpoint
|
105
|
+
|
106
|
+
$ rails g rspec:endpoint <action name> <namespaced controller>
|
89
107
|
|
90
|
-
|
108
|
+
Example:
|
91
109
|
|
92
110
|
$ rails g rspec:endpoint show api/v1/users
|
93
111
|
|
@@ -40,16 +40,35 @@ module RspecRequestHelpers
|
|
40
40
|
self.class_eval(rspec_factory)
|
41
41
|
end
|
42
42
|
|
43
|
+
class VarsDSL
|
44
|
+
def initialize(klass)
|
45
|
+
@klass = klass
|
46
|
+
end
|
47
|
+
|
48
|
+
def method_missing(method_name, *args, &block)
|
49
|
+
case method_name
|
50
|
+
when /!$/
|
51
|
+
@klass.class_eval { let!(:"#{method_name.to_s.sub(/!$/,'')}", &block) }
|
52
|
+
else
|
53
|
+
@klass.class_eval { let(method_name, &block) }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def vars(&block)
|
59
|
+
VarsDSL.new(self).instance_eval(&block)
|
60
|
+
end
|
61
|
+
|
43
62
|
def path(&block)
|
44
63
|
let(:path, &block)
|
45
64
|
end
|
46
65
|
|
47
|
-
def
|
48
|
-
let(:
|
66
|
+
def params(&block)
|
67
|
+
let(:params, &block)
|
49
68
|
end
|
50
69
|
|
51
|
-
def
|
52
|
-
let(:
|
70
|
+
def headers(&block)
|
71
|
+
let(:headers, &block)
|
53
72
|
end
|
54
73
|
|
55
74
|
def expected_response(&block)
|
@@ -97,9 +116,9 @@ module RspecRequestHelpers
|
|
97
116
|
%i(get post put patch delete).each do |http_verb|
|
98
117
|
define_method :"do_#{http_verb}" do
|
99
118
|
if Rails::VERSION::MAJOR >= 5
|
100
|
-
public_send(http_verb, path, params:
|
119
|
+
public_send(http_verb, path, params: params, headers: headers)
|
101
120
|
else
|
102
|
-
public_send(http_verb, path,
|
121
|
+
public_send(http_verb, path, params, headers)
|
103
122
|
end
|
104
123
|
end
|
105
124
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec_request_helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrii Baran
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|